\section{Initialization}
\subsection{Subroutine deallocate\_variables}
This subroutine deallocates variable-sized arrays located inside modules. It is called once at the beginning of the program to flush arrays in case the code terminated unexpectedly during the previous run, and again at the end to free the module variables.

\subsection{Subroutine assign\_constants}
This subroutine assigns numeric constants like zero, one, two, $\pi$, etc. and remembers these values in a module. This feature is useful for two main reasons:
\begin{enumerate}
\item Changing precision is easy, since these constants are not hard-coded to single or double precision in later routines.
\item The code looks more like natural English, and will still make sense when read by a person. (e.g. dyn\_pressure = half * rho * V * V)
\end{enumerate}

This subroutine also assigns the quadrature weights and locations along the span for the rotor blade, and also the azimuthal locations where blade loads are sampled for trim. The Gauss-Legendre weights and locations are computed in the interval [0,1] by the subroutine \textbf{gqgen2}, which is a modified expansion of a carry-over routine from Heli-UM. Quadrature locations and weights are stored in the module \textbf{gaussian}.

\subsection{Subroutine gqgen2}
This subroutine generates the Gauss-Legendre quadrature points in the interval [0,1] for a user-specified number of points. This routine is called twice in assign\_constants: once for the spatial locations, and another time for the azimuthal locations within a time element. The quadrature points are the roots of Legendre polynomials $P_n(z)$, which obey some interesting recurrence relations. We will use them to generate the roots of the Legendre polynomial. The logic is explained below.

\subsection*{\textbf{Numerical Integration}}

The external loads on rotating and non-rotating beams are integrated numerically along the span of the blades to determine the forces and moments transmitted to the hub. These integrals are computed numerically using Gaussian Quadrature using weighted summation of the integrand values at specific points along the span.
\[ \textbf{I} \quad = \quad \int \textrm{ }f(r) \textrm{ } dr \]
\textbf{I} denotes the integral, $f$ the integrand and $r$ the spanwise coordinate along the deformed elastic axis. Using numerical quadrature,
\[ \textbf{I} \quad \approx \quad \sum_{i=1}^{n} w_i \textrm{ } f(r_i) \]
The points $r_i$ are the zeros of the Legendre polynomials, which obey some recurrence relations. The first relation is known as Bonnet's recursion formula, given by
\[ n \textrm{ } P_n(x) \quad = \quad (2n-1) \textrm{ } x \textrm{ } P_{n-1}(x) \quad - \quad (n-1) \textrm{ } P_{n-2}(x) \]
$P_n(x)$ is a Legendre polynomial of order ``n'', given by Rodrigues' formula
\[ P_n(x) \quad = \quad \frac{1}{2^n \textrm{ }n!} \textrm{ }\frac{d^n}{dx^n} \textrm{ }\left[\left(x^2\textrm{ }-\textrm{ }1\right)^n\right] \]
Another recurrence relation is
\[ \frac{x^2\textrm{ } -\textrm{ } 1}{n} \textrm{ } \frac{d P_n(x)}{dx} \quad = \quad (2n+1) \textrm{ } x \textrm{ } P_n(x) \quad - \quad n \textrm{ } P_{n-1}(x) \]
$n$ is the user-specified number of quadrature points. The Gauss-Legendre quadrature weights corresponding to each of the locations is given by (Ref. \cite{Abramowitz1964})
\[ w_i \quad = \quad \frac{2}{\left(\textrm{ } 1\textrm{ } -\textrm{ } x_i^2\textrm{ } \right) \textrm{ } \left[ P_n \textrm{}^\prime (x_i)\right]^2} \]
Using iterative convergence, the quadrature locations and the slope of the Legendre polynomial may be identified by using the recurrence relations, starting from an initial guess given by
\[  x_i \quad = \quad \cos \left[\pi \frac{4 i - 1}{4n + 2}\right] \qquad \qquad i = 1,2,3,\cdots,n\]
These locations are generated assuming that the integration range is $[-1,1]$. The quadrature locations and weights may be transformed for use over other limits using a change of coordinates along $x$.

