How to display velocity for each loop at 20 seconds?
1 回表示 (過去 30 日間)
古いコメントを表示
Here is the code ive been using :
Time=20; %Time the jumper free-falls
Cd=[0.25,.50,.75]; %varying coefficients of drag in kg/m
m=[40,60,80]; %varying masses in kg
g=9.81; %accleration of jumper due to gravity
n=100; %number steps
deltaT=Time/(n-1);
v(1)=0; %initialVelocity
t=linspace(0,Time,n); %the time interval of the jumper
for j=1:3 hold on for i=2:n
v(i)=v(i-1)+(g-(Cd(j)/m(2))*v(i-1)*abs(v(i-1)))*deltaT;
end vj=v; plot(t,vj) end fprintf('%.0fm/s\n',vj(:,1)) fprintf('%.0m/s\n',vj(,2))
0 件のコメント
採用された回答
njj1
2018 年 4 月 25 日
You have an error in your code:
fprint('%.0m/s\n', vj(,2)
This code should work for you:
Time=20; %Time the jumper free-falls
Cd=[0.25,.50,.75]; %varying coefficients of drag in kg/m
m=[40,60,80]; %varying masses in kg
g=9.81; %accleration of jumper due to gravity
n=100; %number steps
deltaT=Time/(n-1);
v(1)=0; %initialVelocity
t=linspace(0,Time,n); %the time interval of the jumper
for j=1:3
hold on
for i=2:n
v(i)=v(i-1)+(g-(Cd(j)/m(2))*v(i-1)*abs(v(i-1)))*deltaT;
end
vj=v;
plot(t,vj)
end
fprintf('%.0f m/s\n',vj(1))
fprintf('%.0f m/s\n',vj(2))
3 件のコメント
njj1
2018 年 4 月 25 日
What you put in your code are the first and second entries of the vector vj. The vector vj is equal to the vector v after each loop through values of i. What you want is probably something like this:
for j=1:3
hold on
for i=2:n
v(i)=v(i-1)+(g-(Cd(j)/m(2))*v(i-1)*abs(v(i-1)))*deltaT;
end
vj(j)=v(end);
plot(t,v)
end
fprintf('%.0f m/s\n',vj(1))
fprintf('%.0f m/s\n',vj(2))
fprintf('%.0f m/s\n',vj(3))
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!