WHAT would be the reason this matlab code works but does not draw the graphic?

1 次查看(过去 30 天)
% Constants
G = 6.67430e-11; % gravitational constant
M = 5.9722e24; % mass of Earth
R = 6.371e6; % radius of Earth
% Initial conditions
y0 = 0; % initial height
v0 = 0; % initial velocity
% Solve differential equation
[t, v] = ode45(@(y,v) -G*M./(v*(y+R).^2), [y0, 100*R], v0);
% Plot solution
plot(t, v);
xlabel('Height (m)');
ylabel('Velocity (m/s)');
title('Gravitational Acceleration');

回答(1 个)

VBBV
VBBV 2023-4-19
The y0 and v0 values are both zero and that results in infinite value, which cannot be plotted. Give suitable values to both variables or ateast v0 since velocity of eath cannot be zero
y0 = 0; % initial height
v0 = 0; % initial velocity
G = 6.67430e-11; % gravitational constant
M = 5.9722e24; % mass of Earth
R = 6.371e6; % radius of Earth
y = -G*M./(v0*(y0+R).^2)
y = -Inf
plot(y)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by