\subsection*{\textbf{Intermediate Quadrature}}
The simulation of beam dynamics requires the computation of the accumulated external loads, from the tip to a certain location of interest. Additionally, the axial fore-shortening $u$ and the Euler rotation angle $\theta_1$ require the accumulated values of certain integrations from the root value to the radial location at which these quantities are evaluated. These ``intermediate'' integrals (so labelled because the limits lie between nodes of finite elements) are evaluated by fitting a polynomial to the sampled values of the integrand within the finite element, and integrating the \emph{fitted} polynomial to reduce computational cost.

Assume that the integrand $f$ is sampled at $n$ points $x_1$, $x_2$, $\cdots$, $x_n$. Let the corresponding values of $f$ at these points be $f_1$, $f_2$, $\cdots$, $f_n$. Let the \textit{approximate} integrand $g(x)$ be represented using a polynomial, given by
\[ f(x) \quad \approx \quad g(x) \quad = \quad \sum_{i = 1}^{n} a_{i-1} \textrm{ } x^{i-1} \]
The coefficients $a_i$, $i$ = 1, 2, $\cdots$, $n$ are determined from the sampled values of the true integrand $f(x)$ at locations $x_i$ using polynomial interpolation. If the approximate integrand matches the true integrand at ($x_1$, $x_2$, $\cdots$, $x_n$) then
\[ \begin{Bmatrix} f(x_1) \\ f(x_2) \\ \cdot \\ \cdot \\ f(x_n) \end{Bmatrix} \quad = \quad \begin{bmatrix} 1 & x_1 & x_1^2 & \cdots & x_1^{n-1} \\ 1 & x_2 & x_2^2 & \cdots & x_2^{n-1} \\ \cdot  & \cdot & \cdot & \cdot & \cdot \\ \cdot  & \cdot & \cdot & \cdot & \cdot \\ 1 & x_n & x_n^2 & \cdots & x_n^{n-1} \end{bmatrix} \quad  \begin{Bmatrix} a_0 \\ a_1 \\ \cdot \\ \cdot \\ a_{n-1} \end{Bmatrix} \]
This system of linear equations may be written as a matrix-vector product
\[ \vector{f} \quad = \quad \textbf{C} \textrm{ } \vector{a} \]
\textbf{C} is invertible as long as all quadrature locations are unique. The polynomial coefficients $\vector{a}$ are obtained by inverting \textbf{C} to yield
\[ \vector{a} \quad = \quad \textbf{C}^{-1} \textrm{ } \vector{f} \]
The approximate integrand may be integrated along the span of the element using different limits, depending on the quantity of interest. For displacement quantities (Euler rotation $\theta_1$ and axial fore-shortening $u$) the integration limits are from the left end of the element to the quadrature point of interest. The integrated value is
\[ \textrm{I}_\textrm{inboard}(x_1) \quad = \quad \int_{0}^{r_{_1}} \textrm{ } g(r_{_1}) \textrm{ }  dr_{_1} \quad = \quad \frac{dr}{dx} \textrm{ } \sum_{i = 1}^{n} a_{i-1} \textrm{ } \frac{x_1^{i}}{i} \]
$\frac{dr}{dx}$ represents the scale factor between the non-dimensional coordinate $x$ and the dimensional coordinate $r$. The summation may be written as a matrix-vector product

