\documentclass[twocolumn, 11pt]{article}
\usepackage{amsmath}
\usepackage{autobreak}
\usepackage{lineno,hyperref}
\usepackage[table,x11names,dvipsnames,table]{xcolor}
\usepackage{authblk}
\usepackage{subcaption,booktabs}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage[nolist,nohyperlinks]{acronym}
\usepackage[superscript]{cite}
\usepackage{tabularx}
\usepackage{float}
\usepackage[group-separator={,}]{siunitx}
\usepackage{geometry}
 \geometry{
 a4paper,
 papersize={210mm,279mm},
 left=12.73mm,
 top=20.3mm,
 marginpar=3.53mm,
 textheight=238.4mm,
 right=12.73mm,
 }

\setlength{\columnsep}{6.54mm}

%\linenumbers %%% Turn on line numbers here

\renewcommand{\familydefault}{\sfdefault}

\captionsetup[figure]{labelfont=bf,textfont=normalfont}
%\captionsetup[subfigure]{labelfont=bf,textfont=normalfont}

%%%% comment out the below for the other title option
\makeatletter
\def\@maketitle{
\raggedright\newpage
  \noindent
  \vspace{0cm}
  \let\footnote\thanks{\hskip -0.4em \huge \textbf{{\@title}} \par}
    \vskip 1.5em
    {\large
      \lineskip.5em
      \begin{tabular}[t]{l}
      \raggedright\@author\end{tabular}\par}
    \vskip 1em
    \@date\par
  \vskip 1.5em
  }
\makeatother

\begin{document}

\title{Exercise 1 Report}

\author[1]{Paddy Milner}

\affil[1]{Department of Physics, University of Bristol}
\renewcommand\Affilfont{\itshape\small}% chktex 6 

\date{01.03.2025}
\maketitle
\begin{abstract}

	The aim of this exercise was to use computational methods to model the gravitational interactions between the earth, the moon, and a lunar probe orbiting the moon. The model provided accurate results when provided with realistic starting conditions, and when the starting conditions were changed, the model responded as expected.

\end{abstract}

\section{Introduction}

In this exercise we will create a computational model to first simulate the orbit of the moon around the earth, and then the orbit of a lunar probe around the moon as well. Using these simulations, we will first use realistic starting conditions to verify that the simulations behave as expected, i.e.\ they behave how these objects do in real life. We will then alter these starting conditions and observe how these alterations affect the simulations result.

\section{Theory and Methods}

Our models will simply use Newton's equation for gravitational attraction,
\[F=\frac{GMm}{r^2}\]
Combined with Newton's second law of motion,
\[F=ma\]
to find the acceleration of the objects. For the moon's orbit around the earth, we find that
\[M_m\ddot{r}_m=-\frac{M_{e}M_{m}G}{|r_m|^2}\hat{r}_m=-\frac{M_{e}M_{m}G}{|r_m|^3}r_m\]
where $M_e$ is the mass of the earth, $M_m$ is the mass of the moon, $G$ is the gravitational constant, and $r_m=(x_m,y_m)$, the coordinates of the moon relative to the fixed origin at the centre of the earth. We will assume that the mass of the moon is negligible compared to that of the earth, and therefore the motion of the earth can be ignored, hence the fixed origin at its centre. From this, we can obtain the following differential equations:
\begin{align}
	\frac{\mathrm{d}v_{m,x}}{\mathrm{d}t}=-\frac{M_{e}Gx_m}{(x_m^2+y_m^2)^{3/2}};\ \ \ \ \ \frac{\mathrm{d}x_m}{\mathrm{d}t}=v_{m,x}
	\nonumber \\
	\frac{\mathrm{d}v_{m,y}}{\mathrm{d}t}=-\frac{M_{e}Gy_m}{(x_m^2+y_m^2)^{3/2}};\ \ \ \ \ \frac{\mathrm{d}y_m}{\mathrm{d}t}=v_{m,y}
	\label{eq:Moon}
