Matlab graph is not drawn

1 回表示 (過去 30 日間)
Kardelen Polat
Kardelen Polat 2022 年 4 月 7 日
回答済み: Les Beckham 2022 年 4 月 7 日
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)

回答 (1 件)

Les Beckham
Les Beckham 2022 年 4 月 7 日
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)

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by