Matlab code does not run past a certain point: i.e. buffers at a certain line of code
So I’m trying to solve a problem (attached below) and I’ve written the code (below) to solve it. When I go to run the code it gets stuck at the following line:
% Solve the ODEs numerically
%[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
It fully ran once, but continues to not run.
This is the problem:
Code:
G = 6.6742e-11; % universal gravitational constant (km^3/kg/s^2)
M = 5.974e24; % Earth mass estimate (kg)
R = 6378; % planet radius (km)
r0 = [3207 5459 2714]; % initial position vector (km)
v0 = [-6.532 0.7835 6.142]; % initial velocity vector (km/s)
t0 = 0; % initial time in seconds
% Define the ODEs
odeFunc = @(t, y) [y(4); y(5); y(6); -G*M*y(1)/(norm(y(1:3))^3); -G*M*y(2)/(norm(y(1:3))^3); -G*M*y(3)/(norm(y(1:3))^3)];
% Set options for ode45 solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Solve the ODEs numerically
[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
% Calculate altitude above Earth’s surface
altitudes = sqrt(sum(y(:, 1:3).^2, 2)) – R;
% Find the maximum altitude and the time at which it occurs
[maxAltitude, maxAltitudeIndex] = max(altitudes);
timeOfMaxAltitude = t(maxAltitudeIndex);
% Display the results
fprintf(‘Maximum Altitude: %.2f kmn’, maxAltitude);
fprintf(‘Time of Maximum Altitude: %.2f hoursn’, timeOfMaxAltitude / 3600);So I’m trying to solve a problem (attached below) and I’ve written the code (below) to solve it. When I go to run the code it gets stuck at the following line:
% Solve the ODEs numerically
%[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
It fully ran once, but continues to not run.
This is the problem:
Code:
G = 6.6742e-11; % universal gravitational constant (km^3/kg/s^2)
M = 5.974e24; % Earth mass estimate (kg)
R = 6378; % planet radius (km)
r0 = [3207 5459 2714]; % initial position vector (km)
v0 = [-6.532 0.7835 6.142]; % initial velocity vector (km/s)
t0 = 0; % initial time in seconds
% Define the ODEs
odeFunc = @(t, y) [y(4); y(5); y(6); -G*M*y(1)/(norm(y(1:3))^3); -G*M*y(2)/(norm(y(1:3))^3); -G*M*y(3)/(norm(y(1:3))^3)];
% Set options for ode45 solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Solve the ODEs numerically
[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
% Calculate altitude above Earth’s surface
altitudes = sqrt(sum(y(:, 1:3).^2, 2)) – R;
% Find the maximum altitude and the time at which it occurs
[maxAltitude, maxAltitudeIndex] = max(altitudes);
timeOfMaxAltitude = t(maxAltitudeIndex);
% Display the results
fprintf(‘Maximum Altitude: %.2f kmn’, maxAltitude);
fprintf(‘Time of Maximum Altitude: %.2f hoursn’, timeOfMaxAltitude / 3600); So I’m trying to solve a problem (attached below) and I’ve written the code (below) to solve it. When I go to run the code it gets stuck at the following line:
% Solve the ODEs numerically
%[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
It fully ran once, but continues to not run.
This is the problem:
Code:
G = 6.6742e-11; % universal gravitational constant (km^3/kg/s^2)
M = 5.974e24; % Earth mass estimate (kg)
R = 6378; % planet radius (km)
r0 = [3207 5459 2714]; % initial position vector (km)
v0 = [-6.532 0.7835 6.142]; % initial velocity vector (km/s)
t0 = 0; % initial time in seconds
% Define the ODEs
odeFunc = @(t, y) [y(4); y(5); y(6); -G*M*y(1)/(norm(y(1:3))^3); -G*M*y(2)/(norm(y(1:3))^3); -G*M*y(3)/(norm(y(1:3))^3)];
% Set options for ode45 solver
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Solve the ODEs numerically
[t, y] = ode45(odeFunc, [t0, 1.66*3600], [r0; v0], options);
% Calculate altitude above Earth’s surface
altitudes = sqrt(sum(y(:, 1:3).^2, 2)) – R;
% Find the maximum altitude and the time at which it occurs
[maxAltitude, maxAltitudeIndex] = max(altitudes);
timeOfMaxAltitude = t(maxAltitudeIndex);
% Display the results
fprintf(‘Maximum Altitude: %.2f kmn’, maxAltitude);
fprintf(‘Time of Maximum Altitude: %.2f hoursn’, timeOfMaxAltitude / 3600); ode45 MATLAB Answers — New Questions