graph of y = 1 / ( cos(x) -c)

12 Ansichten (letzte 30 Tage)
Hollie Bell
Hollie Bell am 15 Mär. 2015
Kommentiert: Jos (10584) am 18 Mär. 2015
i am trying to plot a graph of y = 1 / ( cos(x) -c) where c comes from initial conditions.
When I do a graph by hand for each of the initial conditions I get plots above and below the axis but all my matlab plots are below zero.
C = cos(c) - 1/y
When I hard code the values for C the graph works fine so I expect it is these lines of code.
if true
x0 = [0 pi/2 pi/2 pi/2 pi/2 pi/2 pi/2]
y0 = [1 -1/2 1/2 -2/3 2/3 -1 1]
C = cos(x0) - (1./y0);
for C= 1:7
end
if true
% code
hold on
grid on
x=[0: pi/20: 4*pi]
axis([0 4*pi -5 1])
x0 = [0 pi/2 pi/2 pi/2 pi/2 pi/2 pi/2]
y0 = [1 -1/2 1/2 -2/3 2/3 -1 1]
C = cos(x0) - (1./y0);
for C= 1:7
y = 1./(cos(x) -C);
plot (x,y,'color',rand(1,3))
end
set(gca,'xTick',0:pi/2:4*pi)
set(gca,'xTickLabel',{'0', ' ', 'pi', ' ', '2pi', ' ', '3pi', ' ', '4pi'})
% Define y-ticks and let them be auto-labelled...
set(gca,'yTick',-5:.5:1)
title('1/ (cos(x) - c)') xlabel('x') ylabel('y') legend('y(0)= 1','y(pi/2)= -1/2', 'y(pi/2)= 1/2', 'y(pi/2)= -2/3', 'y(pi/2)= 2/3', 'y(pi/2)= -1', 'y(pi/2)= 1')
end
<</matlabcentral/answers/uploaded_files/27185/assignment3_2b.jpg>>
Any help would be appreciated.

Akzeptierte Antwort

Hollie Bell
Hollie Bell am 15 Mär. 2015
How good are you!
Thanks
  1 Kommentar
Jos (10584)
Jos (10584) am 18 Mär. 2015
Is this really the answer you wish to accept? ;-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jos (10584)
Jos (10584) am 15 Mär. 2015
I think these lines do not behave as expected:
C = cos(x0) - (1./y0); % these values are never used
for C= 1:7
y = 1./(cos(x) -C); % C is 1, 2, 3 ...
...
where my guess is that you want to use a specific value, like this:
C = cos(x0) - (1./y0); % 7 values
for k = 1:7
% use a specific value of C in each iteration
y = 1./(cos(x) - C(k));
...

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by