# How to display velocity for each loop at 20 seconds?

5 views (last 30 days)
John Baumgartner on 25 Apr 2018
Commented: John Baumgartner on 25 Apr 2018
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))

njj1 on 25 Apr 2018
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))

John Baumgartner on 25 Apr 2018
I tried fprintf('%.0fm/s\n',vj(1)) and fprintf('%.0fm/s\n',vj(2)) but it prints 0m/s and 2m/s. Those velocities dont match the graph
njj1 on 25 Apr 2018
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))
John Baumgartner on 25 Apr 2018
Exactly what i needed thank you