Matlab graph is not drawn

4 vues (au cours des 30 derniers jours)
Kardelen Polat
Kardelen Polat le 7 Avr 2022
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)

Réponses (1)

Les Beckham
Les Beckham le 7 Avr 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)

Catégories

En savoir plus sur Networks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by