\chapter{Work and Energy}

In this chapter, we are going to talk about how engineers define work
and energy.  We have already talked about force.  We measure force in
newtons, and one newton is the force necessary to accelerate on
kilogram at a rate of one meter per second per second.

When you lean on a wall, you are exerting a force on the wall, but you
aren't doing any work. On the otherhand, if you push a car for a mile,
you are clearly doing work. Work, to an engineer, is the force you
apply to something and the distance that the it moves in the direction
of that force. We measure work in \textit{joules}. A joule is one
newton of force over one meter.

For example, if you push a car uphill with a force of 10 newtons for 12
meters, you have done 120 joules of work.\index{work}

Work is how energy is transferred from one thing to another. When you
push the car, you burn the sugars in your blood. That energy is
transferred to the car: after it has been pushed uphill, the car has
more potential energy.

Thus, we measure the energy something consumes or generates in the
units of work: joules, killowatt hours, horsepower-hours, foot-pounds,
BTUs, and calories.

Let's go over a few different forms that energy can take.

\section{Heat}\index{heat}

When you heat something, you are transferring energy to it.  The BTU
(British Thermal Unit) is a common unit for heat: One BTU is the
amount of heat required to raise the temperature of one pound of water
by one degree. A BTU is about 1,055 joules. When you buy and sell
natural gas as a fuel, it is priced by the BTU.\index{heat} \index{BTU}

\section{Electricity}\index{electricity}

Electricity is the motion of electrons. When you push electrons
through something that resists their passage (like a light bulb),
energy is transferred from the power source (a generator or a battery)
and into the source of the resistance. A \textit{coulomb} is about
$6.24 \times 10^18$ electrons.  If you push one coulomb per second,
you are said to be producing a current of one \textit{ampere} or
\textit{amp}. Electrical resistance is measured in \textit{ohms}.\index{coulombs}\index{amperes or amps}\index{ohms}

\begin{mdframed}[style=important]
The power consumed by a resistance is given by

$$P = I^2R$$

where $P$ is the power consumed in watts, $I$ is the current in amps,
and $R$ is the resistance in ohms.\index{watts}

\end{mdframed}

If your lightbulb consumes 60 watts, and you leave it on for 24 hours,
we say that you have consumed 1.44 kilowatt hours. One kilowatt hour
is the same as 3,600,000 joules.

\section{Chemical Energy}\index{chemical energy}

As mentioned early, some chemical reactions consume energy and some
produce energy. Thus, energy can be stored in the structure of a
molecule. When a plant uses photosynthesis to rearrange water and
carbon dioxide into a sugar molecule, it is converting the energy in
the sunlight into chemical energy. The sugar molecule has more
chemical energy than the carbon dioxide and water molecules that were
used in its creation.

In our diet, we measure this energy in \textit{kilocalories}. A
calorie is the energy necessary to raise one gram of water one degree
Celsius; it is about 4.19 joules. This is a very small unit: an apple
has about 100,000 calories, so people working with food started
measuring everything in kilocalories.\index{calories}

Here is where things get dumb: People who work with food got tired of
saying ``kilocalories'', so they just started using ``Calorie'' to
mean 1,000 calories.  This has created terrible confusion over the
years. If it is capitalized, ``Calorie'' probably means kilocalorie.

\section{Kinetic Energy}\index{kinetic energy}

A mass in motion has energy. For example, if you are in a moving car
and you slam on the breaks, the kinetic energy in the motion of the
car will be converted into heat in the breaks and under the tires.

How much energy does the car have?

\begin{mdframed}[style=important, frametitle={Formula for Kinetic Energy}]

$$E = \frac{1}{2} m v^2$$

where $E$ is the energy in joules, $m$ is the mass in kilograms, and
$v$ is the speed in meters per second.

\end{mdframed}

\section{Gravitational Potential Energy}\index{potential energy!gravitational}

When you lift something heavy onto a shelf, you are giving it
\textit{potential energy}. The amount of energy that you transferred
to it is proportional to its weight and the height that you lifted it.

On the surface of the earth, gravity will accelerate a heavy object at
a rate of $9.8 m/s^2$.

\begin{mdframed}[style=important, frametitle={Formula for Gravitational Potential Energy}]
On earth, then, gravitational potential energy is given by

$$E = (9.8)mh$$

where $E$ is the energy in joules, $m$ is the mass of the object you
lifted, and $h$ is the height that you lifted it.

\end{mdframed}

There are other kinds of potential energy. For example, when you draw
a bow, you have given that bow potential energy. When you release it,
the potential energy is transferred to the arrow, which expresses it
as kinetic energy.

\section{Conservation of Energy}

The first law of thermodynamics says ``Energy is neither created nor
destroyed.''\index{energy!conservation of}

Energy can change forms: Your cells consume chemical energy to give
gravitational potential energy to a car.  However, the total amount of
energy in a closed system stays constant.

\begin{Exercise}[title={The Energy of Falling}, label=energy_falling]

A 5 kg cannonball falls off the top of a 3 meter ladder. Just before
it hits the floor, all of its gravitational potential energy has been
converted into kinetic energy.  How fast is the cannonball going when
it hits the floor?

\end{Exercise}
\begin{Answer}[ref=energy_falling]

  At the top of the ladder, the cannonball has $(9.8)(5)(3) = 147$ joules of potential energy.

  At the bottom, the kinetic energy $\frac{1}{2}(5)v^2$ must be equal
  to 147 joules. So $v^2 = \frac{294}{5}$.  Thus it is going about
  $7.7$ meters per second.

  (Yes, a tiny amount of energy is lost to air resistance. For a dense
  object moving at these relatively slow speeds, this energy is
  neglible.)

\end{Answer}

\section{Efficiency}

Although energy is always conserved as it moves through different
forms, we aren't always that good at controlling it.\index{efficiency}

For example, an car engine consumes chemical energy in gasoline. Only
about 20\% of the energy consumed is used to turn the wheels.  Most of
the energy is lost as heat. If you run a car for a while, the engine
gets very hot and the exhaust going out the tail pipe is hot.

A human is about 25\% efficient. Most of the loss is in the heat
during the chemical reactions that turn food into motion.

In general, if you are trying to increase efficiency in any system,
the problem is usually easy to identify because heat is produced.

Light bulbs are an interesting case. To get the light of a 60 watt
incandescent bulb, you can use an 8 watt LED or a 16 watt flourescent
light. Thus, we say that the LED light is much more efficient: If you
run both, the incandescent bulb will consume 1.44 kilowatt-hours. The
LED will consume only 0.192 kilowatt hours.

Besides light, the incandescent bulb is producing a lot of heat. If it
is inside your house, what happens to the heat? It warms your house.

In the winter, when you want light and heat, the incandescent bulb is
100\% efficient!

In the summer, if you are running the air conditioner, the
incandescent bulb is worse that just ``inefficent at making light'' --
it is creating heat that has to be removed by the air conditioner!


\chapter{Coalescence}

    \begin{definition*}[Petri Nets]
        For the purposes required here, a \textit{petri net} $\mathcal{N}$ is $(\mathcal{P, F})$ where $f \in \mathcal{F} : \mathcal{P}^m \times \mathcal{P}$.
        In particular, $\mathcal{P}$ is a set of places and $\mathcal{F}$ a set of flows or transitions.
        A \textit{configuration} is a set $\mathcal{C} \subset \mathcal{P}$ of tokens in places.

        Notation from here follows the convention used by \citet{naming-proofs-in-cl} of iterating over places in a formula and indexing by $i \in \mathcal{N}$.
        Given a formula in classical logic, conjunction or disjunction is encoded as:
        \begin{align*}
            P_1 \vee_2 Q_3    &\quad\mapsto\quad \{ (P_1) \times \vee_2, (Q_3) \times \vee_2 \} \\
            P_1 \wedge_2 Q_3 &\quad\mapsto\quad \{ (P_1, Q_3) \times \wedge_2 \}
        \end{align*}
        where $A, B$ are (not necessarily unique) subformulae in unique places iterated over by $\{1, 2, \ldots\}$.
        Subsequently, in an expression such as $A_1 \wedge_2 A_3$, a token on $A_1$ is unique to a token on $A_3$

        This is then a direct continuation of the concepts explored by \citet{petri-nets}.
    \end{definition*}

    \begin{example*}
        Consider the 2-d petri net representing the cross-product $a \vee \neg a \otimes \neg a \wedge a$ as follows:
        \input{coalescence-example-1}
    \end{example*}

    \begin{definition*}[Firing Petri Nets]
        Given a petri net $\mathcal{N}$ and configuration $\mathcal{C}$, a \textit{firing} of the net $\mathcal{N}$ is a new configuration generated by application of a transition $f \in \mathcal{F}$ on $m$ tokens $c_1 \ldots c_n \in \mathcal{C}$.
        In particular:
        \begin{equation*}
            (\mathcal{N = (P, F), C}) \mapsto (\mathcal{N}, (\mathcal{C} \cup f_{right}) \setminus f_{left})
        \end{equation*}
        for some $f = (f_{left}, f_{right}) \in \mathcal{F}$.

        For the uses required here, a variant of firing is used instead called \textit{spawning}.
        This generates new configurations in the same manner as firing, with one key difference:
        \begin{equation*}
            (\mathcal{N = (P, F), C}) \mapsto (\mathcal{N}, \mathcal{C} \cup f_{right})
        \end{equation*}
        for some $f = (f_{left}, f_{right}) \in \mathcal{F}$.
        That is, when a transition $f$ is performed on tokens $x_1 \ldots _n$, these tokens remain present in the configuration in addition to the new token $f(x_1 \ldots x_n)$.

        A petri net is said to be \textit{exhaustively fired} if it is fired until there does not exist any such $f \in \mathcal{F}$ to fire.
    \end{definition*}

    \begin{example*}
        Consider the 2d petri net representing $a \vee \neg a \otimes \neg a \wedge a$ with tokens at $\{(a, \neg a), (\neg a, a)\}$.
        \input{coalescence-example-2}
        Note that, in the final step, a pair of tokens are required to perform the conjunction transition.
    \end{example*}

    \begin{definition*}[Coalescence]
        Given a formula $P$, the coalescence algorithm is as follows:
        \begin{enumerate}[nosep]
            \item Set  $n \seteq 1$
            \item Construct a $n$-dimensional petri net $\mathcal{N}$ as $\bigotimes_n P$ where each subformula represents a place and each conjunction and disjunction a flow
            \item Construct a configuration $C$ with a token at every $(\ldots, \top, \ldots)$ an instance of \textit{top} and every $(\ldots, a, \ldots, \neg a, \ldots)$ the intersection of a pair of tautological atoms.
            \item Exhaustively fire the petri net $\mathcal{N}$ using the \textit{spawning} method
            \item If there exists a token in the configuration $\mathcal{C^*}$ at the root of the formula $P$, halt and return $n$
            \item Otherwise, increment $n \seteq n + 1$ and go to step 2
        \end{enumerate}
    \end{definition*}

    \begin{example*}
        Consider the petri net proof for the formula $(a \vee b) \vee \neg a$, with a solution for $n = 2$.
        The net is initialised with tokens in all places satisfying either the $ax$-rule or $\top$-rule and fired exhaustively:
        \input{coalescence-example-3}
    \end{example*}

    \begin{remark*}
        Note the symmetry along the upper-left lower-right diagonal.
        In fact, this symmetry can be exploited in the general case, ignoring all tokens below (w.l.o.g.) the diagonal as they simply express the commutativity property $\vdash A, B \iff \vdash B, A$.
        If this is the case, the coalescence algorithm may halt early if the root of the formula is reached.
    \end{remark*}

    \begin{example*}
        Consider the petri net proof for the formula $(a \vee \neg a) \wedge (b \vee \neg b)$, with a solution for $n = 3$.
        In an exhaustively fired net for $n = 2$, the proof looks as follows:
        \input{coalescence-example-4}
        The coalescence algorithm fails to find a solution in 2 dimensions due to the lack of tokens in upper-right or lower-left quadrants.
        If there were tokens in such a place, the tree would be able to continue to grow towards the formula root at the centre of the net.
    \end{example*}

    \begin{remark*}
        Implementing firable petri nets is straightforward using an $n$-dimensional boolean array of places visited and a collection of $n$-tuples representing tokens.
        Within the context of coalescence proof search, this can be optimised in many ways, in this case a upper-triangular n-dimensional boolean matrix of places visited and a red-black tree of n-dimensional boolean array tokens can be used.
        This exploits most of the available symmetry in the structure of the nets as, in implementation, memory quickly becomes the limiting factor.
        Furthermore, this structure allows for $\mathcal{O}(\log{}n)$ insertion and removal, $\mathcal{O}(n)$ iteration and minimal memory.
    \end{remark*}

    \begin{proposition*}[Coalescence Proof Search]
        The coalescence algorithm on $P$ is exactly a proof search on $P$.
    \end{proposition*}

    \begin{proof}
        In particular, consider the additively stratified $\vdash P$ with $n - 1$ contractions (should such a proof exist).
        The first configuration of tokens is precisely a proof all possible combinations of the \textit{axiom} rule with $n - 3$ other terms through the \textit{weakening}.
        Each flow transition followed when fired is an application of either the $\vee$ or $\wedge$ rule.
        Finally, a token at the root of the formula is $\vdash P \ldots P$, with the \textit{contraction} rule applied implicitly.

        If there exists an additively stratified proof of $P$, the coalescence algorithm will find it.
        Since for every proof there exists an additively stratified proof, coalescence is precisely proof search.
    \end{proof}