\end{align}
This can then be extended to model the probe orbiting the moon as well. It feels attraction from both the moon and the earth, so needs terms for both:
\begin{align}
	\frac{\mathrm{d}v_{p,x}}{\mathrm{d}t}&=-\frac{M_{e}Gx_p}{(x_p^2+y_p^2)^{3/2}}-\frac{M_{e}Gx_{pm}}{(x_{pm}^2+y_{pm}^2)^{3/2}};
	\nonumber \\
	\nonumber \\
	\frac{\mathrm{d}x_p}{\mathrm{d}t}&=v_{p,x}
	\nonumber \\
	\nonumber \\
	\frac{\mathrm{d}v_{p,y}}{\mathrm{d}t}&=-\frac{M_{e}Gy_p}{(x_p^2+y_p^2)^{3/2}}-\frac{M_{e}Gy_{pm}}{(x_{pm}^2+y_{pm}^2)^{3/2}};
	\nonumber \\
	\nonumber \\
	\frac{\mathrm{d}y_p}{\mathrm{d}t}&=v_{p,y}\label{eq:Probe}
\end{align}
where $r_p$ is the position of the probe relative to the earth, and $r_{pm}=r_p-r_m$ is the position of the probe relative to the moon. These will then be solved in python using the scipy.integrate.solve\_ivp () method, after being supplied with initial condition for velocity and position.

\section{Explanation of Code}
\subsection{{Orbit of the Moon}}

\includegraphics[width=1\linewidth]{Images/1.png}

The function for part 1 takes 2 inputs, velocityFactor and orbits. These are scalar multipliers for the initial velocity and max time respectively, which can be altered as desired.
The function for the derivatives is then defined, taking an input of time, the initial state, the masses of each object and the gravitaional constant. State is provided as a tuple with 4 objects, and each value in it is then assigned to xm, ym, vx and vy. The equations for the derivative of each of these values, relating to the equations outlined in equation~\ref{eq:Moon} are then defined, and are returned in the same order they were initially given.

\includegraphics[width=0.95\linewidth]{Images/2.png}

The initial starting conditions of the system are then defined. $M_e$, $M_m$, $G$ and $r$ are all known and fixed quantities. The standard value for $v$, the initial velocity of the moon, is set by balancing centripetal force with gravitational force to produce a stable, circular orbit, however it can be changed by altering velocityFactor in order to produce an elliptical orbit.\ t\_max is set to the sidereal period of the moon multiplied by the number of orbits desired. The position and velocity are then split up into $x$ and $y$ values, and the simplest case is taken, with the moon starting on the $x$ axis and moving directly upwards, allowing us to set $y_m$ and $v_{x,m}$ to 0, and $x_m$ and $v_{y.m}$ to $r$ and $v$ respectively.

\includegraphics[width=0.95\linewidth]{Images/3.png}

The solve\_ivp() function is then called to solve the differential equations. The initial conditions are provided as a tuple, in the order defined in the differential equations function. The time range is also provided as a tuple, and the other arguments needed for the differential equations function are provided using args=. Matplotlib is then used to create a plot of the position of the moon at each time defined in t.\ x and y axes are then added for clarity.

\subsection{Lunar Probe}
\begin{center}
	\includegraphics[width=0.85\linewidth]{Images/4.png}
\end{center}
The initial configuration for section 2 is very similar to that of section 1. The function for the section also takes velocityFactor and orbits as inputs, which perform the same function as in section 1. The differential equations function has a similar form to the one in section 1, taking time, state and some constants as input. The differential equations that govern the movement of the moon and their associated state values are the same, but we now have the additional equations seen in equation~\ref{eq:Probe}, and the variables required for them. Each differential equation is then returned in the same order they were provided, as in the first part.

\includegraphics[width=0.95\linewidth]{Images/5.png}

We then set the initial conditions for both the moon and probe. The values for the moon are all the same as in section 1. The initial conditions for the probe are found by selecting an appropriate distance for the probe from the moons center, then again balancing centripetal and gravitational forces to find its velocity around the moon. However, as the coordinate system is relative to the earth and not the moon, both the initial position and velocity of the probe relative to the moon must be added to the position and velocity of the moon relative to the earth, in order to get the state of the probe relative to the earth. The tolerances for this part were set lower, as the motion of the probe is more precise than that of the moon, so this was required to achieve a good degree of accuracy.

\includegraphics[width=0.95\linewidth]{Images/6.png}

The results are then calculated using solve\_ivp (). Again this is very similar to the procedure in part 1, only with more variables for the initial state. Matplotlib is again used to plot the position of both the moon and the probe in the same fashion as part 1.

\section{Results and Discussion}
\subsection{Orbit of the Moon}
When given standard starting conditions, the simulation provided a stable and circular orbit, as expected, shown in figure~\ref{fig:MoonCircular}.
\begin{figure}
	\includegraphics[width=1\linewidth]{Images/7.png}
	\caption{Circular orbit as a result of standard initial conditions}\label{fig:MoonCircular}
