School of AERoSPAcE EnginEERing
B. Tech ASE
VECTOR CALCULUS
Module 4: Vector Calculus
Lab exercise 4: Solution of Application Problems in
Engineering field
Report on Lab Task Using AI tools
Title:- Sun-Earth-Moon Three-Body Simulation
Submitted to
Dr. Ramesha M
Assistant Professor,
Department of Data Analytics and Mathematical Sciences,
Faculty of Engineering & Technology,
Jain (Deemed-To-Be) University.
Submitted by
USN Name
JUUG25BTECH24513 Fazleen Mehdi
JUUG25BTECH25592 Praneel Jupudi
JUUG25BTECH15799 Mansi Jain
JUUG25BTECH20217 Mohd. As-Haab Khalid
JUUG25BTECH12323 Ahaan Amit Gadgil
JUUGI25BTECH10697 Saanvi Sathish
JUUG25BTECH10873 Maaouli Bhadra
JUUG25BTECH31023 Tia Jain
Branch & Section: ASE
Date of Submission: 19/12/25
Table of Contents
Sl. No. Title Page No.
1 Introduction
2 Objectives
3 Problem Statement
4 Methodology & Mathematical Model
5 MATLAB Implementation & Results
6 Discussion and Interpretation
7 Conclusion
2|Page
Engineering Analysis Report: Sun-Earth-
Moon Three-Body Simulation
Date: October 26, 2023 Subject: Application of N-Body Dynamics and ODE Solvers in
Astrodynamics Software Used: MATLAB ode45
1. Executive Summary
This report details the simulation of the Sun-Earth-Moon three-body problem using
Newtonian gravitation and a numerical ODE solver (MATLAB's ode45). The objective was
to model the orbital trajectories of the Earth and Moon relative to the Sun over a period of
365 days. The simulation successfully generated the orbital path, demonstrating the Earth and
Moon orbiting the Sun while the Moon's trajectory closely follows the Earth's path. A notable
warning was encountered during integration, indicating a potential issue with the chosen step
size or system stiffness at a specific point in the simulation.
2. Introduction
2.1 Background
The Three-Body Problem is a famous challenge in classical mechanics, lacking a general
closed-form solution. Modeling the system requires numerical integration of the governing
differential equations. This simulation uses the general principles of Newtonian gravity to
model the gravitational forces between the Sun, Earth, and Moon.
2.2 Objective
The goal of this simulation is to:
1. Formulate the coupled second-order differential equations for the position of each
body.
2. Reduce the model to a system of first-order ODEs suitable for the ode45 solver.
3. Determine the orbital trajectories of the Earth and Moon over one Earth year (365
days).
2.3 System Constants and Initial Conditions
The simulation uses the following physical constants and initial conditions:
Paramete Descripti
Symbol Value Unit
r on
Gravitati $6.67430 Universal
$\text{m}^3/\text{kg}/\te
onal $G$ \times 10^{- gravitatio
xt{s}^2$
Constant 11}$ nal
3|Page
Paramete Descripti
Symbol Value Unit
r on
constant
$1.989
Mass of $M_{\text{sun
\times kg
Sun }}$
10^{30}$
$5.972
Mass of $M_{\text{eart
\times kg
Earth h}}$
10^{24}$
$7.348
Mass of $M_{\text{mo
\times kg
Moon on}}$
10^{22}$
1
Astronom
Earth $[1.496\time
$r_{\text{earth ical Unit
Initial s 10^{11}, m
}}$ (AU)
Position 0]$
from Sun
2222
$r_{\text{ear
Moon Relative
$r_{\text{moo th}} + [3.84
Initial m to Earth
n}}$ \times
Position 3333
10^{8}, 0]$
Earth $[0, 29.78 Tangentia
$v_{\text{earth
Initial \times m/s l velocity
}}$
Velocity 10^3]$ 4444
3. Mathematical Modeling
3.1 Governing Equation
The acceleration ($a_i$) of any body $i$ (Sun, Earth, or Moon) is the vector sum of the
gravitational accelerations exerted by the other two bodies $j$ and $k$. The gravitational
acceleration exerted by body $j$ on body $i$ is given by:
The net acceleration of body is:
4|Page
3.2 State-Space Formulation
For N=3 bodies, the system is governed by $N$ second-order vector differential equations,
resulting in a total of 3 x 2 = 6 second-order scalar ODEs (one for x and one for y per body).
This is transformed into a system of 12 first-order ODEs :
The state vector y contains the x and y positions and velocities for all three bodies:
4. MATLAB Implementation
The simulation span was set to 365 days, converted to seconds. The function threeBodyODE
calculates the derivatives (velocities and accelerations) for each body at every time step.
clear clc;
% Constants
G = 6.67430e-11; % gravitational constant (m^3/kg/s^2)
M_sun = 1.989e30; % mass of Sun (kg)
M_earth = 5.972e24; % mass of Earth (kg)
M_moon = 7.348e22; % mass of Moon (kg)
% Initial positions (meters)
r_sun = [0; 0]; % Sun at origin
r_earth = [1.496e11; 0];% Earth at 1 AU
r_moon = r_earth + [3.84e8; 0]; % Moon relative to Earth
% Initial velocities (m/s)
v_sun = [0; 0]; % Sun stationary
v_earth = [0; 29.78e3]; % Earth tangential velocity
5|Page
v_moon = v_earth + [0; 1.022e3]; % Moon velocity relative to Earth
% State vector initialization
y0 = [r_sun; r_earth; r_moon; v_sun; v_earth; v_moon];
% Time span (days converted to seconds)
T_days = 365;
tspan = [0 T_days*24*3600];
% ODE function definition (as per the attached code)
function dydt = threeBodyODE(t, y, G, M_sun, M_earth, M_moon)
% Extract positions and velocities (simplified for brevity)
r_sun = y(1:2);
r_earth = y(3:4);
r_moon = y(5:6);
% ... (rest of the extraction and acceleration calculations from original code) ...
dSE = norm(r_earth - r_sun);
dSM = norm(r_moon - r_sun);
dEM = norm(r_moon - r_earth);
a_sun = G*M_earth*(r_earth-r_sun)/dSE^3 + G*M_moon*(r_moon-r_sun)/dSM^3;
a_earth = G*M_sun*(r_sun-r_earth)/dSE^3 + G*M_moon*(r_moon-r_earth)/dEM^3;
a_moon = G*M_sun*(r_sun-r_moon)/dSM^3 + G*M_earth*(r_earth-r_moon)/dEM^3;
dydt = [y(7:12); a_sun; a_earth; a_moon];
end
% Solve ODE
[t, sol] = ode45(@(t,y) threeBodyODE(t,y,G, M_sun, M_earth, M_moon), tspan, y0);
6|Page
5. Results and Discussion
5.1 Orbital Trajectories
The simulation produced the following graphical result for the 365-day period9:
Sun Trajectory: The Sun remains fixed at the origin (0, 0)$ due to its dominant mass
and the initial condition of zero velocity.
Earth and Moon Trajectories: The Earth and Moon follow a near-identical elliptical
arc around the Sun, as the simulation covers only a quater of the Earth's orbit (from
the initial position at $(1.496 x 10^{11}, 0) to the final position on the positive y-axis).
The Moon’s trajectory is almost indistinguishable from Earth's on this large scale,
which is typical for a barycentric simulation where the Moon is a small perturbation
to the Earth's solar orbit.
5.2 Computational Warning and Analysis
The MATLAB solver issued a warning during the computation12:
Warning: Failure at $t=7.211795 \times 10^{6}$. Unable to meet integration tolerances
without reducing the step size below the smallest value allowed...
This indicates that at a specific time (approximately 83.4 days into the simulation), the
problem became stiff—meaning the solution was changing very rapidly—likely due to the
close proximity of the Moon to the Earth. The ode45 solver, which is optimized for non-stiff
7|Page
problems, struggled to maintain the required accuracy (tolerance) without taking excessively
small steps.
5.3 Model Limitations
The current model has limitations inherent to the initial conditions and simplifying
assumptions:
1. Fixed Sun: The Sun's velocity is set to zero, neglecting its slight motion due to the
pull of the planets13.
2. Planar Orbit: The simulation is restricted to two dimensions (the $xy$-plane),
ignoring the slight inclination of the Moon's orbit relative to the Earth's orbit.
6. Conclusion and Recommendations
The three-body problem simulation successfully modeled the initial phase of the Earth and
Moon's combined orbit around the Sun, confirming the fundamental orbital mechanics. The
results show the dominant influence of the Sun and the Moon's trajectory tightly coupled to
the Earth.
Recommendation:
To resolve the integration warning and improve the fidelity of the simulation for longer time
spans, it is recommended to switch to an ODE solver designed for stiff systems, such as
MATLAB's ode15s or ode23t, which can better handle the rapid changes in acceleration
when the Moon is in certain orbital positions relative to the Earth and Sun.
8|Page