\[ \textrm{I}_\textrm{inboard}(x_1) \quad = \quad \frac{dr}{dx} \quad \begin{Bmatrix} x_1 & & \frac{1}{2} x_1^2 & & \cdots & &\frac{1}{n-1} x_1^{n-1} \end{Bmatrix} \textrm{ } \begin{Bmatrix} a_0 \\ a_1 \\ \cdot \\ \cdot \\ a_{n-1} \end{Bmatrix} \]
Using the same notation for the integrals at the other quadrature points, we obtain
\[ \begin{Bmatrix} \textrm{I}(x_1) \\ \textrm{I}(x_2) \\ \cdot \\ \cdot \\ \textrm{I}(x_n)\end{Bmatrix}_\textrm{inboard} = \quad \frac{dr}{dx} \textrm{ } \begin{bmatrix} x_1 & & \frac{1}{2} x_1^2 & & \cdots & &\frac{1}{n-1} x_1^{n-1} \\ x_2 & & \frac{1}{2} x_2^2 & & \cdots & &\frac{1}{n-1} x_2^{n-1} \\ \cdot & & \cdot & & \cdot & & \cdot \\ \cdot & & \cdot & & \cdot & & \cdot \\ x_n & & \frac{1}{2} x_n^2 & & \cdots & &\frac{1}{n-1} x_n^{n-1} \end{bmatrix} \begin{Bmatrix} a_0 \\ a_1 \\ \cdot \\ \cdot \\ a_{n-1} \end{Bmatrix}
\]
The vector of integrals $\vector{I}$ may be written as another matrix vector product as
\[ \vector{I}_\textrm{inboard} \quad = \quad \frac{dr}{dx} \textrm{ }\textbf{E} \textrm{ } \vector{a} \quad = \quad \frac{dr}{dx} \textrm{ }\textbf{E} \textrm{ }\textbf{C}^{-1} \textrm{ }\vector{f} \]
Similarly, the vector of integrals with limits from the current radial position to the outboard end of the finite element is
\[ \vector{I}_\textrm{outboard} \quad = \quad \frac{dr}{dx} \textrm{ }\textbf{F} \textrm{ } \textbf{C}^{-1} \textrm{ } \vector{f} \]
The entries in row $i$ and column $j$ of \textbf{E} and \textbf{F} are
\[ E(i,j) \quad = \quad E_{ij} \quad = \quad \frac{1}{j} x_i^{\textrm{ } j} \qquad \textrm{and} \qquad F(i,j) \quad = \quad F_{ij} \quad = \quad \frac{1}{j} \textrm{ } \left(1- x_i^{\textrm{ } j}\right) \]
The matrices \textbf{E} \textbf{C}$^{-1}$ and \textbf{F} \textbf{C}$^{-1}$ are independent of loads and can be pre-computed. The term $\frac{dr}{dx}$ is the dimensional length of the finite element $l_e$.

\section*{Reading Input Files}
This section explains the code logic governing file read operations and preprocessing steps that are performed prior to any simulation. This step includes reading input files and choosing rotor configurations, aircraft information, flight or wind-tunnel conditions, etc. The call graph is shown below, complete with all dependencies. The various subroutines that read program input files from the subfolder \textbf{Inputs/} are listed below. For a detailed list of the individual inputs, please refer to the user manual.

\subsection{Subroutine read\_solver\_options}
This subroutine reads the program operations from the file \textbf{Solver\_options.input} that specifies the spatial and time discretization for the rotorcraft model, and chooses which of the operations to perform (modal reduction, trim, transfer functions and time marching). Based on the values in the input files, some input files may be omitted if they are not relevant to the configuration chosen. The solver options are stored in a derived type called \textbf{SolverOptions}, in the module \textbf{py\_visible\_globals}.

\begin{Figure}
 \centering
 \includegraphics[width=1.0\linewidth]{images/read_pgmin_callgraph.png}
 \captionof{figure}{Call Graph for Reading Program Input Files}
 \label{fig:mpcg}
\end{Figure}

\subsection{Subroutine read\_wake\_inputs}
This subroutine reads the free wake discretization parameters from \textbf{Free\_wake.input}, if the flag to use the vortex wake model is enabled in Solver\_optoins.input. If the flag is set to \textbf{.F.}, then this subroutine is bypassed. These parameters are stored in a derived type called \textbf{Free\_wake}, located in the module \textbf{py\_invisible\_globals}.

\subsection{Subroutine read\_composite\_coupling}
This subroutine is not yet at the ``production stage''. It is meant to provide structural cross-couplings in the blade dynamics to represent composite material properties.

\subsection{Subroutine read\_flight\_condition}
This subroutine reads the file \textbf{Flight\_condition.input}, which specifies the vehicle speed, altitude, turn rate and climb angle, i.e. target trim conditions. These parameters are stored in a derived type called \textbf{FlightParam}, in the module \textbf{py\_visible\_globals}.

\subsection{Subroutine read\_airloads}
This subroutine is used for CFD-CSD coupling, but may be bypassed by setting the appropriate flags to \textbf{.F.} in \textbf{Solver\_options.input}. It reads airloads (section C$_\ell$, C$_d$ and C$_m$) along the span and around the azimuth for all rotors over one revolution, and returns interpolated loads through a derived type \textbf{Airloads} in the module \textbf{py\_visible\_globals}. This subroutine calls three subroutines:

\subsubsection{Subroutine open\_and\_read}
This subroutine reads airloads distributions from disk, given a file unit identifier. The airloads must be in the OVERTURNS format.

