function [dydt, alt] = satellite(t, y)
dydt(4) = - mu*y(1)/(norm(y(1:3))^3);
dydt(5) = - mu*y(2)/(norm(y(1:3))^3);
dydt(6) = - mu*y(3)/(norm(y(1:3))^3);
alt = sqrt(sum(y(1:3).^2)) - R;
r0 = [ 3207; 5459; 2714];
v0 = [-6.532; 0.7835; 6.142];
options = odeset('RelTol', 1e-6, 'AbsTol', 1e-8);
[t, y] = ode45(@satellite, [0, 5*3600], [r0; v0], options);
alt = zeros(1, numel(t));
[~, alt(j)] = satellite(t(j), y(j,:).');
[maxAlt, maxAltIdx] = max(alt);
timeOfMaxAlt = t(maxAltIdx);
fprintf('Maximum Altitude: %.2f km\n', maxAlt);
Maximum Altitude: 9675.90 km
fprintf('Time of Maximum Altitude: %.2f hours\n', timeOfMaxAlt/3600);
Time of Maximum Altitude: 1.70 hours
plot(t/3600, alt), grid on
xline(timeOfMaxAlt/3600, '--', sprintf('Max Time: %.4f hour', timeOfMaxAlt/3600), 'color', '#7F7F7F', 'LabelVerticalAlignment', 'bottom')
xlabel('Time [hour]'), ylabel('Altitude [km]')
title ('Altitude of Satellite')