How can I the plot t vs v graph according to code?

3 vues (au cours des 30 derniers jours)
ANIL CELEBI
ANIL CELEBI le 27 Mai 2018
Hi There, I worked so much however I face with a little problem. In this code I can easily get all of t values however when I want to t vs graph,I can only get the last value of v in this code.Could you help me about this situation? r=50; L=150;
w=10; t=0; count=0; for i=1:1000
x=10*t; alp=0; x1=-r*sin(t*pi/180)-((r^2*sin(t*pi/180)*cos(t*pi/180))/sqrt(L^2-r^2*sin(t*pi/180)^2)) x2=-r*cos(t*pi/180)-((r^2*(cos(t*pi/180)^2-sin(t*pi/180)^2)/sqrt(L^2-r^2*sin(t*pi/180)^2)))-((r^4*(sin(t*pi/180)^2*cos(t*pi/180)^2)/sqrt(L^2-r^2*sin(t*pi/180)^2)^3)); v=(x1*w) a=x2*w; t=t+1 count=count+1; end time=0:count; plot(time,v(1):v(30))

Réponses (1)

Ameer Hamza
Ameer Hamza le 27 Mai 2018
You are facing this problem because you are saving just the last value of v, You need to create a vector v to save all values. For example, try this
w=10;
t=0;
count=0;
r = 1;
L = 1;
v = zeros(1, 1000);
for i=1:1000
x=10*t;
alp=0;
x1=-r*sin(t*pi/180)-((r^2*sin(t*pi/180)*cos(t*pi/180))/sqrt(L^2-r^2*sin(t*pi/180)^2));
x2=-r*cos(t*pi/180)-((r^2*(cos(t*pi/180)^2-sin(t*pi/180)^2)/sqrt(L^2-r^2*sin(t*pi/180)^2)))-((r^4*(sin(t*pi/180)^2*cos(t*pi/180)^2)/sqrt(L^2-r^2*sin(t*pi/180)^2)^3));
v(i)=(x1*w);
a=x2*w;
t=t+1;
count=count+1;
end
time=0:count-1;
plot(time,v)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by