How to display velocity for each loop at 20 seconds?

1 view (last 30 days)
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))

Accepted Answer

njj1
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))
  3 Comments
njj1
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))

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!