WHAT would be the reason this matlab code works but does not draw the graphic?
1 view (last 30 days)
Show older comments
% 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');
0 Comments
Answers (1)
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)
plot(y)
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!