\subsubsection{Subroutine interp\_airloads}
This subroutine interpolates airloads distributions from OVERTURNS radial and azimuthal locations to those required by the CSD solver, using a custom routine written for polar coordinates. This subroutine calls a subroutine \textbf{linterp\_weights} to generate linear interpolation weights and indices along the span and azimuth.

\subsubsection{Subroutine test\_write}
This subroutine writes the airloads from a derived type to various output files to verify that the interpolation did not fail.

\subsection{Subroutine read\_tunnel\_targets}
This subroutine reads the wind tunnel conditions from the file \textbf{Wind\_tunnel.input}, but is bypassed in propulsive trim, indicated by the appropriate flags in \textbf{Solver\_options.input}. It reads shaft tilt, target hub loads, target swashplate controls and type of wind-tunnel trim to perform.

\subsection{Subroutine write\_postprocessor}
This subroutine writes the output file \textbf{options\_trim.dat} that can be used by postprocessors to interpret the numbers in the batch run output files \textbf{Outputs/Trim\_01.dat} and \textbf{Outputs/Trim\_02.dat}. Refer to the user manual for more details on the individual outputs.

\subsection{Subroutine read\_databases}
This subroutine reads the physical properties of the rotor blades, number of rotors, airfoil tables, fuselage aerodynamic force tables, etc and stores these physical constants in a multiply nested derived type called \textbf{Aircraft} (name preserved from HeliUM convention) in the module \textbf{py\_invisible\_globals}. The purpose of this subroutine is to read all available databases and aircraft configurations, and selectively preserve the ones required for the current simulation. After reading individual blade and airfoil properties, the required rotor structural and aerodynamic characteristics are assembled. The required airfoil tables are stored in memory, and a map is created between the airfoil identifier and its storage location in memory to enable faster access. Finally, the blade structural properties are interpolated and stored at the quadrature points at each finite element in the subroutine \textbf{assign\_rotor\_properties} under the derived type \textbf{BeamProperties}, nested under the \textbf{Blade} type, which is nested under the \textbf{Rotor} type, and finally under the \textbf{Aircraft} type. These numbers do not change during a simulation, and the \textbf{Aircraft} type may be used with the \textbf{intent(in)} keyword to enforce coding consistency.

In addition to obtaining structural properties for the CSD solver, the subroutine \textbf{assign\_rotor\_properties} also obtains blade chord and twist for the free wake solver at equi-spaced radial locations between the blade root cut-out and tip.

\subsection*{Non-Dimensionalization}
The analysis has been performed in a non-dimensional form to avoid overflow and underflow truncation errors. Table \ref{tbl:nondiml} shows the reference parameters used to nondimensionalize the relevant physical quantities. $\Omega_0$ is initially set to the rotor speed, but any value may be chosen for the time constant. This feature is extremely useful, since it allows for changing rotor RPM during batch runs.
\begin{table}[ht]
\begin{minipage}{\columnwidth}
\centering
\caption{Fundamental Non-Dimensionalization Constants}
\label{tbl:nondiml}
\begin{tabular}{ll} \hline \hline
Physical Quantity & Reference Parameter	  	\\
\hline
Mass per unit span & Average blade mass per unit span m$_0$ = $\displaystyle \frac{W_\textrm{b}}{g}$\\
Length 			   & Beam Length (R) \\
Time			   & $\Omega_0^{-1}$ \\
\hline
\end{tabular} \end{minipage}
\end{table}


\section{The \variant{\edgetransitions} problem}
\label{sec:edges}

Whereas \variant{\nodeitems} (Problem~\ref{problem:nodes-variant}) seeks $k$
nodes to optimize expected uncertainty, \variant{\edgetransitions} seeks
$k$ edges.
\begin{problem}[{\edgeproblem}]
Given $G=(V,E)$, transition matrix $\transition$,
initial distribution of items to nodes
$\initial$ and integer $k$, find
$S\subseteq V$ such that $|S|=k$ such that
$\objective_\shortedgetransitions\left(S\right)$
(Equation~\eqref{eq:edgetransitions}) is minimized.
\label{problem:edges-variant}
\end{problem}
We provide two polynomial-time algorithms to solve
the problem, namely \edgeDP\ and \edgegreedy.
For the former, we can also prove that it is optimal, and thus Problem~\ref{problem:edges-variant}
is solvable in polynomial time.

