graph of y = 1 / ( cos(x) -c)
Show older comments
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.
Accepted Answer
More Answers (1)
Jos (10584)
on 15 Mar 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));
...
Categories
Find more on Orange in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!