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

2 ビュー (過去 30 日間)
Jocelyn
Jocelyn 2020 年 11 月 8 日
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 件のコメント
Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020 年 11 月 8 日
m?
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
Rafael Hernandez-Walls 2020 年 11 月 8 日
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 件のコメント
Rafael Hernandez-Walls
Rafael Hernandez-Walls 2020 年 11 月 8 日
instead of putting
v(indice)=[];
put this
t(indice)=[];
d(indice)=[];

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by