\spara{The {\edgeDP} algorithm:}
{\edgeDP} is a dynamic-programming algorithm that
selects edges in two steps: first, it sorts the {\it outgoing}
edges of
each node in decreasing order of transition probability, thus
creating $|V| = n$ corresponding lists; secondly, it combines top edges from
each list to select a total of $k$ edges.
%The algorithm is polynomial and optimal.

In more detail, let $SOL_i(k)$ be the cost
of an optimal solution for the special case of
a budget of $k$ edges allocated among outgoing edges of nodes
$V_{i:} = \{i, i+1, \ldots, n\}$.
According to this notational convention,
the cost of an optimal solution $D_{opt}$ for the problem is given by
$SOL_1(k)$.
%  --
% and we define $SOL_i(k) = \infty$ for $k < 0$ and $SOL_i(k) = 0$
% for $i > \|V\| = n$.
Moreover, considering Equation~\eqref{eq:edgetransitions},
let $\objective_i$ be the function that corresponds to
the (outer) summation term for node $i$
\begin{equation}
	\objective_i(D) = \initial^{\prime\prime}(i)\sum_{v\in V\setminus S}\transition^{\prime\prime}(i,v)\left(1-\transition^{\prime\prime}(i,v)\right)
\end{equation}
(under the auxilliary definitions of Equations \eqref{eq:etinit}
and \eqref{eq:ettransit})
and $ISOL_i(m)$ its optimal value when $D$ contains no more than
$m\leq k$ outgoing edges from node $i$.
Let also $D_i^m$ be a subset of $k$ outgoing edges of $i$
with the highest transition
probabilities.
It can be shown that the optimal value
for $\objective_i(D)$ is achieved for
the edges $D_i^k$ with {\it highest} transition
probability\footnote{For a proof,
see Supplementary Material, Lemma~\ref{lemma:singlenodeoptimality}.}.
Having the outgoing edges of $i$ sorted by transition probability,
we can compute $ISOL_i(m)$ for all $m = 0\ldots k$.

The dynamic programming equation is:
\begin{equation}
	SOL_i(k) = \argmin_{0\leq m\leq k}\{ISOL_i(m) + SOL_{i+1}(k - m)\}
	\label{eq:dptop}
\end{equation}
\edgeDP\ essentially computes and keeps in memory
$\|V\| \times (k+1)$ values according to Eq.\eqref{eq:dptop}.

Given the above, we have the following result:

\begin{lemma}
The {\edgeDP} algorithm is optimal for the {\edgeproblem} problem.
\end{lemma}