% !TEX root = ../bachlor-arbeit.tex
The $S$-matrix calculus enables us to calculate the optical behavior of a stack if we know the optical behavior of all its layers in the form of their $S$-matrices. In section \ref{sec:s_mats} we derived the $S$-matrices of propagation through and interfaces between homogeneous isotropic materials. This calculation is based on the Fresnel equations and is therefore analytic.
However, we cannot calculate the $S$-matrix of a metasurface analytically. This results in a semi-analytic Stacking Algorithm where the $S$-matrices of the metasurfaces need to be provided but the remaining $S$-matrices can be calculated based on geometric parameters.
\\

$\qquad$ A core idea of this algorithm is the fact that geometric transformations like rotation and mirroring can be applied directly to Jones matrices. For example, let $\hat M$ be the Jones matrix of an optical component, then the Jones matrix of the rotated component $\hat{M}_{\varphi}$ is calculated as

\begin{equation}
    \hat{M}_{\varphi} =
    \hat \Theta(-\varphi) \, \hat{M} \, \hat \Theta(\varphi),
    \qq{where}
    \hat \Theta(\varphi) =
    \begin{pmatrix}
        \cos \varphi & \sin \varphi \\
        -\sin \varphi & \cos \varphi
    \end{pmatrix}.
\end{equation}

On this basis we can rotate $S$-matrices in a similar manner and

\begin{equation}
    \hat S_\varphi =
    \begingroup
    \renewcommand*{\arraystretch}{1.5}
        \begin{pmatrix}
            \hat \Theta(-\varphi) \hat T^f \hat \Theta(\varphi)&
            \hat \Theta(-\varphi) \hat R^b \hat \Theta(\varphi)\\
            \hat \Theta(-\varphi) \hat R^f \hat \Theta(\varphi)&
            \hat \Theta(-\varphi) \hat T^b \hat \Theta(\varphi)
        \end{pmatrix}
    \endgroup.
\end{equation}

Flipping and mirroring of $S$-matrices is done analogously. With all mathematical operations well defined we can write down SASA in pseudo code.

\comment{
\begin{figure}[H]
    \centering
    \includegraphics[width=.4\linewidth]{bg_two_layers}
    \caption{An example for a two layer metasurface stack. The top layer consist of rectangular gold particles arranged on a square matrix of period $\Lambda$. The bottom layer consist of rectangular holes in a gold sheet which are rotated by an angle of $\varphi$ in respect to the top layer. The two metasurfaces are separated by a glass spacer of thickness $d$.}
    \label{fig:bg:two_layers}
\end{figure}
}

\begin{figure}[H]
\begin{algorithm}[H]
    \SetAlgoLined
    \KwIn{Stack = $[\text{Layer}\, 0, \, \text{Layer 1}, \, \, \dots]$}
    \KwOut{Stack $S$-matrix}
    $S$-mats = $[\ ]$ \\
    \For{$i = 0$;  $i < \s{len}(\s{Stack})$;  $i = i+1$;}{
        \uIf{Stack$[i]$ \KwIs metasurface}{
            add layer $\hat S$ to $S$-mats
        } \Else {
            calculate propagation $S$-matrix $\hat S_{n_i,d_i}$ \\
            add $\hat S_{n_i,d_i}$ to $S$-mats
        }
        apply geometric transformations to added $S$-matrix \\
        calculate interface $S$-matrix $\hat S_{n_i,n_{i+1}}$ \\
        add $\hat S_{n_i,n_{i+1}}$ to $S$-mats
    }
    $\hat S = \mathds 1$ \\
    \For{$i = 0$;  $i < \s{len}(\text{S-mats})$;  $i = i+1$;}{
        $\hat S = \hat S \star S$-mats$[i]$
    }
    \KwRet{$\hat S$}
\end{algorithm}
\begin{tabular}{ll}
    SASA pseudo code: &
    \begin{tabular}[t]{@{}l@{}}
        A Layer variable holds all the information of that layer, that is the $S$-matrix if \\
        its a metasurface and the refractive index $n$ and thickness $d$ otherwise.
    \end{tabular}\\
\end{tabular}
\end{figure}

\paragraph{Conditions}~\\
\label{par:conditions}For this algorithm to produce physical valid output, some conditions need to be met. Equations that are boundary conditions to the algorithm will be marked bold. It has been shown \cite{Simovski2007} that the $S$-matrix calculus can only be used when the meta materials in the stack do not interact with each other via the near field. That is, only the zeroth diffraction order of a metasurface can be non-evanescent and higher orders need to have decayed enough when they reach the next metasurface.

First, we need to ensure that only the zeroth diffraction order is non evanescent by requiring

\begin{boldequation} \label{bg:eq:lamda}
    \lambda > \max(n^f, n^b) \cdot \Lambda.
\end{boldequation}

Additionally, the distance between metasurfaces needs to be large enough so that all higher order modes have decayed. It was shown in \cite{Menzel2016} that if we demand

\begin{boldequation}
    e^{\Im(k_z)d} < e^{-2} \approx 0.14,
    \qq{then}
    d > \frac{\Lambda}{\pi \sqrt{1 - \frac{\Lambda^2 n^2}{\lambda^2}}}.
\end{boldequation}

The factor $e^{-2}$ was chosen arbitrarily. A smaller value increases the agreement of the $S$-matrix calculus and more rigorous numerical methods which also take into account the near field. One of these, the \hyperref[sec:FMM]{Fourier Modal Method} will be described in more detail in section \ref{sec:opt}.

\paragraph{Symmetries}~\\
\label{sec:symmetries}We can use geometric transformations to examine the $S$-matrices of metasurfaces which satisfy certain symmetries. We will start with mirror symmetry. The Jones matrix $\hat M'$ of a mirrored component $\hat M$ can be calculated as

\begin{equation}
    \hat M' = \hat F^{-1} \hat M \hat F \qq{where}
    \hat F =
    \begin{pmatrix}
        1 & \phantom{-} 0 \\
        0 & -           1
    \end{pmatrix}.
\end{equation}

If a metasurface has mirror symmetry, the $S$-matrix needs to satisfy
$\hat S = \hat S'$
and therefore all the contained Jones matrices need to satisfy this condition too.

\begin{equation}
\begin{aligned}
    \qq*{Let} \hat T^f =
    &\begin{pmatrix}
        A & B \\
        C & D
    \end{pmatrix},
    \qq{then} \\
    \qty(\hat T^f)' =
    \hat F^{-1} \hat T^f \hat F =
    \begin{pmatrix}
        1 & \phantom{-} 0 \\
        0 & -           1
    \end{pmatrix}
    &\begin{pmatrix}
        A & B \\
        C & D
    \end{pmatrix}
    \begin{pmatrix}
        1 & \phantom{-} 0 \\
        0 & -           1
    \end{pmatrix}
    \stackrel{!}{=}
    \begin{pmatrix}
        A & B \\
        C & D
    \end{pmatrix} =
    \hat T^f \\
    \Rightarrow \qquad
    \hat T^f =
    &\begin{pmatrix}
        A & 0 \\
        0 & D
    \end{pmatrix}.
\end{aligned}
\end{equation}

We can also examine rotational symmetry with the rotation matrix $\hat \Theta(\varphi)$. A metasurface of $C_4$ symmetry, for example square shaped meta particles, maps onto itself if rotated $90^\circ$. That means the $S$-matrix should also remain equal, so
$\hat S_{\pi/2} \stackrel{!}{=} \hat S$
and

\begin{equation}
\begin{aligned}
    \hat T^f_{\pi/2} =
    \hat \Theta(-\pi/2) \,
    \hat T^f \,
    \hat \Theta(\pi/2)
    &\stackrel{!}{=}
    \hat T^f
    \qq*{,}
    \hat \Theta(\pi/2) =
    \begin{pmatrix}
        \phantom{-} 0 & 1 \\
        -1 & 0
    \end{pmatrix} \\
    \Rightarrow \qquad
    \hat T^f &=
    \begin{pmatrix}
        \phantom{-} A & B \\
        -           B & A
    \end{pmatrix}.
\end{aligned}
\end{equation}

So if a metasurface has both mirror and $C_4$ symmetry, its $\hat T^f$ matrix has the form

\begin{equation}
    \quad
    \hat T^f =
    \begin{pmatrix}
        A & 0 \\
        0 & A
    \end{pmatrix}.
\end{equation}

In this case the star product is commutative and therefor the stack will behave the same for light coming from the top and bottom.
It should be noted that these considerations apply to all Jones matrices and not only to $\hat T^f$.


\subsubsection{Key Management}
\label{sec:721KeyManagement}
There are several pairs of public and private keys to keep track of throughout these protocols. We provide a summary here (for an actor Alice ($A$)):

