no data plots on graph (plot (x,y))

2 visualizaciones (últimos 30 días)
Jocelyn
Jocelyn el 8 de Nov. de 2020
Comentada: Rafael Hernandez-Walls el 8 de Nov. de 2020
Hello,
Thank you for your assistance.
When I run my code, the 'Figure' graph box pop up however there is no data/lines on the graph. I am trying to plot the acceleration, velocity, and altitude of a paratrooper falling out of a plane as a function of time.
Below is my code:
d = 32000;
H = 8000;
Re = 6370000;
%c2 = 0.5*exp(-d/H);
g = 9.8*((1+(d/Re))^2);
Dt = 0;
t = 0;
%Vt = sqrt(g*m/(0.5*exp(-d/H));
dt = 0.0001;
while d > Dt
v = (sqrt((9.8*((1+(d/Re))^2))*m/(0.5*exp(-d/H))))*tanh((9.8*((1+(d/Re))^2))*t/(sqrt((9.8*((1+(d/Re))^2))*m/(0.5*exp(-d/H)))));
d = d + (v*dt);
if d == Dt
break
else
t = t+dt;
d = d + (v*dt);
end
end
disp('time until ground impact (seconds): ')
disp(t)
plot(d,t)
plot(v,t)
plot((v/t),t)
Full question that I was trying to get the above code to solve was: calculate the time of fall until the ground impact, given c2 scales with atmospheric density as c2 =0.5exp(-d/H), where H= 8km is the scale height of the atmosphere and d is the height above the ground. Furthermore, assume that g is no longer constant but is given by g = 9.8/(1+(d/Re))^2 where Re = 6370km is the radius of the earth. Plot the acceleration, velocity, and altitude of the paratrooper as a function of time.
  2 comentarios
Rafael Hernandez-Walls
Rafael Hernandez-Walls el 8 de Nov. de 2020
m?
Jocelyn
Jocelyn el 8 de Nov. de 2020
Thank you. This value was previously saved (it's 70) in the command window, so my code was running even though I did not program it on this script.

Iniciar sesión para comentar.

Respuesta aceptada

Rafael Hernandez-Walls
Rafael Hernandez-Walls el 8 de Nov. de 2020
David is correct. Why don't you try something like that in your code...
d(1) = 32000;
H = 8000;
Re = 6370000;
%c2 = 0.5*exp(-d/H);
Dt = 0;
t(1) = 0;
%Vt = sqrt(g*m/(0.5*exp(-d/H));
dt = 0.0001;
m=70;
indice=1;
while d(indice) > Dt
g = 9.8*((1+(d(indice)/Re)).^2);
v(indice) = (sqrt((9.8*((1+(d(indice)/Re))^2))*m/(0.5*exp(-d(indice)/H))))*tanh((9.8*((1+(d(indice)/Re))^2))*t(indice)/(sqrt((9.8*((1+(d(indice)/Re))^2))*m/(0.5*exp(-d(indice)/H)))));
d(indice+1) = d(indice) + (v(indice)*dt);
if d(indice+1) == Dt
break
else
t(indice+1) = t(indice)+dt;
d(indice+1) = d(indice) + (v(indice)*dt);
end
indice=indice+1;
end
disp('time until ground impact (seconds): ')
disp(t(indice))
v(indice)=[];
plot(d,t)
figure
plot(v,t)
figure
plot((v./t),t)
  1 comentario
Rafael Hernandez-Walls
Rafael Hernandez-Walls el 8 de Nov. de 2020
instead of putting
v(indice)=[];
put this
t(indice)=[];
d(indice)=[];

Iniciar sesión para comentar.

Más respuestas (1)

David Hill
David Hill el 8 de Nov. de 2020
You need to run your code using arrays for t, g, v, and d.
  1 comentario
Jocelyn
Jocelyn el 8 de Nov. de 2020
How do I save the data being continually updated in the while loop into an array so I can use this array in the plot function?

Iniciar sesión para comentar.

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