% \begin{algorithm}
% \LinesNumbered
%  \KwIn{k}
%  \KwOut{SOL: Dynamic programming array}
%  initialize empty array $SOL_{\|V\| \times (k+1)}$;\\
%  \For{i = $\|V\|$..1}{
%   \For{$k'$ = 0:k}{
%     SOL[$i$, $k'$] := $\argmin_{0\leq k_i\leq k'}\{ISOL_i(k_i) + SOL[i+1, k' - k_i]\}\}$
%    }
%  }
%  \Return SOL;
%  \caption{Dynamic programming algorithm for the \edgetransitions\ variant.}
%  \label{alg:edgeDP}
% \end{algorithm}

For a proof sketch of this lemma see Supplementary Material,
Theorem~\ref{theorem:edgeDP}.

\emph{Running time:} \edgeDP\
computes $k\times |V|$ values. For each value to be
computed, up to $O(k)$ numerical operations are performed. Therefore,
\edgeDP\ runs in $O(k^2|V|)$ operations. Backtracking to retrieve the
optimal solution requires at most equal number of steps, so it does not
increase the asymptotic running time.

\spara{The {\edgegreedy} algorithm:}
\edgegreedy\ is a natural greedy algorithm that selects
$k$ edges in an equal number of steps, in each step selecting
one more edge to minimize $\objective_{\shortedgetransitions}$.
% \edgegreedy\ is described in Algorithm~\ref{alg:edgegreedy}.

% \begin{algorithm}
% \LinesNumbered
%  \KwIn{k}
%  \KwOut{$ResultEdges$: Set of selected edges}
%  $ResultEdges$ = $\{\}$ \\
%  \For{$i = 1 \cdots k$}{
%  	Select $e\in E$ :=
%  		$\argmin \objective_{\shortedgetransitions}(ResultEdges \cup \{e\})$ \\
%  	$ResultEdges$ := $ResultEdges$ $\cup$ \{e\}; \\
%  	E := E $\setminus$ \{e\}; \\
%  }
%  \Return $ResultEdges$;
%  \caption{Greedy algorithm for the \edgetransitions\ variant.}
%  \label{alg:edgegreedy}
% \end{algorithm}

%Unfortunately, we have not been able to prove or dispove optimality
%for \edgegreedy.

In all our experiments the performance of {\edgegreedy} is the same as the performance of
the optimal {\edgeDP} algorithm. However, we do not have a proof that the former is also optimal. We leave this as a problem for future work.

\emph{Running time:} Following Equation \eqref{eq:edgetransitions},
to select $k$ edges,
\edgegreedy\ %as defined in Algorithm~\ref{alg:edgegreedy}
invokes up to $k\times O(|E|)$ evaluations of
$\objective_{\shortedgetransitions}$.
% ; and each evaluation of
% $\objective_{\shortedgetransitions}$ involves $O(|E|)$ numerical operations.
As we discussed for \nodegreedy, if the evaluation of the
objective function is naively implemented with a double summation,
the running time of \edgegreedy\ is
$O(k|E||V|^2)$ numerical operations.
If the objective function is implemented as a summation over edges,
the running time improves to $O(k|E|^2)$.
Furthermore, following the observations similar to those we saw for {\nodegreedy}, the
running time of \edgegreedy\ becomes $O(|E| + k|E|) = O(k|E|)$.

We notice that \edgeDP\ has better
performance than \edgegreedy\ for dense graphs ($|E|\approxeq |V|^2$)
and small $k$. Moreover, as with \nodegreedy, \edgegreedy\ is
amenable to parallelization - the new value of the objective function
can be computed in independently for each edge that's considered for
selection.

% We have the following theorem for \edgegreedy.
% \begin{theorem}
% \edgegreedy\ is optimal for the \edgetransitions\ variant of
% the \mcproblem\ problem.
% \label{theorem:edgegreedy}
% \end{theorem}
% The proof for Theorem~\ref{theorem:edgegreedy} mirrors the proof for
% Theorem~\ref{theorem:nodegreedy}, adjusted to the selection of edges instead
% of nodes - and is omitted for brevity.


%!TEX root = ../TTT4150-Summary.tex
\section{Coordinate frames}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Reference frames}

\subsubsection{Notation}
\begin{itemize}
    \item $\V{v}^n$---velocity given in frame $n$
    \item $\M{R}_p^n$---rotation from frame $p$ to $n$
    \item $\V{\omega}_{ip}^p$---angular rate of frame $p$ w.r.t. $i$, represented in $p$.
\end{itemize}

\subsubsection{Inertial frames and the ECI frame $\{i\}$}
A frame in which Newton's laws of motion apply, i.e. it does not accelerate. All inertial sensors measure relative to an inertial frame. \emph{Earth-centered intertial} (ECI) is an example of this, with origin at the Earth center, not rotating with the earth. (But as the Earth rotates around the sun, ECI is not exactly inertial.)

\subsubsection{ECEF frame $\{e\}$}
Earth-centered, earth-fixed. Rotates relative to ECI with $\omega_{ie} \approx \SI{7.292e-5}{\radian\per\second}$.

\subsubsection{Geographic frame $\{g\}$}
Origin equal to platform origin projected onto the reference ellipsoid. $z$-axis down, normal to ellipsoid surface. $x$-axis north, $y$-axis east. Not inertial.

\subsubsection{Geocentric frame}
Similar to the geographic frame, but $z$-axis down toward Earth center. Also not inertial.

\subsubsection{Tangent plane}
North, east, down as used in daily life. Origin at a fixed point on Earth. Coincides with the geographic frame when the system origin coincides with the tangent frame origin.

\subsubsection{Body frame $\{b\}$}
Attached to the vehicle of interest, often origin at center of gravity. $x$-axis forward, $z$-axis down, and $y$-axis completes the right-handed orthogonal coordinate system (i.e. to the right).

\subsubsection{Platform frame}
Frame centered somewhere on the sensor platform. Usually non-moving wrt. the body frame, so $\M{R}_p^b$ is constant.

\subsubsection{Instrument frame}
The frame along which an instrument measures. (An IMU measures acceleration along the instrument axes, and rotation rate around the instrument frame axes.)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Ellipsoids}

