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 truex0 = [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:7endif true % code
hold ongrid onx=[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:7y = 1./(cos(x) -C);plot (x,y,'color',rand(1,3))endset(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.
Best Answer