Add Tex and update scripts

This commit is contained in:
Ceres 2025-10-21 08:53:34 +01:00
parent 791d876347
commit b5b7b31a87
Signed by: ceres-sees-all
GPG key ID: 9814758436430045
7 changed files with 147 additions and 9 deletions

6
.gitignore vendored
View file

@ -1 +1,7 @@
.vscode/settings.json
*.log
*.out
*.gz
*.aux
*.fdb_latexmk
*.fls

BIN
Exercise 1/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
Exercise 1/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

BIN
Exercise 1/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

View file

@ -61,19 +61,19 @@ def part1(velocityFactor, orbits):
plt.show()
def part2(velocityFactor, orbits):
#Part one Diffeq
def f_part1(t, state, Me, Mm, G):
xm, ym, vx, vy, xp, yp, vpx, vpy = state
#Part two Diffeq
def f_part2(t, state, Me, Mm, G):
xm, ym, vx, vy, xp, yp, vpx, vpy = state #all input values
xpm = xp-xm
ypm = yp-ym
dxmdt = vx
dxmdt = vx #moon diffeqs
dymdt = vy
dvxdt = -(Me*G*xm)/((xm**2+ym**2)**(3/2))
dvxdt = -(Me*G*xm)/((xm**2+ym**2)**(3/2))
dvydt = -(Me*G*ym)/((xm**2+ym**2)**(3/2))
dxpdt = vpx
dxpdt = vpx #probe diffeqs
dypdt = vpy
dvpxdt = -((Me*G*xp)/((xp**2+yp**2)**(3/2)))-((Mm*G*xpm)/((xpm**2+ypm**2)**(3/2)))
dvpydt = -((Me*G*yp)/((xp**2+yp**2)**(3/2)))-((Mm*G*ypm)/((xpm**2+ypm**2)**(3/2)))
@ -102,8 +102,8 @@ def part2(velocityFactor, orbits):
vx0 = 0
vy0 = vm
xp0 = rpm+rm
yp0 = 0
xp0 = rpm+rm #as position is relative to the earth
yp0 = 0 #not to the moon
vpx0 = 0
vpy0 = vm+vpm
@ -111,7 +111,7 @@ def part2(velocityFactor, orbits):
atol = 1e-9
#Solver
results = solve_ivp(f_part1, (t_min,t_max), (xm0, ym0, vx0, vy0, xp0, yp0, vpx0, vpy0), args=(Me, Mm, G), t_eval=t, atol=atol, rtol=rtol)
results = solve_ivp(f_part2, (t_min,t_max), (xm0, ym0, vx0, vy0, xp0, yp0, vpx0, vpy0), args=(Me, Mm, G), t_eval=t, atol=atol, rtol=rtol)
#Graph plotting

BIN
Exercise 1/main.pdf Normal file

Binary file not shown.

132
Exercise 1/main.tex Normal file
View file

@ -0,0 +1,132 @@
\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}
\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} \label{sec:Theory}
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_eM_mG}{|r_m|^2}\hat{r}_m=-\frac{M_eM_mG}{|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_eGx_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_eGy_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_eGx_p}{(x_p^2+y_p^2)^{3/2}}-\frac{M_eGx_{pm}}{(x_{pm}^2+y_{pm}^2)^{3/2}};\ \ \ \ \ \frac{\mathrm{d}x_p}{\mathrm{d}t}=v_{p,x}
\nonumber \\
\frac{\mathrm{d}v_{p,y}}{\mathrm{d}t}=-\frac{M_eGy_p}{(x_p^2+y_p^2)^{3/2}}-\frac{M_eGy_{pm}}{(x_{pm}^2+y_{pm}^2)^{3/2}};\ \ \ \ \ \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}}
\begin{figure} [!h]
\centering
\includegraphics[width=1\linewidth]{1.png}
\end{figure}
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.
\begin{figure} [!h]
\centering
\includegraphics[width=1\linewidth]{2.png}
\end{figure}
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.
\begin{figure} [!h]
\centering
\includegraphics[width=1\linewidth]{3.png}
\end{figure}
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{figure} [!h]
\includegraphics[width=1\linewidth]{4.png}
\end{figure}
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
\end{document}