\begin{center}
	\resizebox{\textwidth}{!}{
	\begin{tabular}{ c c c c c }
		\textbf{Ownership of...} & \textbf{Account symbol} & \textbf{Private Key} & \textbf{Public Key} & \textbf{Notes}\\
		\\
    \makecell{Ethereum address} & $E_A$ & $sk^E_A$ & $pk^E_A$ & Used for `mint' and `burn'. \\
		\\
    \makecell{Anonymous Ethereum addresses} & $\Xi_{A,i}$ & $sk^{\Xi}_{A,i}$ & $pk^{\Xi}_{A,i}$ & Used for `transfer'. $i\in\mathbb{N}$.\\
		\\
    \makecell{Ethereum Whisper accounts} & $W_{A,j}$ & $sk^{W}_{A,j}$ & $pk^{W}_{A,j}$ & Used for private messaging. $j\in\mathbb{N}$\\
		\\
    \makecell{ERC-721 commitment $Z_l$} & $Z_l$ & $sk^{Z,l}_{A}$ & $pk^{Z,l}_{A}$ & Used to `mint', `transfer' and `burn' $Z_l$.\\

	\end{tabular}
	}
\end{center}
\ \\
Hereafter, when we write $sk_A$ and $pk_A$ we will be referring to $sk^{Z,l}_{A}$ and $pk^{Z,l}_{A}$ respectively (where $Z_l$ is clear from context) - unless otherwise stated.


\chapter{Model specification in the core functions}
\label{chap:modelspec}
Most users will not directly work with the core functions nor build marssMODEL objects from scratch.  Instead, they will interact with the core functions via the function \verb@MARSS()@ described in Chapter \ref{chap:MARSS}.  With the \verb@MARSS()@  function, the user specifies the model structure with matrices or text strings (``diagonal'', ``unconstrained'', etc.) and \verb@MARSS()@ builds the marssMODEL object.   However, a basic understanding of the structure of marssMODEL objects is useful if one wants to  interact directly with the core functions.

\section{The fixed and free components of the model parameters}\index{model specification!in marssMODEL objects}
In a marssMODEL object, each parameter is written in vec form and specificed by the equation of the form $\ff + \DD\bbeta$ as in Equation 77 in \citet{Holmes2010}. $\ff$ is the fixed matrix, $\DD$ is the free matrix and $\bbeta$ is the column vector of parameters.  In a marssMODEL object, the \verb@fixed@ list has the $\ff$ for each parameter matrix, the \verb@free@ list has the $\DD$ matrix for each parameter matrix, and \verb@par@ in the marssMLE object has the $\bbeta$ column vector of estimated parameters.

\section{Examples}

\subsection{$\QQ$ is a diagonal matrix with one variance value}
In this case, there is only one value on the diagonal and the off-diagonals are 0.  Thus there is only one estimated parameter and the fixed values are all 0.
\begin{equation*}
\QQ = \left[ \begin{array}{ccc}
    \alpha & 0 & 0 \\
    0 & \alpha & 0 \\
    0 & 0 & \alpha \end{array} \right]
\end{equation*}
\verb@fixed$Q@ is
\begin{equation*}
\ff = \left[ \begin{array}{c}
    0 \\
    0 \\
    0 \\
    0 \\
    0 \\
    0 \\
    0 \\
    0 \\
    0
    \end{array} \right]
\end{equation*}
\verb@par$Q@ is
\begin{equation*}
\bbeta =
 \left[ \begin{array}{c}
    "alpha"
\end{array} \right]
\end{equation*}
and \verb@free$Q@ is
\begin{equation*}
\DD = \left[ \begin{array}{c}
    1 \\
    0 \\
    0 \\
    0 \\
    1 \\
    0 \\
    0 \\
    0 \\
    1
 \end{array} \right]
\end{equation*}
Notice that $\ff + \DD\bbeta$ is the vec of $\QQ$.

\subsection{$\QQ$ is a diagonal matrix with unique variance values}

\begin{equation*}
\QQ = \left[ \begin{array}{ccc}
    \alpha_1 & 0 & 0 \\
    0 & \alpha_2 & 0 \\
    0 & 0 & \alpha_3 \end{array} \right]
\end{equation*}
The fixed matrix is the same with all 0s, but the par and free matrices change. \verb@par$Q@ is
\begin{equation*}
\bbeta =
 \left[ \begin{array}{c}
    "alpha1" \\
    "alpha2" \\
    "alpha3" \\
\end{array} \right]
\end{equation*}
and \verb@free$Q@ is
\begin{equation*}
\DD = \left[ \begin{array}{ccc}
    1 & 0 & 0\\
    0 & 0 & 0\\
    0 & 0 & 0\\
    0 & 0 & 0\\
    0 & 1 & 0\\
    0 & 0 & 0\\
    0 & 0 & 0\\
    0 & 0 & 0\\
    0 & 0 & 1
 \end{array} \right]
\end{equation*}

\subsection{$\QQ$ has one variance and one covariance}

\begin{equation*}
\QQ = \left[ \begin{array}{ccc}
    \alpha & \beta & \beta \\
    \beta & \alpha & \beta \\
    \beta & \beta & \alpha \end{array} \right]
\end{equation*}
The fixed vector is still the same, all zero.  \verb@par$Q@ is
\begin{equation*}
\bbeta =
 \left[ \begin{array}{c}
    "alpha" \\
    "beta"
\end{array} \right]
\end{equation*}
and \verb@free$Q@ is
\begin{equation*}
\DD = \left[ \begin{array}{cc}
    1 & 0\\
    0 & 1\\
    0 & 1\\
    0 & 1\\
    1 & 0\\
    0 & 1\\
    0 & 1\\
    0 & 1\\
    1 & 0
 \end{array} \right]
\end{equation*}

\subsection{$\QQ$ is unconstrained}

Since $\QQ$ is a variance-covariance matrix, it must be symmetric across the diagonal.
\begin{equation*}
 \QQ =
 \left[ \begin{array}{ccc}
    \alpha_1 & \beta_1 & \beta_2 \\
    \beta_1 & \alpha_2 & \beta_3 \\
    \beta_2 & \beta_3 & \alpha_3
    \end{array} \right]
\end{equation*}
There are no fixed values in $\QQ$ so $\ff$ is still all zero.  \verb@par$Q@ is
\begin{equation*}
\bbeta =
 \left[ \begin{array}{c}
    "alpha1" \\
    "beta1" \\
    "beta2" \\
    "alpha2" \\
    "beta3" \\
    "alpha3"
\end{array} \right]
\end{equation*}
and \verb@free$Q@ is
\begin{equation*}
\DD = \left[ \begin{array}{cccccc}
    1 & 0 & 0 & 0 & 0 & 0\\
    0 & 1 & 0 & 0 & 0 & 0\\
    0 & 0 & 1 & 0 & 0 & 0\\
    0 & 1 & 0 & 0 & 0 & 0\\
    0 & 0 & 0 & 1 & 0 & 0\\
    0 & 0 & 0 & 0 & 1 & 0\\
    0 & 0 & 1 & 0 & 0 & 0\\
    0 & 0 & 0 & 0 & 1 & 0\\
    0 & 0 & 0 & 0 & 0 & 1
 \end{array} \right]
\end{equation*}

\subsection{$\QQ$ is fixed}

For example,
\begin{equation*}
\QQ = \left[ \begin{array}{ccc}
    0.1 & 0 & 0 \\
    0 & 0.1 & 0 \\
    0 & 0 & 0.1 \end{array} \right]
\end{equation*}
The \verb@fixed$Q@ matrix is
\begin{equation*}
     \left[ \begin{array}{c}
    0.1 \\
    0 \\
    0 \\
    0 \\
    0.1 \\
    0 \\
    0 \\
    0 \\
    0.1
 \end{array} \right]
\end{equation*}
There are no estimated parameters so the free matrix is $9 \times 0$ and the par matrix is $0 \times 1$.

\section{Limits on the model forms that can be fit}

The main limitation is that one must specify a model that has only one solution.  The core functions will allow you to attempt to fit an improper model (one with multiple solutions).  If you do this accidentally, it may or may not be obvious that you have a problem.  The estimation functions may chug along happily and return some solution.  Careful thought about your model structure and the structure of the estimated parameter matrices will help you determine if your model is under-constrained and unsolvable.


\section{Algorithmic Background}
\label{section:background}
\par
{\bf SPOOLES} is an attempt to provide the capability for solving
sparse systems of linear equations for a diverse set of applications
on a diverse set of parallel computers.  We have included innovative
approaches for the ordering of sparse matrices.  We have also taken
an object oriented approach to providing the sparse matrix technology
which is different from the more traditional subroutine library
approach.  The algorithms for the numerical factorization and
solve steps are based on established algorithms.
\par
The purpose of this chapter is to give a quick overview of the
algorithms used in {\bf SPOOLES}.  We will leave the complete
description of the algorithms to the references.
\par
\subsection{Ordering a sparse matrix}
\label{subsection:intro:ordering}
\par
The past few years have seen a resurgence of interest and
accompanying improvement in algorithms and software to order sparse
matrices.
The minimum degree algorithm, specifically the multiple external
minimum degree algorithm \cite{liu85-mmd},
was the preferred algorithm of choice for
the better part of a decade.
Alternative minimum priority codes have recently pushed multiple
minimum degree aside,
including approximate minimum degree \cite{ame96-amd} and
approximate deficiency \cite{ng96-mindefIdaho},
\cite{rot96-mindefIdaho}.
They offer improved quality or improved run time, and on occasion,
both.
\par
Nested dissection for regular grids \cite{geo73-nested} is within a
factor of optimal with respect to factor entries and operation counts.
One of the earliest attempts, automatic nested dissection
\cite{geo81-book} used a simple profile algorithm to find separators.
It rarely performed as well as minimum degree.
Better heuristics to find separators were brought in from the
electrical device simulation area \cite{lei89-fidmat} and while
these algorithms produced better orderings, the run times kept
them from practical application.
Nested dissection came on its own with two developments.
The first was the application of spectral analysis of graphs to
find separators \cite{pot90-partition}.
The eigenvector associated with the smallest nonzero eigenvalue of
the Laplacian of a graph generates a spectrum of separators.
While the ordering times for spectral nested dissection were still
on the order of ten or more times the cost of a minimum degree ordering,
the ordering quality sometimes made the cost worthwhile.
\par
The key that made nested dissection a competitive and practical
alternative to minimum degree was the introduction of multilevel
ideas ---
to find a separator on a graph, first find a separator on a coarse
graph and project back to the original.
Early implementations include \cite{bar93-partition}
and \cite{bui93-partition}.
Multilevel algorithms are very popular in current software
including
{\bf CHACO}
\cite{hen93-chaco},
\cite{hen93-partition},
{\bf METIS}
\cite{kar95-multilevel},
\cite{kar95-metis},
{\bf BEND}
\cite{hr96-msnd},
{\bf WGGP}
\cite{gup96-WGPP}
and
{\bf PCO}
\cite{rag95-PCO}.
\par
{\bf SPOOLES} also includes a hybrid ordering approach called
multi-section
\cite{ash95-DDSEP},
\cite{ash96-maxflow},
\cite{ash96-multisection} and
\cite{ro95-hybrid}.
For some types of graphs, nested dissection does much better than
minimum degree, for others much worse.
Multisection is an ordering that uses both nested dissection and
minimum degree to create an ordering that is almost always as good
or better than the better of nested dissection or minimum degree
and rarely much worse.
\par
\subsection{Background on permutations and trees}
\label{subsection:order:background}
\par
Two important structures that are used in the solution of sparse
systems of equations are permutations and trees.  Because of the
object oriented nature of the {\bf SPOOLES} library the user
needs to know some information about these structures.
\par
For an example, let us examine the matrix R2D100, a matrix generated by
first randomly triangulating the unit square with 100 grid points.
The resulting matrix has 100 rows and columns.
We ordered the matrix using a generalized nested dissection
algorithm from the {\bf SPOOLES} library, and present the
vertex elimination tree for this ordering in
Figure~\ref{fig:R2D100-tree-vtx}.  The vertex elimination tree is
a representation of the order that the vertices in the graph
will be eliminated.
This order corresponds to the order that the rows
and columns will be factored for a square $A$.
The dependencies of the order form a tree structure.
The leaves of the tree (our trees hang
upside down with the leaves at the bottom and the root at the top)
represent vertices which can be eliminate first.  The parents
of those leaf nodes can be eliminated next, and so on, until finally
the vertices represented by the root of the tree will be
eliminated last.
\par
\begin{figure}[htbp]
\caption{Elimination tree for R2D100, 100 rows and columns}
\label{fig:R2D100-tree-vtx}
\begin{center}
\mbox{
\psfig{file=R2D100vtx.eps,width=5.0in,height=5.00in}
}
\end{center}
\end{figure}
\par
The elimination tree illustrates the dependence of the vertices.
The basic  rule is that a vertex {\it depends} only on its descendents
and will {\it affect} only its ancestors.
It should be clear that the tree allows us to identify independent,
parallel computation.
For example, the computation of the factor entries in the
subtree rooted at vertex 47 is completely independent of the
subtree rooted at vertex 89, so we could identify one process to
compute the left subtree and another to compute the right subtree.
\par
While the vertex elimination tree is useful to communicate the data
dependencies, it is not a good granularity on which to
base a factorization or solve, in serial or in parallel.
It is important to group vertices together in some meaningful way
to create larger data structures that will be more efficient with
respect to storage and computation.
The first step in this direction is to group together vertices
that form a chain with no branches in the tree.
Using this grouping we generate the {\it fundamental supernode tree}
given in the bottom of Figure~\ref{fig:R2D100-tree-front}.
\begin{figure}[htbp]
\caption{Top: vertex elimination tree with the vertices mapped to
the fundamental supernode that contains them.
Bottom: fundamental supernode tree.}
\label{fig:R2D100-tree-front}
\begin{center}
\mbox{
\psfig{file=R2D100vtxmap.eps,width=5.0in,height=5.00in}
}
\par
\mbox{
\psfig{file=R2D100front.eps,width=5.0in,height=2.50in}
}
\end{center}
\end{figure}
\par
A factorization based on the fundamental supernode tree requires
no more operations than one based on the vertex elimination tree.
There are many small supernodes at the lower levels of the tree.
By {\it amalgamating} small but connected sets of supernodes together into larger
supernodes we can reduce the overhead of the processing all of the small
supernodes at the expense of adding
entries to the factors and operations to compute the factorization.
This amalgamation of supernodes generally leads to an overall increase in
efficiency.  We call the result of the {\it amalgamated} supernode tree.
\par
The tree in the bottom of Figure~\ref{fig:R2D100-tree-comp} was
obtained by allowing up to twenty logically zero entries into the
block column for a supernode.
The top tree shows the fundamental supernodes mapped to their
amalgamated supernodes.
\par
\begin{figure}[htbp]
\caption{Top: fundamental supernode tree with the supernodes mapped to
the amalgamated supernode that contains them.
Bottom: amalgamated supernode tree.}
\label{fig:R2D100-tree-comp}
\begin{center}
\mbox{
\psfig{file=R2D100frontmap.eps,width=5.0in,height=2.50in}
}
\par
\mbox{
\psfig{file=R2D100comp.eps,width=3.0in,height=2.00in}
}
\end{center}
\end{figure}
\par
There is one final step to constructing the tree that governs the
factorization and solve.
Large matrices will generate large supernodes at the topmost levels
of the tree.
For example, a $k \times k \times k$ grid with a 27 point finite
difference operator, when ordered by nested dissection, has a root
supernode with $k^2$ rows and columns.
The data structure for a top level supernode can be very large,
too large to fit into memory.
In a parallel environment, we follow the convention that each node
in the tree is handled by one process.
Having a very large node at the top levels of the tree will
severely decrease the parallelism available to the computations.
\par
The solution to both problems, large data structures and limited
parallelism, is to split large supernodes into pieces.
We can specify a maximum size for the nodes in the tree, and split
the large supernode into pieces no larger than this maximum size.
This will keep the data structures to a manageable size and increase
the available parallelism.  We call the resulting tree the {\it front}
tree because it represents the final computational unit for the
factorization, the frontal matrix.
\par
The amalgamated supernode tree has been transformed so that except for
the leaf nodes, which are not changed, no node in the tree has more
than four vertices.
The new tree is given on the left
of Figure~\ref{fig:R2D100-tree-split},
while the right tree shows maps the nodes back to the amalgamated
supernode tree.
Splitting large nodes into smaller nodes will not increase the
factor storage or operation counts.
\par
\begin{figure}[htbp]
\caption{Left: tree after the large supernodes have been split.
Right: tree with nodes mapped back to their amalgamated supernode.}
\label{fig:R2D100-tree-split}
\begin{center}
\mbox{
\psfig{file=R2D100split.eps,width=3.00in,height=3.000in}
}
\quad
\mbox{
\psfig{file=R2D100splitmap.eps,width=3.00in,height=3.000in}
}
\end{center}
\end{figure}
\par
This front tree is now the defining
structure for the numerical factorization and solve steps.  The structure
of the front tree defines the order of the computations that will be
carried out in the factorization and the solve.  The methods for
almagamating and splitting to produce the front tree is found in
Section~\ref{chapter:manipulating:ETree}.
\par
\subsection{Matrix factorization and solves}
\label{subsection:intro:solve}
\par
One of the most important design consideration for our numeric
software is to support pivoting for numerical stability.
Much of the time pivoting for stability is not needed ---
when matrices are diagonally dominant or well conditioned positive definite ---
but there are
cases where pivoting is crucial.
\par
For symmetric matrices we use the fast Bunch-Parlett algorithm
to choose $1 \times 1$ or $2 \times 2$ pivots
\cite{ash95-AGL}.
For non-symmetric matrices we use its analogue.
It has recently come to our attention that this
pivoting strategy has been known as {\it rook pivoting}
\cite{fo96-rook}, \cite{ne92-rook}.
We compute the factorization
$P L D U Q$ or $P U^T D U P^T$
where $L$ is unit lower triangular,
$U$ is unit upper triangular,
and $P$ and $Q$ are permutation matrices.
When pivoting is enabled, the magnitude of entries in $L$ and
$U$ are bound by some user supplied tolerance.
\par
For the {\bf SPOOLES} library we chose to implement the fan-in
algorithm for the numerical factorization
\cite{ash90-fan-in}.  When it is time
to begin the computations for a given front, the processor owning
the rows and columns for that front receive the modification to
that front from previously computed fronts which are owned by other
processors.  The incoming modification is computed by the processor
that owns the previously computed front.


\documentclass[twoside]{MATH77}
\usepackage{multicol}
\usepackage[fleqn,reqno,centertags]{amsmath}
\usepackage{bm}
\begin{document}
\hyphenation{DJACG}
\begmath 8.4 Computing Numerical Derivatives, Gradients and Jacobians

%\silentfootnote{$^\copyright$1997 Calif. Inst. of Technology,
%\thisyear \ Math \`a la Carte, Inc.}
% Original author is Doug Salane.
% Modifications by Richard Hanson, 21-06/2002.
\subsection{Purpose}

This subroutine computes approximate gradient vectors and Jacobian matrices of
vector functions $\mathbf{f}(\mathbf{y})$ in several variables.  This routine
is used to compute approximate derivatives for problems where only function
information is available.  To approximate a scalar derivative function,
consider it an equivalent $1 \times 1$ Jacobian matrix.  Either one-sided or
central differences can be used.

\subsection{Usage}

\subsubsection{Program Prototype, Double Precision}
\begin{description}
\item[INTEGER]  \ {\bf MODE, M, N, LDFJAC, IOPT(k),
 LWK, IWK({\bf LIWK}$\geq$ 21), LIWK}\\
See the description of IOPT for the $k$ required.

\item[DOUBLE PRECISION]  {\bf Y}($\geq${\bf N}){\bf , F}($\geq${\bf M}){\bf ,\\
 FJAC}(LDFJAC,$\geq${\bf N}){\bf , YSCALE}(1 or $\geq${\bf N}),\\
  {\bf FAC}($\geq${\bf N}){\bf , WK}({\bf LWK} $\geq$ {\bf 3*M+18})
\end{description}\vspace{-10pt}

\begin{tabbing}
\hspace{.2in}\=Assign values to M, N, LDFJAC  and IOPT().\\
\>Set Y() to the value of the vector $\mathbf{y}$ at which\\
\>\ \ \ \ \=partial derivatives are needed, and set F()\\
\>\ \ \ \ \=to $\mathbf{f}(\mathbf{y})$. \\
\>Set MODE = 0.\\
10\>continue \\

C Approximate FJAC(,) as the M $\times $ N Jacobian\\
C matrix of first partial derivatives of $\mathbf{f}(\mathbf{y})$ with\\
C respect to $\mathbf{y}$, evaluated at Y():

\end{tabbing}\vspace{-15pt}
\begin{center}
\fbox{\begin{tabular}{l}
\quad {\bf CALL DJACG(MODE, M, N, Y, F,}\\
\quad \quad {\bf FJAC, LDFJAC, YSCALE, FAC,}\\
\quad \quad {\bf IOPT, WK, LWK, IWK, LIWK)}\\
\end{tabular}}
\end{center}
\begin{tabbing}
\hspace{.2in}\=if (MODE .gt. 0) then\\

\>\ \ \ \ \=Compute WK() as an M-vector of function\\
\>\>\ \ \ \ \=values $\mathbf{f}(\mathbf{y})$ evaluated at perturbed
$\mathbf{y}$ in Y().\\

\>\>go to 10\\
\>end if\\
\>Here the process is normally completed, if there \\
\>are no error conditions. Approximations to the\\
\> partials are in FJAC(,), with related scaling\\
\> and performance data in FAC() and IWK().\\
\end{tabbing}\vspace{-15pt}

\subsubsection{Argument Definitions}

\begin{description}
\item[MODE]  \ [inout] On initial entry set MODE = 0. The routine DJACG
 will normally return a number of times with MODE = J,
 the index of the derivative being computed.  A return value of MODE=0 means
 the approximate derivatives are computed.  A return value of MODE = K $<$ 0
 means that argument number $-$K has an error condition.

 For J $>$ 0 the calling code should compute WK() as a
function of Y() and call DJACG again, not altering MODE.

\item[M]  \ [in] Number of terms in F() and number of rows of data in
FJAC(,).  Must have M .gt. 0.

\item[N]  \ [in] Number of terms in Y() and number of columns of data in
FJAC(,).  Must have N .gt. 0.

\item[Y()] \ [inout] Initially must contain the vector $\mathbf{y}$ at which
  the partial will be computed. Contains perturbed $\mathbf{y}$ on each return
  with MODE = J $>$ 0. On final return with MODE = 0, contains the original
  $\mathbf{y}$.  Only component J is perturbed with each return, but more than
  one evaluation for a given J may occur.  After DJACG computes FAC() for the
  problem, one evaluation per variable is typically needed if central
  differences are not used..

\item[F()] \ [in] On entries with MODE $\geq $ 0, the user has function
  values in F(), {\em i.e.}, F($I$) $=f_I \mathbf{y}).$ The user
  should initialize F()=$\mathbf{f}(\mathbf{y)}$ before the routine is
  entered with MODE = 0.

\item[FJAC(,)]  \ [inout] , The numerical derivatives, {\em i.e.},
 FJAC$(i,j)=\partial f_i/\partial y_j$.  For default usage,
 this is designated as [out] except in columns
 receiving special treatment, as noted in IOPT().

\item[LDFJAC]  \ [in] Declared first dimension of the array FJAC(,).
 Require LDFJAC $\geq $ M or N=1.

\item[YSCALE()]  \ [in] An array of length 1 or N. The user can provide
             representative sizes for $\mathbf{y}$ values in the array
             YSCALE(). The user can also use YSCALE() to give
             appropriate directions for the differences.  If YSCALE(1) =0
             then Y() itself is used for the scaling.

\item[FAC()]      \ [inout] An array of length N. The value
FAC(J)  contains the factor for differencing variable J.
  If FAC(1)=0, the array FAC() is set to the square root  of
  machine  precision on the first call to DJACG.
  Unless the user wishes to initialize FAC(),
  this array should not be altered between subsequent  calls
  to  DJACG.

     The user  may  provide  FAC()  values  if  desired.
   If the user provides these values, FAC(J) should be
   set to a value between 0 and 1.  The routine DJACG
   ensures that FACMIN $\leq$ FAC(J) $\leq$ FACMAX.  The values
   for FACMIN  and FACMAX are saved in the storage
   locations WK(3M+1), WK(3M+2)
   when DJACG exits with MODE .gt. 0.

\item[IOPT()] \ [in] An integer array defining the methods used to
   compute the derivatives.  The default is to use one-sided differences to
   compute derivatives.  Entries in this array are interpreted as follows.

\begin{description}
\item[0] Use the current settings for all remaining variables.  The starting
  setting is to use one-sided differences.
\item[$k > 0$] Use the current settings for all variables from the last
specified up to and including variable $k$.
\item[$-1$] Set to use  one-sided differences.  (Not needed at the
beginning since this is the default state.)
\item[$-2$] Set to use central differences.

  This will typically yield more accuracy than the one-sided differences, but
  with the expense of an additional function evaluation per variable.  The
  increment used for central differencing is T=$\mathit{macheps}^{-1/6}$
  times the increment used in one-sided differencing.

  To change this factor for succeeding variables, assign a new value between
  calls with MODE = J in the storage location FAC(J).

  The default value T=$\mathit{macheps}^{-1/6}$ is based on the
  approximate relation T*FAC(J) = $\mathit{macheps}^{2/3}$.  This value
  is near an optimal choice, under certain conditions on higher derivatives,
  provided FAC(J) = $\mathit{macheps}^{1/2}$.  Sometimes larger or
  smaller values of FAC(J) will give more accuracy than the default.

\item[$-3$] Set to accumulate the result from whatever type of differences
  have been specified above into initial values provided in FJAC(1:M,J).
  This must be followed by a number $\geq 0$ as any number $< 0$ will turn
  this off.

  This partial consists of the prior computed values FJAC(1:M,J) plus
  additional values that are computed with divided differences. The value
  F() should equal the part of the function to be differenced.

\item[$-4$] Skip variables.  This must be followed by a value $\geq 0$
as any  number $< 0$ will turn this off.

No function evaluation is made when skipping a variable.  It is assumed that
this partial is computed in the user's program in some way other than with
divided differences.
\end{description}

An an illustration, suppose column 3 is not to be computed and column 4 is to
be accumulated.  The rest of the columns are computed with one-sided
differences and no additional options.  These requirements are designated by:
IOPT(1:7) = $2,\ -4,\ 3,\ -3,\ 4,\ -1,\ 0$.

\item[WK()] \ [inout] A work array whose dimension is at least LWK.
  Values of $\mathbf{f}(\mathbf{y)}$ are placed in WK() when MODE =
    J $>$ 0 is returned.  The additional locations of WK() are used for
  scratch storage.

\item[LWK] \ [in] The required length of the work array, LWK $\geq$ 3M+18.

\item[IWK()] \ [inout] An integer array whose dimension is at least LIWK.  The
  first 10 positions of IWK() contain diagnostic information, which can
  normally be ignored.  The remaining locations are used for scratch storage.

  IWK(1) gives the number of times the function, {\em i.e.}\
  $\mathbf{f}(\mathbf{y})$, was computed.

  IWK(2) gives the number of columns in which three attempts were made
  to increase a percentage factor for differencing ({\em i.e.}\ a component in the
  FAC() array) but the computed $\Delta_J$ remained too small relative to
  Y(J) or YSCALE(J).  In such cases the percentage factor is set
  to the square root of the unit roundoff of the machine.

  IWK(3) gives the number of columns in which the computed $\Delta_J$ was
  zero to machine precision because Y(J) or YSCALE(J) was zero.
  In such cases $\Delta_J$  is set to the square root of the unit roundoff.

  IWK(4) gives the number of Jacobian columns which had to be recomputed
  because the largest difference formed in the column was close to zero
  relative to $\mathit{scale}$, where
\begin{equation*}
  \mathit{scale} = \max( |f_i (\mathbf{y})|,|f_i(\mathbf{y}+\bm{\Delta)}|)
\end{equation*}
and $i$ denotes the row index of the largest difference in the column
currently being processed.  IWK(10) gives the last column where this
occurred.

IWK(5) gives the number of columns whose largest difference is close to
zero relative to $\mathit{scale}$ after the column has been recomputed.

IWK(6) gives the number of times scale information was not available for
use in the roundoff and truncation error tests.  this occurs when
\begin{equation*}
  \min (|f_i(\mathbf{y})|,|f_i (\mathbf{y}+\bm{\Delta)}|) = 0.
\end{equation*}
where $i$ is the index of the largest difference for the column currently
being processed.

IWK(7) gives the number of times the increment for differencing $\Delta_J$
was computed and had to be increased because (Y(J)+ $\Delta_J) -$ Y(J) was too
small relative to Y(J) or YSCALE(J).

IWK(8) gives the number of times a component of the FAC() array
was reduced because changes in function values were large and excess
truncation error was suspected. IWK(9) gives the last column in which
this occurred.

IWK(9) gives the index of the last column where the corresponding
component of the FAC() array had to be reduced because excessive
truncation error was suspected.

IWK(10) gives the index of the last column where the difference was
small and the column had to be recomputed with an adjusted increment, as in
IWK(4).  The largest derivative in this column may be inaccurate due to
excessive roundoff error.

\item[LIWK] \ [in] The required length of the array IWK(), LIWK $\geq $
    21.

\end{description}

\subsubsection{Modifications for Single Precision}

For single precision usage change the DOUBLE PRECISION statements to REAL and
change the name DJACG to SJACG. It is recommended that one use the double
precision rather than the single precision version of this package for better
reliability and accuracy.

\subsection{Example}
\subsubsection{A Gradient Computation}

The function is $f(y_1,y_2) = a \exp(b y_1)+c y_1 {y_2}^2$.  Its gradient
vector, or $1 \times 2$ Jacobian matrix, is
  \begin{equation*}
  [\partial f/\partial y_1,\partial f/\partial y_2]=
                         [a b \exp(b y_1)+c {y_2}^2, 2c y_1 y_2]
  \end{equation*}
  This formula is used for comparison to the computed results.  Values of the
  parameters and variables in the program are:

\begin{enumerate}
\item[] $a=2.5$, $b=3.4$, $c=4.5$
\item[] $y_1=2.1$, $y_2=3.2$
\end{enumerate}

This driver illustrates how to:
\begin{enumerate}
\item Compute approximate derivatives using one-sided divided differences
  (default)
\item Use one-sided differences on the first component and analytically
  compute the second component
\item Accumulate a known term of the first component with a differenced term
  that is not known a priori
\item Use central differences for both partials, getting more accuracy with
  additional function evaluations
\end{enumerate}

[The code and output listing are shown below.]

\subsection{Functional Description}

Let $\mathbf{y}$ denote the vector given initially in Y().  Let $\epsilon $
denote the machine precision, $\mathit{macheps}$. This is provided by the
functions D1MACH(4) and R1MACH(4) in single precision. (See
Chapter~19.1).

Let $\mathbf{e}_j$ denote the $n$-vector that is all zeros except for the
$j^{th}$ component which is one.

For each $i$ and $j$ compute%
\begin{equation*}
\hspace{-12pt}\text{FJAC(i,j)}=
\frac{f_i(\mathbf{y}+h_j \mathbf{e}_j)-f_i(\mathbf{y)}}{h_j}
\end{equation*}
The error in this difference approximation to the derivative $%
\partial f_i/\partial y_j$ is bounded by the magnitude of%
\begin{equation*}
h_jM_2/2+\delta /h_j
\end{equation*}
where $M_2$ denotes the magnitude of $||\partial ^2 f/\partial ^2y_j||_2$
evaluated at some point on the line segment from $\mathbf{y}$ to $%
\mathbf{y}+h_j \mathbf{e}_j$, and $\delta $ is a bound on the error in computing
$||\mathbf{f}(\mathbf{y})||$.

A key feature of DJACG is its heuristic for efficiently estimating values of
$\Delta_j = h_j=\mathit{fac}_j\times \mathit{scale}_j$ to maintain precision.
The algorithm for choosing $\mathit{fac}_j$ is found in Salane,
\cite{Salane:NUMD:1986}.  August, 1986.  A user should save values of
$\mathit{fac}_j$ between computations of partials, particularly when values of
{$\mathbf{y}$} do not change much and several evaluations of the partials are
anticipated.

The routine DJACG is re-entrant and thread-safe.  This is done by
avoiding the use of elementary functions, except SQRT(). All required
scalars are saved in the working arrays WK() and IWK() during
reverse communication.

An evaluation of the function $\mathbf{f}(\mathbf{y})$ can use DJACG as
part of that computation.  This feature will be useful when approximating
higher order derivatives of a smooth function, or using threaded algorithms to
concurrently compute the Jacobian matrix columns.  To use the re-entrant or
threaded functionality, separate storage copies of the arguments are usually
required.

\bibliography{math77}
\bibliographystyle{math77}

\subsection{Error Procedures}

Require MODE = 0 or $> 0$ on any entry to DJACG. A returned value
of MODE = 0 is normal, meaning the derivatives are approximated.  Values
of MODE = K $< 0$ mean that argument number $-$K has an error
condition.  Additional diagnostic information about numerical cancellation or
excessive truncation error is found in IWK(2:10).

\subsection{Supporting Information}

The source language is ANSI Fortran~77.

\begin{tabular}{@{\bf}l@{\hspace{5pt}}l}
\bf Entry & \hspace{.35in} {\bf Required Files}\vspace{2pt} \\
DJACG & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH}\\
SJACG & \parbox[t]{2.7in}{\hyphenpenalty10000 \raggedright
AMACH}\\
\end{tabular}

Designed and programmed by D. A. Salane, Sandia Labs. (1986).
  Modified by  R. J. Hanson, Rice University, (June, 2002) with advice from
  F. T. Krogh.

\begcode

\medskip\
\lstset{language=[77]Fortran,showstringspaces=false}
\lstset{xleftmargin=.8in}

\centerline{\bf \large DRDJACG1}\vspace{5pt}
\lstinputlisting{\codeloc{djacg1}}

\vspace{20pt}\centerline{\bf \large ODDJACG1}\vspace{10pt}
\lstset{language={}}
\lstinputlisting{\outputloc{djacg1}}

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx} % Allows including images
\usepackage{subcaption}
\usepackage{amsmath}

\title{Weekly Report}
\author{Junior Team }
\date{July 2020}

\begin{document}

\maketitle

\section{Assumptions and Variable Set-Up}
In order to analyze the square data set, we had to make some assumptions in order to account for some differences between the square and ellipse data sets. When we initially used the square data, we were implementing the Wang-Mason model, which we found that mass is arbitrary, since it cancels out. We figured that this is not the case for IRB Bound and assume that the square and ellipse are made of the same material to use this conversion:

\begin{equation}
    m_{square} = m_{ellipse} * \frac{A_{square}}{A_{ellipse}}
\end{equation}

\noindent Additionally, whereas the ellipse data that we received came with the Jacobian and pre- and post-impact states, we needed to isolate these ourselves. To compute the $n$ and $d$ vectors for the Jacobian, we first identified the impact to extrapolate. From then on, we used the pre-impact data for our calculations. We then found the coordinates of all four edges of the square. We took the coordinate with the lowest $y$ value and its corresponding $x$ to be the contact point of the square. After subtracting this $(x, y)$ pairing from the COM coordinates to get the moment arms--measured from the contact point-- we put these into the third columns of the vectors.

\begin{equation}
n =
\begin{bmatrix}
 0 \\
 1 \\
 x_{COM}-x_{contact}
\end{bmatrix}
\end{equation}

\begin{equation}
d =
\begin{bmatrix}
 1 \\
 0 \\
 y_{COM}-y_{contact}
\end{bmatrix}
\end{equation}

\section{Constructing Square Data Set}
This week we created an impact data set from the square trajectory files. To identify when an impact occurs, the code looks for a sign change in the vertical velocity (negative to positive) and the y coordinate of the COM must be lower than the previous and following y com position. To avoid "bad data" (double impacts, skipped frames etc...) we used our visualizer and manually recorded only the impacts that were clear (just considering the first two collisions from each drop). From 500 csv files, (1000 total potential impacts) we ended up with around 375 clear impacts. \\

\noindent The data set could be expanded, but we would need much more robust code or spend some more man-hours going through the data set in detail. With our code, if the first impact is fishy and looks like a double hit we automatically can't take data from a later impact because of the inconsistencies of the automated impact data extraction (described above w/ the y velocity/position). For now, we thought we have plenty of data points. A clear bias with the data collection however is natural clumping of pre-impact angles. When the angles are around $0$ or $\pm \frac{\pi}{2}$ a double hit is far more likely to occur so we have have far fewer data points around these impacts which are quite common because the 1/250 second data collection rate isn't quite fast enough to capture these "double hits".

 \begin{figure}[h!]
        \centering
        \includegraphics[scale=0.11]{SquareDataBias.jpg}
        \caption{Bias in Data Collection (Pre Impact Angle)}
        \label{fig:dataBias}
\end{figure}

\section{Comparing Ellipse  and Square Data}
\subsection{IRB with Width}
For the square, it is less intuitive to explain the error in the IRB with some sort of moment due to a contact patch width since the impacts are almost exclusively occurring at the corners. That being said, you could still use the idea behind using width as a correction factor for inaccuracies in the data collection method.

\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.45\linewidth}
        \includegraphics[scale=0.125]{squareWidth.jpg}
        \caption{Square Data Set}
        \label{fig:squareWidth}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.45\linewidth}
       \includegraphics[scale=0.125]{ellipseWidth.jpg}
        \caption{Ellipse Data Set}
        \label{fig:ellipseWidth}
    \end{subfigure}
    \caption{Error from IRB model over range of max widths}
\end{figure}

\noindent Although adding the width correction factor does lower error, the overall magnitude of errors for the square data is still much larger then that from the ellipse data set. Even at a width of 2cm (largest in max widths tested) the average error from the square is around twice as large as the average error from the ellipse data set with no width (max width = 0). The curve is also sloped much more steeply, showing larger decreases in error and ending at basically 0 average error for the ellipse set. Another interesting point is that when the max width is set to 2cm for the ellipse data set (unrealistically large) all trials have an optimal width below this cap. For the square data set however, tons of trials clump at the bounds of this unrealistic cap (\ref{fig:squareAngleWidth}) meaning a larger magnitude width would decrease error. It seems as though the classical IRB model is far worse at predicting the square impacts and width is not a natural correction factor.

\subsection{Pre Impact Angle vs. Width}
With the ellipse data set, we were seeing a sinusoidal relationship between the pre-impact angle of the ellipse and the optimal width (which can also be interpreted as error) from the IRB model (with width). This same trend doesn't seem to arise from the square data set.  This could be due to ideas from Fig \ref{fig:dataBias} (bias in the data set), ideas from section 3.1, or a combination of both.

\begin{figure}[h!]
    \centering
    \begin{subfigure}[b]{0.45\linewidth}
        \includegraphics[scale=0.125]{ellipseAngleWidth.jpg}
        \caption{Ellipse Data Set}
        \label{fig:ellipseAngleWidth}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.45\linewidth}
       \includegraphics[scale=0.125]{squareAngleWidth.jpg}
        \caption{Square Data Set}
        \label{fig:squareAngleWidth}
    \end{subfigure}
    \caption{Pre-impact Angle vs. Optimal Width for IRB Model (Capped at 2cm)}
\end{figure}

\section{More Angle Exploration}
Using the classical IRB model, we found some new trends between the observed change in angular velocity and the error (Fig \ref{fig:changeInOmegaEllipse}). The cases where we observe very high error are primarily when there are small changes in angular velocity. This also comes back to a point discussed last group meeting, where adding a width to reduce error is not due to a lack of moment or an angular velocity prediction that was too small in magnitude.
\begin{figure}[h!]
    \centering

     \begin{subfigure}[b]{0.45\linewidth}
            \centering
            \includegraphics[scale=0.12]{changeInOmegaEllipse.jpg}
            \caption{Ellipse Data Set}
            \label{fig:changeInOmegaEllipse}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.45\linewidth}
            \centering
            \includegraphics[scale=0.12]{changeInOmegaSquare.jpg}
            \caption{Square Data Set}
            \label{fig:changeInOmegaSquare}
    \end{subfigure}
    \caption{Absolute value of change in angular velocity compared to error from the}
\end{figure}

\noindent A similar trend arises from the square data (Fig \ref{fig:changeInOmegaSquare}), which matches an observation we made when trying to improve our data set. When we first ran the classical IRB model, we looked for outliers with extremely high error to re-watch on the visualizer and double check that we hadn't made any mistakes in labeling the impacts. Sometimes it turned out that the high error was due to a double impact we had mis-categorized and resulted in a removal of that data point, but other times, it was when the square would land on the corner, and just bounce straight up with an angular velocity of around zero.

\newpage
\section{More Square Data Exploration}
After selecting manually selecting our data from the Square Data set as outlined above, we went out to try and replicate some of the patterns we were seeing with the ellipse data. In the plots below, we can observe these patterns:

\begin{figure}[h!]
     \begin{subfigure}[b]{0.45\linewidth}
            \includegraphics[scale=0.15]{SquarePlot11.jpg}
            \caption{Net Moment vs Error Square}
    \end{subfigure}
    \quad
    \begin{subfigure}[b]{0.45\linewidth}
            \includegraphics[scale=0.15]{SquarePlot22.jpg}
            \caption{IRB moment vs Width Torque}
    \end{subfigure}
\end{figure}

\end{document}

Weekly Reports/Weekly Report 719/main.tex


\documentclass[main.tex]{subfiles}
\begin{document}

\marginpar{Monday\\ 2020-3-16, \\ compiled \\ \today}

\subsection{The Klein-Gordon equation in the presence of an external electromagnetic field}

A complex scalar solution to the Klein-Gordon equation can represent a charged relativistic spin-0 particle.
Since the particle is charged, it is interesting to study its interaction with the electromagnetic field.

We will discuss only the interaction of the particle with an externally determined field, that is, we will not discuss how the particle influences the field around it.

In order to describe the electric and magnetic fields in a covariant way we use the four-vector \(A_{\mu } = (A_0 , \vec{A})\), such that \(\vec{E} = - \vec{\nabla} A_0 - \partial_{0} \vec{A}\) and \(\vec{B} = \vec{\nabla} \times \vec{A}\), or, in covariant terms,
%
\begin{align}
F^{ \mu \nu } = 2\partial^{[\mu } A^{\nu ]}
\,,
\end{align}
%
where the antisymmetric field-strength tensor \(F^{\mu \nu }\) encodes both the electric and magnetic fields.

\begin{definition}
The \textbf{minimal coupling} to an external electromagnetic field is obtained by substituting in the wave equation the partial derivative \(\partial_{\mu }\) with the \emph{covariant derivative}
%
\begin{align}
\mathrm{D}_{\mu } \overset{\text{def}}{=} \partial_{\mu } + i q A_{\mu }
\,,
\end{align}
%
where \(q\) is the electric charge of the particle.
\end{definition}

Inserting this, the coupled Klein-Gordon equation reads
%
\begin{align}
\qty[\DD^{\mu } \DD_{\mu } + M^2 ] \varphi (x) = 0
\,.
\end{align}

Recall that the momentum is defined as \(p_{\mu } = i \partial_{\mu }\), so this substitution is equivalent to changing the momentum to \(i (\partial_{\mu } +iqA_{\mu }) =  p_{\mu } - q A_{\mu }\).

This is the same minimal coupling ansatz which is used in nonrelativistic quantum mechanics: there, the minimally-coupled Schrödinger equation reads
%
\begin{align}
E \psi = \qty[\frac{\qty(\vec{p} - q \vec{A})^2}{2M}  + q A_0 ] \psi
\,,
\end{align}
%
in which we can see the two contributions: the three-momentum \(\vec{p}\) is exchanged for \(\vec{p} - q \vec{A}\), while the energy \(E\) is exchanged for \(E - q A_0 \) (and the term is brought on the other side of the equation for convenience).

Let us make the terms in the minimally coupled Klein-Gordon equation explicit:
%
\begin{subequations}
\begin{align}
\qty[\qty(\partial^{\mu } +iqA^{\mu }) \qty(\partial_{\mu } +i q A_{\mu }) + M^2] \varphi &= 0  \\
\qty[\square + iq A^{\mu } \partial_{\mu } + iq \partial_{\mu } A^{\mu } - q^2A^2 + M^2] \varphi &=0  \\
\qty[\square + 2iq A^{\mu } \partial_{\mu } + iq \qty(\partial_{\mu } A^{\mu }) - q^2A^2 + M^2] \varphi &=0
\,,
\end{align}
\end{subequations}
%

Do note that anything on the right acts on anything on the left: the application of the derivatives looks like \(
\DD^{\mu } \qty(\DD_{\mu } \qty(\varphi ))\). So, the term
\(\partial_{\mu } A^{\mu }\) should be read as \(\partial_{\mu } \qty(A^{\mu } \varphi )\), which we expanded into \(\qty(\partial_{\mu } A^{\mu }) + A^{\mu } \partial_{\mu }\) --- all acting on \(\varphi \), but the term \(\qty(\partial_{\mu }A^{\mu })\) is just multiplied by \(\varphi \), it does not perform a differentiation.

\subsubsection{The Coulomb potential}

The 4-potential is not physical: if we change it by \(A_{\mu } \rightarrow A^{\prime }_{\mu } = A_{\mu } + \partial_{\mu } \Lambda \) for some scalar function \(\Lambda \) it does not change the resulting measurable electric and magnetic fields.
Therefore, while still retaining full generality in our description of physical systems we can impose certain conditions, such as \(\partial_{\mu } A^{\mu } = 0\).
This condition, known as the \emph{Coulomb gauge}, does not actually fix all of the gauge freedom --- that is, even by imposing this we still do not have a one-to-one correspondence between the physical fields and the 4-potentials: after imposing it, we can still perform gauge transformations where the function \(\Lambda \) is harmonic, that is, it satisfies \(\square \Lambda = 0\).

This condition is convenient since it allows us to get rid of a term in the KG equation, so we impose it.

\subsubsection{Antimatter: an interpretation for the negative-energy solution}

Let us consider a simple case: the monochromatic solution to the KG equation, \(\varphi_{\pm} (x) = e^{\mp i k \cdot x}\), coupled to the EM field.
Let us suppose that the 4-momentum \(k^{\mu} = (\omega_{k}, \vec{k})\) corresponding to the two solutions is fixed, that is, the positive energy solution has \(E \varphi^{+} = \omega_{k}\) while the negative energy solution has \(E \varphi^{-} = - \omega_{k}\), with the same \(\omega_{k}\) and the same \(\vec{k}\).

Splitting the energy and momentum terms, the equation reads:
%
\begin{align}
\qty[\qty(E - q A_0 )^2 - \qty(\vec{p} - q \vec{A})^2 + M^2] \varphi^{\pm}(x) = 0
\,,
\end{align}
%
where \(E = i \partial_{t} \) while \(\vec{p} = - i \vec{\nabla}\).

Then, we can write the two equations like
%
\begin{subequations}
\begin{align}
\qty[\qty(\omega_{k} - q A_0 )^2 - \qty(\vec{k} - q \vec{A})^2 + M^2] \varphi^{+}(x) &= 0 \\
\qty[\qty(\omega_{k} + q A_0 )^2 - \qty(\vec{k} + q \vec{A})^2 + M^2] \varphi^{-}(x) &= 0
\,,
\end{align}
\end{subequations}
%
where we used the fact that \((-\omega_{k} - q A_0 )^2 = (\omega_{k} + q A_0 )^2\), and similarly for the other term.

So, we can see that the two equations can be transformed into each other also by swapping the charge, \(q \rightarrow -q\).

The interpretation for this is that the KG equation describes two degrees of freedom, which we call a \emph{particle} (with \(E>0\)) and an \emph{antiparticle} (with \(E<0\)).

The particle and antiparticle have the same mass, but their charge is opposite.
In a certain sense, the existence of antimatter is a prediction of relativistic quantum mechanics.

\subsection{The nonrelativistic limit}

As a consistency check for our relativistic equation, we wish to verify that the nonrelativistic limit of the KG equation is the Schrödinger equation.

In the nonrelativistic limit the mass of the particle \(M\) is much larger than its momentum \(p\), so we can expand:
%
\begin{align}
E = \sqrt{\abs{p}^2 + M^2}
= M \sqrt{1 + \frac{\abs{p}^2}{M^2}}
= M + \underbrace{\frac{\abs{p}^2}{2M}}_{E_k} + \order{\frac{\abs{p}^{4}}{M^{3}}}
\,.
\end{align}

In quantum mechanics the time evolution of a particle depends on its energy, so if \(M \gg E_k\) the evolution due to the mass will be much faster than that due to the kinetic energy: so, we factor it out by
%
\begin{align}
\varphi (t, \vec{x}) = e^{-iMt} \varphi^{\prime } (t, \vec{x})
\,,
\end{align}
%
where the evolution of \(\varphi^{\prime }\) will look like \(e^{-iE_k t} \varphi'\).

Now, let us expand the derivative terms in the KG equation (in the Coulomb gauge, so we do not worry about \(\partial_{\mu }A^{\mu }\)):
%
\begin{subequations}
\begin{align}
\DD^{\mu } \DD_{\mu } &= \qty(\partial^{0} + i q A^{0})
\qty(\partial_{0} + i q A_{0})
+ \qty(\partial^{i} + i q A^{i})
\qty(\partial_{i} + i q A_{i}) \\
&= \qty(\partial_{0} + i q A_{0})^2
- \qty(\partial_{i} + i q A_{i})^2  \\
&= \qty(\partial_{0} + i q A_{0})^2
- \qty(\vec{\nabla} - i q \vec{A})^2
\,,
\end{align}
\end{subequations}
%
where we used the fact that \(\vec{A} = A^{i}\), while \(\vec{\nabla} = \partial_{i} = - \partial^{i}\).

In the full KG equation applied to the decomposed field \(\varphi = e^{-iMt} \varphi^{\prime }\) we move the momentum terms to the right and keep the mass and energy on the left:
%
\begin{subequations}
\begin{align}
\qty[\qty(\partial_{0} + i q A_0 )^2 + M^2] e^{-iMt} \varphi^{\prime }
&=
\qty(\nabla- iq \vec{A})^2 e^{-iMt} \varphi^{\prime }
\marginnote{The term \(e^{-iMt}\) is constant with respect to the spatial coordinates}
\\
\qty[\partial_0^2 + 2iq A_0 \partial_0 - q^2 A_0^2 + M^2]
e^{-iMt} \varphi^{\prime }
&=
e^{-iMt} \qty(\nabla- iq \vec{A})^2 \varphi^{\prime }
\,.
\end{align}
\end{subequations}

The time-derivative on the right acts both on the mass term and on the wavefunction \(\varphi^{\prime }\). So, we get\footnote{It is really easy when doing these computations to forget some terms. A way I've found helpful is to write down the full expression,
%
\begin{align}
\qty(\partial_0 + i q A_0 )
\qty(\partial_0 + i q A_0 )
\qty(e^{-iMt} \varphi')
\,,
\end{align}
%
give binary labels (000, 001\dots until 111) to each term and work through all \(2^3\) of them. Notice the expansion of the term
%
\begin{align}
\partial_0 \partial_0 \qty(e^{-iMt} \varphi')
= \partial_0 \qty(-iM e^{-iMt} \varphi' + e^{-iMt} \partial_0 \varphi')
= -iM e^{-iMt} \partial_0 \varphi'
- M^2 e^{-iMt} \varphi'
+ e^{-iMt} \partial_0^2 \varphi
- iM e^{iMt} \varphi'
\,.
\end{align}
}
%
\begin{subequations}
\begin{align}
\begin{split}
e^{-iMt} \qty(\nabla- iq \vec{A})^2 &\varphi^{\prime } = \\
=e^{-iMt}
\qty[\partial_0^2 - M^2 - 2iM \partial_0  + 2iq A_0 (-iM) + iq \qty(\partial_0 A_0 ) + 2iq A_0 \partial_0 - q^2 A_0^2 + M^2] & \varphi^{\prime }
\end{split}
\\
= \qty[\partial_0^2 - 2iM \partial_0  + 2q A_0 M + iq \qty(\partial_0 A_0 ) + 2iq A_0 \partial_0 - q^2 A_0^2 ]
\varphi^{\prime }
=
\qty(\nabla- iq \vec{A})^2  &\varphi^{\prime }
\,,
\end{align}
\end{subequations}
%
and now we must discuss which terms we can discard.

\todo[inline]{The coefficient before the term \(\propto \partial_0 A_0 \)is reported by the professor as \(2\), but I and several other people find only one of those terms.}

On the right hand side we have terms of the order of the mass and ones of the order of the energy: we wish to keep only the former, since as we assumed they dominate the latter. Specifically, terms without explicit dependence on the mass are of the order of the kinetic energy:\footnote{This is imprecise, we can do better: we distinguish the terms with time derivatives and those without.
Those with time derivatives are applied to \(\varphi'\), which by construction evolves with \(\omega = E_k\), therefore they are negligible.
The other terms are \(q^2 A_0^2\), which is the electric potential energy, and  \(2iq \partial_0 A_0 \), which is proportional to the electric field: we assume the electric field to be nonrelativistic, that is, of intensity comparable to the kinetic energy of the particle, and much smaller than its mass.
}
then, we remove and get precisely the minimally coupled Schrödinger equation:
%
\begin{subequations}
\begin{align}
\qty[- 2 iM \partial_0 + 2 q_0 A_0 M ] \varphi' &= \qty(\vec{\nabla} - iq \vec{A})^2 \varphi^{\prime }  \\
i \partial_0 \varphi' &= \qty[- \frac{ \qty(\vec{\nabla} - i q \vec{A})^2}{2M} + q_0 A_0 ] \varphi'
\,.
\end{align}
\end{subequations}
%

This is precisely the equation we wrote above: the nonrelativistic Schrödinger equation for a charged spin-0 particle in an electromagnetic field.

\subsection{Summary}

\begin{enumerate}
  \item The dispersion relation \(E^2 = p^2+m^2\) is a quadratic relation, the positive root is called \(\omega_{p} = \sqrt{p^2+m^2}\) and the energy can be \(E = \pm \omega_{p}\).
  \item A solution to the KG equation has two independent terms \(\varphi^{+}\) and \(\varphi^{-}\), which can be interpreted as a particle-antiparticle pair, where \(\varphi^{+}\) has charge \(q\) while \(\varphi^{-}\) has charge \(-q\).

  An antiparticle has the same quantum numbers, but the opposite charge.
  \item There is no way to define a conserved (positive definite) probability for the KG equation, but the nonrelativistic limit of the KG equation is consistent with nonrelativistic quantum mechanics.
\end{enumerate}

\begin{claim}
The continuity equation for the coupled KG equation is given by
%
\begin{align}
\partial_{\mu } j^{\mu }_{EM} = 0
\,,
\end{align}
%
where
%
\begin{align}
j^{\mu }_{EM} = \frac{1}{2} \qty(i \varphi^{*} \partial^{\mu } \varphi   - q A^{\mu } \varphi^{*} \varphi ) - \text{c. c.}
\,.
\end{align}
\end{claim}

\begin{proof}
Similarly to what was done before, we notice that
%
\begin{align}
\varphi^{*} \qty(\DD^{\mu } \DD_{\mu } + M^2) \varphi =
\varphi^{*}\qty[\square + 2iq A^{\mu } \partial_{\mu } + iq \qty(\partial_{\mu } A^{\mu }) - q^2A^2 + M^2] \varphi
=0
\,
\end{align}
%
can be added to the negative of its complex conjugate, which reads
%
\begin{align}
\varphi \qty[\square - 2 iq A^{\mu }\partial_{\mu } - i q \qty(\partial_{\mu } A^{\mu }) ] \varphi^{*} = 0
\,,
\end{align}
%
to yield
% %
% \begin{subequations}
% \begin{align}
% 0&= \varphi^{*} \qty(\DD^{\mu } \DD_{\mu }) \varphi - \text{c. c. } \marginnote{Simplified mass terms, which were symmetric in \(\varphi^{*} \leftrightarrow \varphi \)}
% \\
% 0&= \DD^{\mu } \qty(\varphi^{*} \DD_{\mu } \varphi) - \qty(\DD^{\mu } \varphi^{*}) \qty(\DD_{\mu } \varphi ) - \text{c. c. } \marginnote{Removed symmetric term in \(\varphi \leftrightarrow \varphi^{*}\)}\\
% 0&= \DD^{\mu } \qty(\varphi^{*} \DD_{\mu } \varphi) - \text{c. c. } \\
% 0&= \DD^{\mu } \qty( \varphi^{*} \DD_{\mu } \varphi - \text{c. c. }) \\
% 0&= \DD^{\mu } j_{\mu }
% \,,
% \end{align}
% \end{subequations}
% %
% so our conserved current is
% %
% \begin{subequations}
% \begin{align}
% j^{\mu } &= \varphi^{*} \DD^{\mu } \varphi - \text{c. c. } \\
% j^{\mu } &= \varphi^{*} \partial^{\mu } \varphi
% + iq A^{\mu } \varphi^{*} \varphi
% - \text{c. c. }  \\
% &= \varphi^{*} \partial^{\mu} \varphi + i q A^{\mu } \varphi^{*} \varphi - \varphi \partial^{\mu }\varphi^{*} + i q A^{\mu } \varphi^{*} \varphi \\
% &= \varphi^{*} \partial^{\mu} \varphi - \varphi \partial^{\mu }\varphi^{*} + 2i q A^{\mu } \varphi^{*} \varphi
% \,,
% \end{align}
% \end{subequations}
% %
% and conventionally we define \(j^{\mu }_{EM} = \frac{i}{2} j^{\mu }\), which is
% %
% \begin{align}
% j^{\mu }_{EM} = \frac{i}{2} \varphi^{*}\partial^{ \mu } \varphi
% -\frac{i}{2} \varphi\partial^{ \mu } \varphi^{*} + \frac{2}{2} i^2  q A^{\mu } \varphi^{*} \varphi
% \,.
% \end{align}
%
\begin{subequations}
\begin{align}
\begin{split}
0&=\varphi^{*} \square \varphi + 2iqA_{\mu } \varphi^{*} \partial^{\mu } \varphi + iq \qty(\partial_{\mu }A^{\mu } ) \varphi \varphi^{*} + \\
&-\varphi \square \varphi^{*} + 2iqA_{\mu } \varphi \partial^{\mu } \varphi^{*} + iq \qty(\partial_{\mu }A^{\mu } ) \varphi \varphi^{*}
\end{split}  \marginnote{The \(q^2A^2\) and \(M^2\) terms cancel since they are real}\\
&= \partial^{\mu } \qty(\varphi^{*} \partial_{\mu } \varphi - \varphi \partial_{\mu } \varphi^{*}) + 2iq \qty[A_{\mu } \qty(\varphi^{*} \partial^{\mu } \varphi  + \varphi \partial^{\mu } \varphi^{*} ) + \varphi \varphi^{*} \partial_{\mu } A^{\mu }]  \\
&= \partial^{\mu } \qty[ \varphi^{*} \partial_{\mu } \varphi - \varphi \partial_{\mu } \varphi^{*} + 2 iq A_{\mu } \varphi \varphi^{*}]
\,,
\end{align}
\end{subequations}
%
so the expression inside the brackets is the conserved current, up to a multiplicative factor of \(i/2\).
\end{proof}

\end{document}


\documentclass[11pt]{amsart}
\usepackage{amsmath,amsfonts,amsthm,amssymb, amsaddr}

\title{Solving Kepler Problem with Vector Calculus}

\author{Joe Bentley}

\date{\today}

\begin{document}

\maketitle

\newpage

\section{Conservation of Energy}

Here we will arrive at a result which shows conservation of energy from Newton's second law of motion, $\mathbf{F} = m \mathbf{a}$

First, we need to set up a differential equation describing the situation,

\begin{align}
  \label{eq:raw}
  m \frac{d \mathbf{v}}{d t} = - \frac{GMm}{r^3} \mathbf{r}.
\end{align}

We then take the scalar product of each side with $\mathbf{v}$,

\begin{align}
  \label{eq:dotted}
  m \mathbf{v} \cdot \frac{d \mathbf{v}}{d t} = - \frac{GMm}{r^3} \mathbf{r} \cdot \mathbf{v}.
\end{align}

In the next part we will consider the time derivative of $v^2$, we know that $v^2 = \mathbf{v} \cdot \mathbf{v}$, hence

\begin{align*}
  \frac{d}{dt}(v^2) = \frac{d}{dt}(\mathbf{v} \cdot \mathbf{v}) = \mathbf{v} \cdot \frac{d\mathbf{v}}{dt} + \frac{d\mathbf{v}}{dt} \cdot \mathbf{v} = 2 \mathbf{v} \cdot \frac{d\mathbf{v}}{dt}
\end{align*}

In the second step we applied the product rule.

We can see that this is almost like the left hand of our equation, just with a factor of 2, and missing an $m$. The left hand side of our equation is then, in fact, the time derivative of the kinetic energy.

\begin{align*}
  \frac{d}{dt}\left(\frac{1}{2}mv^2\right) = m\mathbf{v}\cdot\frac{d\mathbf{v}}{dt}
\end{align*}

This is the left hand side of our equation. Now we will concentrate on the right hand side.

Clearly, $r^2 = \mathbf{r} \cdot \mathbf{r}$, and thus,

\begin{align*}
  \frac{d}{dt}\left(r^2\right) = \frac{d}{dt}\left(\mathbf{r}\cdot\mathbf{r}\right) \\
  2r\frac{dr}{dt} = 2\mathbf{r}\cdot\frac{d\mathbf{r}}{dt} = 2\mathbf{r}\cdot\mathbf{v} \\
  \mathbf{r}\cdot\mathbf{v}=r\frac{dr}{dt}
\end{align*}

We can substitute this into eq.~\ref{eq:dotted} so the right hand side becomes,

\begin{align*}
  - \frac{GMm}{r^3} \left(r\frac{dr}{dt}\right) = - \frac{GMm}{r^2} \frac{dr}{dt} = \frac{d}{dt}\left[\frac{GMm}{r}\right]
\end{align*}

Now we have both the left hand side and right hand side of our equation,

\begin{align*}
  \frac{d}{dt}\left(\frac{1}{2}mv^2\right) = \frac{d}{dt}\left(\frac{GMm}{r}\right)
\end{align*}

By minusing the RHS,

\begin{align*}
  \frac{d}{dt}\left(\frac{1}{2}mv^2 - \frac{GMm}{r}\right) = 0
\end{align*}

Thus we see conservation of energy, the total energy in the system (the kinetic energy minus the gravitational potential energy) is invariant in time.

\section{Conservation of Angular Momentum}

We start by taking the vector product of eq.~\ref{eq:raw} with $\mathbf{r}$,

\begin{align}
  \label{eq:cross}
  \mathbf{r}\times\left(m\frac{d\mathbf{v}}{dt}\right) = \mathbf{r}\times\left(- \frac{GMm}{r^3}\right)\mathbf{r} = 0.
\end{align}

This is zero because $\mathbf{r}\times\mathbf{r}$ is zero. Also used here is $\mathbf{F} = m\mathbf{a}$ in the second argument to the vector product.

What is the left side in differential form? Well it kind of looks like the time derivative of the angular momentum, $\mathbf{L} = \mathbf{r}\times m\mathbf{v}$, so we will try that,

\begin{align*}
  \frac{d}{dt}\left(\mathbf{r}\times m\mathbf{v}\right) = \frac{d\mathbf{r}}{dt}\times m\mathbf{v} + \mathbf{r}\times m\frac{d\mathbf{v}}{dt} = \mathbf{v}\times m\mathbf{v} + \mathbf{0} = \mathbf{0}
\end{align*}

The $\mathbf{r}\times m\frac{d\mathbf{v}}{dt}$ is zero as we have shown in eq.~\ref{eq:cross}.

Therefore we see that since the time derivative of the angular momentum is zero, it is conserved, as it is unchanging in time,

\begin{align*}
  \frac{d}{dt}\left(\mathbf{L}\right) = \frac{d}{dt}\left(\mathbf{r}\times m\mathbf{v}\right) = 0.
\end{align*}

Since $\mathbf{r}$ is perpendicular to $\mathbf{L}$, and $\mathbf{L}$ is constant, the motion takes place in the plane perpendicular to $\mathbf{L}$, which also contains the origin of rotation.

\section{Laplace-Runge-Lenz Vector}

To find a new unknown conserved quantity we take the vector product of $\mathbf{F} = m\mathbf{a}$ with $\mathbf{L}$,

\begin{align*}
  m\frac{d\mathbf{v}}{dt}\times\mathbf{L} = -\frac{GMm}{r^3}\mathbf{r}\times\mathbf{L}
\end{align*}

and then dividing by $m$,

\begin{align}
  \label{crossedwithL}
  \frac{d\mathbf{v}}{dt}\times\mathbf{L} = -\frac{GM}{r^3}\mathbf{r}\times\mathbf{L}
\end{align}

The left hand side looks kind of like the time derivative of $\mathbf{v}\times\mathbf{L}$,

\begin{align*}
  \frac{d}{dt}\left(\mathbf{v}\times\mathbf{L}\right) = \frac{d\mathbf{v}}{dt}\times\mathbf{L} + \mathbf{v}\times\frac{d\mathbf{L}}{dt} = \frac{d\mathbf{v}}{dt}\times\mathbf{L}
\end{align*}

Since angular momentum $\mathbf{L}$ is conserved, we see know that $\frac{d\mathbf{L}}{dt}$ is zero. Therefore we now know that the left hand side is equal to $\frac{d}{dt}\left(\mathbf{v}\times\mathbf{L}\right)$.

Now for the right hand side, we plug back in the definition of $\mathbf{L}$,

\begin{align*}
  -\frac{GM}{r^3}\mathbf{r}\times\mathbf{L}=-\frac{GMm}{r^3}\mathbf{r}\times\left(\mathbf{r}\times\mathbf{v}\right)
\end{align*}

This is just the vector triple product,

\begin{align*}
  -\frac{GMm}{r^3}\left[\left(\mathbf{r}\cdot\mathbf{v}\right)\mathbf{r}-\left(\mathbf{r}\cdot\mathbf{r}\right)\mathbf{v}\right] \\
  = \frac{GMm}{r^3}\left[r^2 \mathbf{v}-\left(r\frac{dr}{dt}\right)\mathbf{r}\right] \\
  = \frac{GMm}{r}\mathbf{v} - \frac{GMm}{r^2}\frac{dr}{dt}\mathbf{r} \\
  = \frac{GMm}{r}\frac{d\mathbf{r}}{dt} + \frac{d}{dt}\left(\frac{GMm}{r}\right)\mathbf{r} \\
  = \frac{d}{dt}\left(\frac{GMm}{r}\mathbf{r}\right)
\end{align*}

The last line was by seeing that the second to last line is just the product rule, so we just inversed it into the $\frac{d}{dt}$

We therefore have finally that,

\begin{align*}
  \frac{d}{dt}\left(\mathbf{v}\times\mathbf{L}\right) = \frac{d}{dt}\left(\frac{GMm}{r}\mathbf{r}\right)
\end{align*}

And then by minusing the right side,

\begin{align*}
  \frac{d}{dt}\left(\mathbf{v}\times\mathbf{L}-\frac{GMm}{r}\mathbf{r}\right) = \mathbf{0}
\end{align*}

Which is conserved as we've shown here, as it is invariant in time. This will be written in it's final form as a vector,

\begin{align*}
  \mathbf{A} = \mathbf{v}\times\mathbf{L} - \frac{GMm}{r}\mathbf{r}
\end{align*}

This is called the Laplace-Runge-Lenz vector.

\section{Shape of the Orbit}

The shape of the orbit can be found by taking the scalar product of $\mathbf{A}$ with $\mathbf{r}$,

\begin{align*}
  \mathbf{r}\cdot\mathbf{A} = \mathbf{r}\cdot\left(\mathbf{v}\times\mathbf{L}\right) - \frac{GMm}{r}\mathbf{r}\cdot\mathbf{r}
\end{align*}

In the first time on the right hand side of the equation we have the scalar triple product, so $\mathbf{r}\cdot\left(\mathbf{v}\times\mathbf{L}\right) = \left(\mathbf{r}\times\mathbf{v}\right)\cdot\mathbf{L}$. $\mathbf{r}\times\mathbf{v}$ is just equal to the angular momentum divided by the mass, therefore $\mathbf{r}\times\mathbf{v} = \frac{\mathbf{L}}{m}$. Therefore we have,

\begin{align*}
  rA\cos{\theta} &= \left(\mathbf{r}\times\mathbf{v}\right)\cdot\mathbf{L} - GMmr \\
                 &= \frac{L^2}{m} - GMmr \\
  \implies \frac{L^2}{GMm^2} &= r\left[1 + \frac{A}{GMm}\cos{\theta}\right]
\end{align*}

Now we shall make a few definitions,

\begin{align*}
  p &= \frac{L^2}{GMm^2}, \\
  e &= \frac{A}{GMm}
\end{align*}

where $p$ is known as the semi-latus rectum, and $e$ is known as the eccentricity.

Now, if we arrange for $r$, we have the equation for a conic section,

\begin{align*}
  r = \frac{p}{1 + e\cos{\theta}}
\end{align*}

\section{Energy and the LRL Vector}

The magnitude of $A$, and hence the eccentricity $e$, can be related to the energy $E$ of the orbit.

\begin{align*}
  A^2 &= \mathbf{A}\cdot\mathbf{A} = {\|\mathbf{v}\times\mathbf{L}\|}^2 + {\left(\frac{GMm}{r}\right)}^2 \mathbf{r}\cdot\mathbf{r} - 2\frac{GMm}{r} \mathbf{r}\cdot\left(\mathbf{v}\times\mathbf{L}\right) \\
      &= {GMm}^2 - 2\frac{GM}{r} L^2 + {\|\mathbf{v}\times\mathbf{L}\|}^2
\end{align*}

The angular momentum $L^2$ appears in the final line because of the scalar triple product at the end of the first line being equal to $\frac{L^2}{m^2}$.

The term ${\|\mathbf{v}\times\mathbf{L}\|}^2$ can be rewritten, which will be shown generally here,

\begin{align*}
  \mathbf{a}\cdot\mathbf{b} &= ab\cos{\theta} \\
  \mathbf{a}\times\mathbf{b} &= ab\sin{\theta} \mathbf{\hat{n}} \\
  \|\mathbf{a}\times\mathbf{b}\| &= ab\sin{\theta} \\
  {\|\mathbf{a}\times\mathbf{b}\|}^2 + {\left(\mathbf{a}\cdot\mathbf{b}\right)}^2 &= a^2b^2\left[\cos^2\theta + \sin^2\theta\right] = a^2b^2 \\
  \implies{\left(\mathbf{v}\cdot\mathbf{L}\right)}^2 + {\|\mathbf{v}\times\mathbf{L}\|}^2 &= v^2L^2
\end{align*}

But, since $\mathbf{v}$ and $\mathbf{L}$ are perpendicular by definition of $\mathbf{L}$, we see that,

\begin{align*}
  {\|\mathbf{v}\times\mathbf{L}\|}^2 = v^2L^2
\end{align*}

Now we can substitute this in to our equation from earlier to get a relation between $A^2$ and $E = \frac{1}{2}mv^2 - \frac{GMm}{r}$,

\begin{align*}
  A^2 &= {\left(GMm\right)}^2 + v^2L^2 - 2\frac{GM}{r}L^2 \\
      &= {\left(GMm\right)}^2 + \frac{2L^2}{m} \left[\frac{1}{2}mv^2 - \frac{GMm}{r}\right] \\
      &= {\left(GMm\right)}^2 + \frac{2L^2E}{m}
\end{align*}

We now have an expression relating the energy of the orbit to the square of the Laplace-Runge-Lenz vector.

\end{document}


\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{physics}
\setlength{\parindent}{0pt}
\setlength{\parskip}{1em}
\relpenalty=10000
\binoppenalty=10000

\begin{document}
\section{Stereometry}
\begin{enumerate}
\item
Find the volume of an icosahedron with sidelength $a$.

\item
Find the volume of a dodecahedron with sidelength $a$.

\item
Find the density of close packed spheres.

\item % http://www.math.olympiaadid.ut.ee/arhiiv/loppv/lp1993/lp93est.pdf
Points $P_1,\dots,P_n$ are in space such that no three are collinear. Any triangle $P_iP_jP_k$ contains a side which is shorter than $a$. Prove that there exist spheres $S_1$ and $S_2$ with radii, such that all of the $n$ points are in at least one of them.

\item % http://www.math.olympiaadid.ut.ee/latex/varia/kodu/kodu_9697/ky9697_4l.ltx
$P_1$ is a convex polyhedron with vertices $A_1, A_2,\dots,A_9$. Polyhedra $P_2,\dots,P_9$ are formed by shifting $P_1$ such that $A_1$ is shifted to $A_2,\dots,A_9$ respectively. Prove that at least two of the polyhedra $P_1,\dots,P_9$ are intersecting.

\item % 3 http://www.math.olympiaadid.ut.ee/arhiiv/valik/vv2009/vv2009.pdf
Find all integers $n$ for which there exists a convex polyhedron and which satisfies all the following:
\begin{enumerate}
  \item All faces of the polyhedron are regular polygons
  \item Among the faces of the polyhedron there are at most two polygons with different number of sides
  \item There exist two faces which share an edge and are both $n$-gons.
\end{enumerate}

\item % http://www.math.olympiaadid.ut.ee/arhiiv/varia/bwtr/bw07tr/bw07trla.pdf
A convex polyhedron has faces $S_1,\dots,S_n$ with areas $A_1,\dots,A_n$ respectively. For each side $S_i$, let us define a vector $\vec{v_i}$ with length $A_i$ and normal to $S_1$. Prove that $\sum_{i=1}^n \vec{v_i} = \vec{0}$

\end{enumerate}

\end{document}


\documentclass[a4paper]{article}

\usepackage[margin=1in]{geometry} % full-width

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{graphicx, color}
\usepackage[caption=false]{subfig}

% Author info
\title{Double Pendulum equations of motion and numerical results}
\author{Victor I.  Danchev \\ \href{vidanchev@uni-sofia.bg}{vidanchev@uni-sofia.bg}}

\date{
	Sofia University St.  Kliment Ohridski \\
	\today
}

\begin{document}
	\maketitle

	\begin{abstract}
	To be abstracted :)
	\end{abstract}

	\tableofcontents

	\newpage

	\section{Introduction} \label{Intro}
	To be introduced :)

	I'll be modelling a pendulum composed of two rigid rods as opposed to point masses hanged on ropes.

	\section{Equations of motion}\label{EoM}
	\textbf{Starting with the equations as derived on paper, will fill with explanation after!}

	\subsection{The Lagrangian}\label{Lagrangian_subsection}
	We'll define each rod $ i = \{ 1 , 2 \} $ as having length $(l_i)$, mass $(m_i)$ and moment of inertia about its center of mass ($I_{c i}$).
	Additionally we will have the gravitational acceleration norm $g$ as a constant ($g \cong 9.8 [\mathrm{m/s^2}]$).
	Normal vectors for the two "arms" of the pendulum are
	\begin{eqnarray}\label{n_1_def}
		\hat{n}_1 &=& ( \sin{ \theta } , -\cos{ \theta } )^T \\ \label{n_2_def}
		\hat{n}_2 &=& ( \sin{ \varphi } , - \cos{ \varphi } )^T.
	\end{eqnarray}
	Positions of the centre of mass for the two rods are
	\begin{eqnarray}\label{rc_1_def}
		\vec{r}_{c1} &=& \frac{ l_1 }{ 2 }\hat{n}_1 \\ \label{rc_2_def}
		\vec{r}_{c2} &=& l_1 \hat{n}_1 + \frac{ l_2 }{ 2 }\hat{n}_2.
	\end{eqnarray}
	The Lagrangian is taken as the sum of kinetic terms minus the sum of potential terms, which gives
	\begin{eqnarray}\label{initial_Lagrangian}
		L = \frac{1}{2}m_1 |\dot{\vec{r}}_{c1}|^2 + \frac{1}{2}m_2 |\dot{\vec{r}}_{c2}|^2 + \frac{1}{2}I_{c1} |\vec{\omega}_{c1}|^2 + \frac{1}{2}I_{c2} |\vec{\omega}_{c2}|^2 - m_1 g y_{c1} - m_2 g y_{c2},
	\end{eqnarray}
	where $\dot{\vec{\omega}}_{ci}$ are the angular rates around the centres of mass for the two rods.
	Note that constant terms have been neglected (since a Lagrandian is unique up to linear transformation with constants).
	It is easy to see that $|\vec{\omega}_{c1}| = \dot{\theta}$ and $|\vec{\omega}_{c2}| = \dot{\varphi}$.
	Also, given a homogeneous rod of mass $m$ and length $l$, the moment of inertia around its centre of mass is
	\begin{eqnarray}
		I_c = \frac{1}{12}m l^2.
	\end{eqnarray}
	Using \eqref{n_1_def}--\eqref{rc_2_def} in \eqref{initial_Lagrangian}, one gets the full form
	\begin{eqnarray}\label{full_form_Lagrangian}
		L =& \left( \frac{1}{6}m_1 l_1^2 + \frac{1}{2}m_2 l_2^2 \right) \dot{\theta}^2 + \frac{1}{6}m_2 l_2^2 \dot{\varphi}^2 + \frac{1}{2}m_2 l_1 l_2 \cos( \theta - \varphi ) \dot{\theta} \dot{\varphi} \\ \nonumber
		& + \frac{1}{2}m_1 g l_1 \cos{\theta} + m_2 g \left( l_1 \cos{\theta} + \frac{l_2}{2} \cos{\varphi} \right).
	\end{eqnarray}
	A lot of the clutter comes from constants, so I've chosen to simplify to
	\begin{eqnarray}\label{simplified_Lagrangian}
		L = a_{\theta}\dot{\theta}^2 + a_{\varphi}\dot{\varphi}^2 + a_{\mathrm{mix}}\cos( \theta - \varphi )\dot{\theta}\dot{\varphi} + b_{\theta}\cos{\theta} + b_{\varphi}\cos{\varphi},
	\end{eqnarray}
	where I've defined the constants
	\begin{eqnarray}\label{a_th_def}
		a_{\theta} &=& \frac{1}{6}m_1 l_1^2 + \frac{1}{2}m_2 l_2^2 \\ \label{a_phi_def}
		a_{\varphi} &=& \frac{1}{6}m_2 l_2^2 \\ \label{a_mix_def}
		a_{\mathrm{mix}} &=& \frac{1}{2}m_2 l_1 l_2 \\ \label{b_th_def}
		b_{\theta} &=& l_1 g \left( \frac{m_1}{2} + m_2 \right) \\ \label{b_phi_def}
		b_{\varphi} &=& \frac{1}{2} l_2 g m_2.
	\end{eqnarray}
	At this point the equations of motion can be readily derived.

	\subsection{The Equations of Motion}\label{EoM_subsection}
	Lagrange's equations from a minimum action principle give dynamical equations
	\begin{eqnarray}\label{Lagrange_Equations}
		\frac{d}{dt}\left(\frac{d L}{d \dot{q}^i} \right) = \frac{dL}{dq^i},
	\end{eqnarray}
	where $q^i$ are the general positions (configuration space parameters) and $\dot{q}^i$ are their derivatives (general velocities).
	The combination of all of these $\{ q^1, q^2, ... , q^N, \dot{q}^1, \dot{q}^2, ... , \dot{q}^N \}$ is the full state of the system (phase space).
	In our case $N = 2$ and the state is $\vec{s} = ( \theta , \varphi , \dot{\theta} , \dot{\varphi} )^T$.
	I will further denote $\dot{\theta} \equiv \omega_{\theta}$ and $\dot{\varphi} \equiv \omega_{\varphi}$.

	Computing the equations \eqref{Lagrange_Equations} for the Lagrangian \eqref{simplified_Lagrangian} yields the equations of motion
	\begin{eqnarray}\label{eom_1}
		2 a_{\theta} \dot{\omega}_{\theta} + a_{\mathrm{mix}}\cos( \varphi - \theta ) \dot{\omega}_{\varphi} & = - b_{\theta}\sin{\theta} + a_{\mathrm{mix}}\sin( \varphi - \theta )\omega^2_{\varphi} = f_1( \mathrm{state} ) \\ \label{eom_2}
		2 a_{\varphi} \dot{\omega}_{\varphi} + a_{\mathrm{mix}}\cos( \varphi - \theta ) \dot{\omega}_{\theta} & = - b_{\varphi}\sin{\varphi} - a_{\mathrm{mix}}\sin( \varphi - \theta )\omega^2_{\theta} = f_2( \mathrm{state} ),
	\end{eqnarray}
	where $\mathrm{state} \equiv ( \theta , \varphi , \omega_{\theta} , \omega_{\varphi} )^T$.
	This can be written as a matrix equation
	\begin{eqnarray}
		\begin{pmatrix}
			2 a_{\theta} & a_{\mathrm{mix}}\cos( \varphi - \theta ) \\
			a_{\mathrm{mix}}\cos( \varphi - \theta ) & 2 a_{\varphi}
		\end{pmatrix}
		\begin{pmatrix}
			\dot{\omega}_{\theta} \\
			\dot{\omega}_{\varphi}
		\end{pmatrix}
		& = &
		\begin{pmatrix}
			f_1( \mathrm{state} ) \\
			f_2( \mathrm{state} ).
		\end{pmatrix}
	\end{eqnarray}
	Complementing with the two equations $\dot{\varphi} = \omega_{\varphi}$ and $\dot{\theta} = \omega_{\theta}$ gives us a complete 1st order system of 4 non-linear differential equations.
	To solve it explicitly, the matrix on the left-hand-side should be invertable.
	\begin{eqnarray}
		A_{\mathrm{LHS}} & = &
		\begin{pmatrix}
			2 a_{\theta} & a_{\mathrm{mix}}\cos( \varphi - \theta ) \\
			a_{\mathrm{mix}}\cos( \varphi - \theta ) & 2 a_{\varphi}
		\end{pmatrix}
	\end{eqnarray}
	Looking at the determinant, the matrix will always be invertable as long as
	\begin{eqnarray}
		\det{ A_{\mathrm{LHS}} } = 4 a_{\theta} a_{\varphi} - a^2_{\mathrm{mix}} \cos^2( \varphi - \theta ) \neq 0.
	\end{eqnarray}
	Given the definitions of the constants $a$ and $b$, this statement is equivalent to
	\begin{eqnarray}
		\cos^2( \varphi - \theta ) \neq \frac{ 4a_{\theta} a_{\varphi} }{ a^2_{\mathrm{mix}} } = \frac{4}{3} \left( \frac{ l_2 }{ l_1 } \right)^2 \left[ 1 + \frac{m_1 l_1^2}{3 m_2 l_2^2} \right],
	\end{eqnarray}
	which we'll show holds for all the physical cases.

	To be continued :)

	\section{Conclussions}
	To be concluded :)

	\newpage
	\begin{thebibliography}{9}

	\bibitem{Goldstein}
	H.~Goldstein, C.~Poole and J.~Safko, \textit{Classical Mechanics}.

	\end{thebibliography}

\end{document}