% -*- latex -*-
\documentclass[letter,12pt]{article}
%---------------------------------------------------------------
%\usepackage{listings}
\usepackage[framed]{matlab-prettifier}
\usepackage{color}
\usepackage{fullpage}
\usepackage{enumitem} % control over itemize, list environment
%---------------------------------------------------------------

\begin{document}
\newcommand{\hwtitle}[1]{%
	\begin{center}
		\Large  \bf Midterm #1%
	\end{center}%
}

\newcommand{\mat}[1]{% matlab code
%{\color{blue}\texttt{#1}}%
	% this one does not work inside of captions
	{\lstinline[style = Matlab-editor, basicstyle = \mlttfamily, columns=fixed]!#1!}%
	% this one work but style is different
	%{\lstinline[columns=fixed]!#1!}%
}
%---------------------------------------------------------------
\newcommand{\problem}[1]{% homework problem
	%{\item  \bf #1%}
\item {\bf #1{}:}% the next blank line is important

}

\newcommand{\hide}[1]{}

\newenvironment{homework}[2]%
{%
	\hwtitle{#1}
	#2% Prerequisits

	\begin{enumerate}[
		label={\bf Problem\ \arabic*}, 
		leftmargin=0pt,
		start,
		labelindent=0pt,
		widest=20, align=left, itemindent=!
		]
}%
{%
	\end{enumerate}
}%
%---------------------------------------------------------------

\begin{homework}{03 Solar system celestial mechanics (100 points total)}{
%Prerequisites
\begin{itemize}
\item 
	One report per team is enough, but make sure everyone is
	listed in the authors list.
\item
	Discuss the relevant physics equations, describe your solution, show
	results. Report page limit is 10 pages excluding listings which should be
	in appendixes, font size to be no less than 12pt. 
	The emailed submission must have all relevant listings in the attachments.
\item 
	All Matlab code/scripts must be present in the carbon copy as well.
\item 
	Make all you calculations in the S.I. units (m, kg, s).
\end{itemize}

\vskip .5in

%Problem statement
%---------------------------------------------------------------
We will model the motion of the relevant bodies of the solar system governed by the
gravitational force. In total, we will consider 8 planets (Pluto is out),
the Sun, and the Moon. 

The model is simplified: 
\begin{itemize}
	\item assume that all bodies are moving in the same xy-plane
	\item disregard the influence of stars, asteroids and other objects
\end{itemize}


The data file with masses, initial positions, and velocities will be
provided on the web. Download the file \mat{'solar_system_data.mat'}
and load it
with \\
\mat{load 'solar_system_data.mat'}. \\
This will put the following variables to your workspace
\mat{body_names, xposition, yposition, vx, vy,} and \mat{mass}. These are
column vectors of corresponding data. To see which index corresponds to
which celestial body refer to the \mat{body\_names} variable. For example,
index 3 corresponds to Venus, since  \mat{body\_names(3)} yields \mat{'Venus'}.

Your job is to model the evolution of the many body system numerically (it is known that even
a 3 body system dynamics is impossible to do analytically in a general case).

{\bf Do not hardcode the number of the celestial
bodies}, i.e. pull/deduce this information from the data file.


{\flushleft \bf  Important equations.}

All you need to know is the Newton's second law ({\bf Pay attention to the
vector notation! If not sure consult with the class instructor})
\begin{eqnarray}
	m_i \vec{r}_i\,'' = m_i \vec{a}_i = \vec{F}_i
	\label{eq:nsl}
\end{eqnarray}
here $i$ is the index of the body, $m_i$ is its mass, $\vec{r}_i$ is the
radius vector pointing to the $i${th} body, $a_i$ is the $i${th} body acceleration.
The force ($\vec{F}_i$) acting on $i$th body is governed by the
gravitational pull of {\bf all} other bodies, we can write it  as
\begin{eqnarray}
	\vec{F}_i &=&  \sum_{j \neq i} \vec{F}_{ij} \\
	\vec{F}_{ij} &=& G \frac{ m_i m_j}{r_{ij}^3} \vec{r}_{ij} \\
	\vec{r}_{ij} &=&  \vec{r}_j - \vec{r}_i
	\label{eq:gravity}
\end{eqnarray}
here $G=6.67428 \times 10^{-11}$~$N m^2/kg^2$ is the gravitational
constant.

Since we consider only the xy-plane, all  vectors have no z
projection, i.e., $a_z=0$, $F_z=0, r_z=0, v_z=0$.
}




\problem{(40 points)}
Calculate all bodies positions for the time span of at least one orbital
period of Neptune ($\approx165$ years). Plot all $y_i(t)$ vs. $x_i(t)$
(i.e., orbit shapes) in the same graph for this time period.

\problem{(20 points)}
Make a movie of the planets motion for the first 12 years. Mark a planet
position with a circle proportional to the \mat{log10} of its mass (Sun might be an
exception, choose something reasonable for it) and  leave a trace of
previous positions with a line.  Make sure that you have
enough frames to show the dynamics of the system, but the movie size {\bf must not
exceed  2 MB}.


\problem{(20 points)}
Have a closer look at the path of the Moon. Does it 
cross its own path  or just wobble around the Earth's path?
From a distant observer point of view, does the Moon circle around
Earth?  Show the representative plot leading to your conclusion.

Now, plot the Moon track (x vs. y)  with respect to an observer on Earth.
I.e., calculate and plot x and y with respect to the center of Earth location.

Make your final conclusion whether the Moon orbits around Earth or not.


\problem{(20 points)}
Have a closer look at the Sun's orbit. Which planet has the most 
influence on the Sun's orbit? Try to remove the planet (assign its mass to zero) 
in question from
the system and compare the Sun tracks. Show  plots which support your
conclusion. Note: you might need a quite long time span.

Note: removal of any celestial  body will make the total momentum non
zero, which results in a combined drift  of the whole system in a
certain direction. Pay attention to this drift and the wobble around it.

\hide{ %{{{
\problem{(10 points)}
It is well known that the presence of Neptune was first calculated by
Urbain Le Verrier and
then Neptune was observed very close to the predicted
location in 1846. Le Verrier observed that he needed one more planet (later
named Neptune) to explain the deviation of Uranus from the calculated track.

Can you show that removal of Neptune modifies the orbit of Uranus?
Remember about the drift when a body is excluded from the system.

Make plots in
Cartesian and polar coordinates (see a note at the end).  Which one is more convincing?

\vskip .5in
{\flushleft \bf Note}: For some of these problems, it is more convenient to use the polar
coordinate system where you convert x and y to  $\rho=\sqrt{x^2+y^2}$ and
$\phi=\arctan(y/x)$. Use plots of $\rho$ vs. $\phi$, especially, for
differences in one track with respect to another.
} %}}} end of hide



\end{homework}
%---------------------------------------------------------------
\end{document}
%---------------------------------------------------------------
