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

조회 수: 6 (최근 30일)
Jocelyn
Jocelyn 2020년 11월 8일
댓글: Rafael Hernandez-Walls 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 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