Professional Documents
Culture Documents
Maths 5
Maths 5
Maths 5
Now, sub in the corrected expanded values into the finite difference formula:
( )
'' 2 ''' 3 ' '' ' 4 '' 2
f ( x j ) h f ( x j ) h f ( s 1) h
' ' f ( x j) h f ' ' ' (x j )h3 f
f (x j )≈ −2 f ( x j )−f ( x j ) h+ − + −3 f ( x j ) +6 (f ( x j) + f ( x j ) h+ +¿ +
''
2 6 24 2 6
¿
'' h
f ( x j ) ≈ ¿) = O(h^2)
3
2a)
for k = 1:n-1
F1 = h(k) * fun(t(k), y(:, k));
F2 = h(k) * fun(t(k) + (8/15) * h(k), y(:, k) + (8/15) * F1);
F3 = h(k) * fun(t(k) + (2/3) * h(k), y(:, k) + (1/4) * F1 + (5/12) * F2);
y(:, k + 1) = y(:, k) + (F1 + 3 * F3) / 4;
end
end
2b)
Given the problem with mass ratio µ:
Let y(t) = (y1(t), y2(t), y3(t), y4(t)) = (x(t), y(t), x’(t), y’(t))
We want to express the equations of motion as a system of ODEs, y' = F(y; µ).
y1'(t) = y3(t)
y2'(t) = y4(t)
y3'(t) = -[(1 - µ) * (y1(t) + µ) / r^3 + µ * (y1(t) - 1 + µ) / r1^3]
y4'(t) = -[(1 - µ) * y2(t) / r^3 + µ * y2(t) / r1^3]
Where:
r1 is the distance between the spacecraft and the Moon, given by r1 = sqrt((y1(t) + µ)^2 +
y2(t)^2).
These ODEs describe the motion of the spacecraft in a non-dimensionalized rotating coordinate
system and are used to simulate its trajectory.
y3 = y(3);
y4 = y(4);
clear all
close all
f)
% Define the initial conditions for the free-return trajectory
y0_free_return = [-0.0233267; -0.0125213; 8.03118; -7.16836];
t_free_return = linspace(0, 1.36569, 1000); % Adjust time span and number of points
% Solve the ODEs for the free-return trajectory using one of the solvers
[t_free, y_free] = odesRK3(@(t, y) orbitRates(y, 1.21506e-2), t_free_return, y0_free_return);
% You can use any of the solvers, but odesRK3 is a good choice for high accuracy.