Clear Filters
Clear Filters

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

4 views (last 30 days)
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 Comments
Jocelyn
Jocelyn on 8 Nov 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.

Sign in to comment.

Accepted Answer

Rafael Hernandez-Walls
Rafael Hernandez-Walls on 8 Nov 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 Comment
Rafael Hernandez-Walls
Rafael Hernandez-Walls on 8 Nov 2020
instead of putting
v(indice)=[];
put this
t(indice)=[];
d(indice)=[];

Sign in to comment.

More Answers (1)

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

Sign in to comment.

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!