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

1 view (last 30 days)
% 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');

Answers (1)

VBBV
VBBV on 19 Apr 2023
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)

Community Treasure Hunt

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

Start Hunting!