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

4 次查看(过去 30 天)
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 个评论
Jocelyn
Jocelyn 2020-11-8
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.

请先登录,再进行评论。

采纳的回答

Rafael Hernandez-Walls
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 个)

David Hill
David Hill 2020-11-8
You need to run your code using arrays for t, g, v, and d.
  1 个评论
Jocelyn
Jocelyn 2020-11-8
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by