Matlab graph is not drawn
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I was trying to plot a x vs t graph of vertical projectile motion until the maximum altitude with the following code but the graph is not plotted. What can be the problem?
V0=1000 + 100*7 + 50*8;
x(2)=0;
t0=0;
R=6.37*10^6;
g0=9.81;
dt=100;
k=2;
for i=0:dt:1000
if x(k)>x(k-1)
g=g0*R^2/(R+x(t))^2;
x(k+1)= 2*x(k)-x(k-1)+g*dt^2;
end
end
plot(t,x)
0 Kommentare
Antworten (1)
Les Beckham
am 7 Apr. 2022
You aren't incrementing k or creating t in your loop.
There are also other things wrong with your calculation of x. For one thing, I don't see that you are using V0 at all.
Try something like this to get a plot and then fix your calculations to get a plot that actually looks like what you expect.
V0 = 1000 + 100*7 + 50*8;
% x(2)=0;
% t0=0;
R = 6.37*10^6;
g0 = 9.81;
dt = 100;
% k=2;
t = 0:dt:1000;
x = zeros(size(t));
for k=2:numel(t)
if x(k)>x(k-1)
g = g0*R^2/(R+x(k))^2;
x(k+1)= 2*x(k) - x(k-1) + g*dt^2;
end
end
plot(t,x)
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!