\end{figure}

The simulation kept its shape for a large number of orbits, showing its stability. When the initial velocity was altered but the radius of the orbit was held, we observed a range of effects. For small alterations, approximately in the range of 0.1<velocityFactor<1.41, stable elliptical orbits were produced, as shown in figures~\ref{fig:MoonSmallElliptical} and~\ref{fig:MoonBigElliptical}.

\begin{figure}
	\includegraphics[width=1\linewidth]{Images/8.png}
	\caption{Elliptical orbit with a velocity of 0.4*v}\label{fig:MoonSmallElliptical}
\end{figure}

\begin{figure}
	\includegraphics[width=1\linewidth]{Images/9.png}
	\caption{Elliptical orbit with a velocity of 1.3*v}\label{fig:MoonBigElliptical}
\end{figure}

For velocities less than 0.1*v, the simulation began to fail, producing what was effectively noise. At velocities greater than 1.41*v, the moon appears to escape the orbit of the earth, as shown in figure~\ref{fig:MoonEscape}. These trajectories continued with increasing t\_max, to the point where simulation took a very long time, suggesting that they are not simply very large orbits.

\begin{figure}
	\includegraphics[width=1\linewidth]{Images/10.png}
	\caption{Moon escaping the earths orbit}\label{fig:MoonEscape}
\end{figure}
This can be compared with what we would expect using the escape velocity equation, which is given by
\begin{equation}
	v_e=\sqrt{\frac{2GM}{r}}
	\label{eq:Escape}
\end{equation}
As we find the velocity for a circular orbit by balancing centripetal and gravitational force, we use the equation
\begin{equation}
	v=\sqrt{\frac{GM}{R}}
	\label{eq:Velocity}
\end{equation}
We can see that the difference between equation~\ref{eq:Escape} and equation~\ref{eq:Velocity} is simply a factor of $\sqrt 2$, or 1.414, so our model holds well with what we would expect.

\subsection{Lunar Probe}
For standard starting values for section 2, we again see the moon in a stable circular orbit around the earth, and the probe forms a stable orbit around the moon as well, as shown in figure~\ref{fig:ProbeCircular}
\begin{figure}
	\includegraphics[width=1\linewidth]{Images/11.png}
	\caption{Circular orbit of moon and probe}\label{fig:ProbeCircular}
\end{figure}
When altering the initial velocity of the moon, for small changes we again see stable elliptical orbits. With increases above 1.41*v, causing the moon to escape the earth, the probe continues to orbit the moon in a stable manner, as shown in figure~\ref{fig:ProbeBigEscape}
\begin{figure}
	\includegraphics[width=1\linewidth]{Images/12.png}
	\caption{Moon and probe escaping the earth}\label{fig:ProbeBigEscape}
\end{figure}
When we decrease the starting velocity of the moon, it continues in a stable orbit, however when reaching the periapsis of the moons orbit, the probe is accelerated enough to escape the orbit of both the moon and the earth, as shown in figure\ref{fig:ProbeSmallEscape}
\begin{figure}
	\includegraphics[width=1\linewidth]{Images/13.png}
	\caption{Probe escaping the moon}\label{fig:ProbeSmallEscape}
\end{figure}
The point at which the probe escapes the moon can be increased by changing the direction of the probes orbit around the moon, simply by setting vpy0 = vm-vpm, rather than vm+vpm. Now, when the probe escapes the orbit of the moon, it is still gravitationally bound to the earth and enters an erratic orbit around it, shown in figure~\ref{fig:ProbeEarth}
\begin{figure}
	\includegraphics[width=1\linewidth]{Images/14.png}
	\caption{Probe escaping the moon and entering an orbit around the earth}\label{fig:ProbeEarth}
\end{figure}

\section{Conclusion}
Overall, the model produced mostly accurate results when given starting values somewhat close to realistic values, however began to lose clarity at extreme values, especially with low starting velocities. This could likely be improved by decreasing the tolerance of the model, however this would lead to larger calculation times. The model agreed with the value for the escape velocity of the moon, showing a good accuracy when provided with somewhat realistic data. Other improvements to the model could include adding a third dimension, as well as modelling the effects of the rotation of each of the objects, as these tidal forces do affect the path of the moons orbit in real life.
\end{document}
