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');
0 个评论
回答(1 个)
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)
plot(y)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!