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

1 visualizzazione (ultimi 30 giorni)
Laura il 19 Apr 2023
Risposto: VBBV il 19 Apr 2023
% 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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

VBBV il 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)
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Graphics in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by