\begin{figure}[htbp]
    \centering
    \includegraphics[width=.6\linewidth]{img/ellipsoid}
    \caption{An oblate ellipsoid}
    \label{fig:ellipsoid}
\end{figure}
An ellipsoid is defined by its semi-major axis $a$ and semi-minor axis $b$ (see Figure \ref{fig:ellipsoid}). Its \emph{eccentricity} $e$ is defined by
\begin{equation}
    e^2 = \frac{a^2 - b^2}{a^2} .
\end{equation}
and its flattening $f$ is
\begin{equation}
    f = \frac{a-b}{a} .
\end{equation}

\subsubsection{Radii of curvature}
$M$ is the radius of curvature of a meridian at a given geodetic latitude $\phi$. $N$ is the radius of curvature normal to the meridian at a given $\phi$. Because the Earth is oblate, $M$ is largest at the poles, and smallest at the equator. At the poles, $N = M$, because the radius is the same in all directions.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Geodetic coordinates}

Defined by
\begin{itemize}
    \item latitide $\phi$,
    \item longitude $\lambda$, and
    \item height $h$ above the ellipsoid.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Definitions of height}

Three surface models are used: The ellipsoid surface, the geoid surface, and the true surface of the earth. The \emph{geoid} is based on what the mean sea level would be based on local gravitation and the earth rotation.

\begin{itemize}
    \item Orthometric height: Height above the geoid.
    \item Geoid height: Height of the geoid above/below the ellipsoid.
    \item Ellipsoidal height: Height above the ellipsoid, measured normal to the surface. This is what GPS uses.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Earth-Centered, Earth-Fixed (ECEF) coordinates}

Defined by Cartesian coordinates $X$, $Y$, and $Z$, along the axes in Figure \ref{fig:ellipsoid}. The positive $x$-axis intersects the surface at $\phi = \lambda = 0^\circ$. (The frame is fixed to Earth and rotates with it.)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Conversion from geodetic to ECEF}

For a sphere of radius $R$ we have
\begin{equation}
\begin{split}
    X &= (R+h) \cos \phi \cos \lambda \\
    Y &= (R+h) \cos \phi \sin \lambda \\
    Z &= (R+h) \sin \phi .
\end{split}
\end{equation}

For an ellipsoid with semi-minor axis $a$ and semi-major axis $b$, we have
\begin{equation}
\begin{split}
    X &= (N + h) \cos \phi \cos \lambda \\
    Y &= (N + h) \cos \phi \sin \lambda \\
    Z &= \left( N[1-e^2] + h \right) \sin \phi
\end{split}
\end{equation}
where the \emph{normal radius of curvature} is
\begin{equation}
    N = \frac{a}{\sqrt{1-e^2 \sin^2 \phi}} .
\end{equation}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Conversion from ECEF to geodetic}

Easy for a sphere:
\begin{equation}
\begin{split}
    \phi    &= \atan \frac{Z^2}{\sqrt{X^2 + Y^2}} \\
    \lambda &= \atan \frac{Y}{X}                  \\
    h       &= \sqrt{X^2 + Y^2} \cos \phi + Z \sin \phi - R
\end{split}
\end{equation}

For an ellipse, ECEF to geodetic conversion can be done iteratively or by one of several closed-form solutions.

\subsubsection{Iterative method}
The longitude $\lambda$ is found as
\begin{equation}
    \lambda = \atan \frac{X}{Y} .
\end{equation}

The latitude $\phi$ is found by iterating
\begin{equation}
    \phi_{k+1}
    =
    \atan
    \left(
        \frac{Z}{\rho}
        +
        \frac{N_k e^2 \sin \phi_k}{\rho}
    \right)
\end{equation}
where
\begin{equation}
    \rho = \sqrt{X^2 + Y^2} .
\end{equation}

When $\phi$ is sufficiently accurate, the height $h$ is found by
\begin{equation}
    h = \rho \cos \phi + Z \sin \phi - N(1 - e^2 \sin^2 \phi)
