I can\'t get my graph of t vs. s to show up. There are no error messages, there
ID: 1815972 • Letter: I
Question
I can't get my graph of t vs. s to show up. There are no error messages, there is just no line that shows up on the graph.
This is the code I used:
clc
clear
r=9;
w=100;
b=14;
A=[ ];
B=[ ];
C=[ ];
for t=0:.01/49:.01;
u=2*pi*w*t;
z=sqrt(b2-r2*sin(u)2);
s=r*cos(u)+z;
v=-2*pi*w*r*sin(u)-2*pi*w*r2*sin(u)*cos(u)/z;
a=-4*pi2*w2*cos(u)-4*pi2*w2*r4*sin(u)2*cos(u)2/(z3)-4*pi*w2*r2*cos(u)2/z+4*pi*w2*r2*sin(u)2/z;
A=[A,[t;s]];
B=[B,[t;v]];
C=[C,[t;a]];
if t==.01
disp(A)
disp(B)
disp(C)
end
end
plot(t,s,'-r','LineWidth',2)
axis([0 .01 5 23])
Explanation / Answer
first, the "if" statement is unnecessary. you can have theA,B,C arrays display outside the for loop. that way it isguaranteed not to display until the for loop is completed. otherwise you're wasting time by checking if the loop has endedevery iteration. next, you are graphing something, but it is only 1 point. your "t" array is only 1 variable, and so is your "s". because the for loop is changing the value of those variables eachtime. you never created t and s arrays, but you did create anA array (which is what you should be using). I would try this command instead: plot(A(1,:),A(2,:),'-r','LineWidth',2) where I am plotting all columns of the first row (your t values)against all columns of the second row (your s values).
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.