Borrar filtros
Borrar filtros

How to display velocity for each loop at 20 seconds?

2 visualizaciones (últimos 30 días)
John Baumgartner
John Baumgartner el 25 de Abr. de 2018
Comentada: John Baumgartner el 25 de Abr. de 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))

Respuesta aceptada

njj1
njj1 el 25 de Abr. de 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 comentarios
njj1
njj1 el 25 de Abr. de 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
John Baumgartner el 25 de Abr. de 2018
Exactly what i needed thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by