\end{equation}

\subsubsection{Bowring's closed-form method}
Only valid near the Earth surface.
\begin{equation}
\begin{split}
    \phi &= \atan \frac{Z + e^2 b \sin^3 \mu}{\rho - e^2 a \cos^3 \mu} \\
    \mu  &= \atan \frac{Z a}{\rho b}
\end{split}
\end{equation}

\subsubsection{Vermeille's closed-form method}
Closed-form, valid quite far from Earth (including satellite orbits). Really mathy.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Direction cosine matrix}

You have a vector $\V{v}_1$ given in frame $\phi_1$. The unit vectors along the axes of $\phi_1$ are $I_1$, $J_1$, and $K_1$. Similarly, the unit vectors along the axes of $\phi_2$ are $I_2$, $J_2$, and $K_2$.

Then, the direction cosine matrix between the frames is
\begin{equation}
    \M{R}_2^1
    =
    \begin{pmatrix}
        \cos(I_2, I_1) & \cos(I_2, J_1) & \cos(I_2, K_1) \\
        \cos(J_2, I_1) & \cos(J_2, J_1) & \cos(J_2, K_1) \\
        \cos(K_2, I_1) & \cos(K_2, J_1) & \cos(K_2, K_1) \\
    \end{pmatrix}
\end{equation}


\documentclass[letterpaper]{article}

\usepackage{fullpage}
\usepackage{nopageno}
\usepackage{amsmath}
\usepackage{amssymb}
\allowdisplaybreaks

\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}

\begin{document}
\title{Notes}
\date{November 10, 2014}
\maketitle
\section*{4.3 \#21a,c}
Find multiplicative inverses of the given elements in the given fields
\subsection*{a}
$[a+bx]$ in $\mathbb{R}[x]/\langle x^2+1\rangle$

\begin{align*}
  [a+bx][c+dx]&\equiv 1\mod (x^2+1)\\
  (a+bx)(c+dx)-1&=x^2+1\\
  x^2+1&=q(a+bx)+r\\
  x^2+1&=(bx+a)(\frac{1}{b}x-\frac{a}{b^2})+1+\frac{a^2}{b^2}
\end{align*}
\subsection*{c}
$[x^2-2x+1]$ in $\mathbb{R}[x]/\langle x^3-2\rangle$

$x^3-2=(x^2-2x+1)(x+2)+3x-4$

$x^2-2x+1=(\frac{1}{3}x-\frac{2}{9})(3x-4)+\frac{1}{9}$

$1=9(x^2-2x+1)-9(\frac{1}{3}x-\frac{2}{9})(3x-4)$

$1=(x^2-2x+1)(9+(3x-2)(x+2))-(x^3-2)(3x-2)$

$[1]=[x^2-2x+1][3x^2+4x+5]-[x^3-2][3x-2]$

$[0]=[x^3-2]$

$[x^2-2x+1]^{-1}=[3x^2+4x+5]$

\section*{htrm}
f has no repeated factors iff $\gcd(f(x),f^{-1}(x))=1$
\subsection*{example}
$K=Z_{p}(T)=\{\frac{f(t)}{g(t)}:f(t),g(t)\in \mathbb{Z}_p[T],g(t)\ne 0\}$ check that $K$ is a field

let $f(x)=x^p-T\in K[x]$. claim that $f(x)$ is irreducible.

\section*{proposition}
let $p(x)in K[x]\setminus \{0\}$ be irreducible with $\deg p\ge 1$. then $K[x]/\langle p(x)\rangle$ is a field.
\section*{proof}
sind $p(x)$ is irreducible then $\gcd(f(x),p(x))=1$ and so $[f(x)]$ has mult inverse.

\section*{thm}
take $f(x)\in K[x]$ with $\deg f\ge 1$ then there exists an extension of $K$ called $L$ such that $f(x)$ has a root in $L$
\subsection*{proof}
let $p(x)$ be an irreducible factor of $f(x)$. now let $L=K[x]/\langle p(x)\rangle$. now $K\to \{[a]:a\in K\}\subseteq L$ with $x\to[x]$ is an isomorphism. let $u=[x]=L$ and $f(u)=p(u)g(u)=p([x])g(u)=0g(u)=0$
\end{document}