\chapterimage{head2.png} % Chapter heading image
\chapter{EM Algorithm}

\section{The General EM Algorithm}
\begin{definition}[The joint probability]
    \begin{equation}
        p(\textbf{x}, \textbf{y})= p(x_0)\prod_{t=1}^{T} p(x_{t}|x_{t-1}) p(y_t|x_t)
    \end{equation}
    \begin{center}
        \includegraphics[scale=0.6]{ch2/four_states_ex.png}
    \end{center}
In this example
    \begin{equation}
    \begin{split}
        p(\textbf{x}, \textbf{y})= &[p(x_0) p(x_1|x_0) p(y_1|x_1)] [p(x_2|x_1) p(y_2|x_2)]  [p(x_3|x_2) p(y_3|x_3)] \\
        &[p(x_4|x_3) p(y_4|x_4)]
    \end{split}
    \end{equation}
\end{definition}

\begin{definition}[The likelihood functional]
\begin{equation}
    L[\theta] = p(\textbf{y};\theta) = \int d\textbf{x}p(\textbf{x}, \textbf{y})
\end{equation}
\end{definition}

\begin{definition}[The log-likelihood functional]
\begin{equation}
    l[\theta] = \ln{(\int d\textbf{x}p(\textbf{x}, \textbf{y}))}
\end{equation}
\end{definition}

\begin{definition}[Solve Euler-Lagrange equation]
Maximization for the optimal parameter set requires taking derivatives of the log-likelihood functional and solves the resulting Euler-Lagrange equation:
\begin{equation}
        \frac{\partial l[\theta]}{\partial \theta} = \frac{\partial}{\partial \theta} \ln{(\int d\textbf{x}p(\textbf{x}, \textbf{y}))} = 0
\end{equation}
We can further get
\begin{equation}
    \frac{\partial l[\theta]}{\partial \theta} =  \frac{\partial \ln{L[\theta]}}{\partial \theta} = \frac{1}{L[\theta]}\frac{\partial L[\theta]}{\partial \theta}
\end{equation}
Because we need to do maximization according to previous step($k$), we want to solve the
following equation
\begin{equation}
    0 = \frac{\partial l^k[\theta]}{\partial \theta} = \frac{1}{L^k[\theta]}\frac{\partial L^k[\theta]}{\partial \theta}
\end{equation}
And we can express the likelihood functional as
\begin{equation}
    L^k[\theta] = p(\textbf{y}) = \sum_{\tau=0}^{T-1} \left<\alpha^k_{t_{\tau}}\right|  e^{-\textbf{H} \Delta t} \left|\beta^k_{t_{\tau+1}}\right>
\end{equation}
Therefore, the maximization problem becomes to solve
\begin{equation}
    0 =  \frac{\partial l^k[\theta]}{\partial \theta} = \frac{1}{L^k[\theta]} \sum_{\tau=0}^{T-1} \frac{\partial}{\partial \theta} \left<\alpha^k_{t_{\tau}}\right|  e^{-\textbf{H} \Delta t} \left|\beta^k_{t_{\tau+1}}\right>
\end{equation}
\end{definition}

\section{The expected log of the complete likelihood}
\begin{definition}[$\left<\alpha^k_{t_{0}}\right|  e^{-\textbf{H} \Delta t} \left|\beta^k_{t_{1}}\right>$]
\begin{equation}
    \left< \alpha_{t_0} | e^{-\textbf{H}\Delta t} | \beta_{t_1} \right> = \int p(x_0) p(x_1|x_0) p(y_2,y_3,y_4|x_1) dx_1= p(x_0,y_2,y_3,y_4)
\end{equation}
    \begin{center}
        \includegraphics[scale=0.25]{ch4/alpha_t0_e_beta_t1.pdf}
    \end{center}
\end{definition}

\begin{definition}[$\left<\alpha^k_{t_{1}}\right|  e^{-\textbf{H} \Delta t} \left|\beta^k_{t_{2}}\right>$]
\begin{equation}
    \left< \alpha_{t_1} | e^{-\textbf{H}\Delta t} | \beta_{t_2} \right> = \int p(x_1,y_1) p(x_2|x_1) p(y_3,y_4|x_2) dx_2= p(x_1,y_1,y_3,y_4)
\end{equation}
\begin{center}
    \includegraphics[scale=0.35]{ch4/alpha_t1_e_beta_t2.pdf}
\end{center}
\end{definition}

\begin{definition}[$\left<\alpha^k_{t_{2}}\right|  e^{-\textbf{H} \Delta t} \left|\beta^k_{t_{3}}\right>$]
\begin{equation}
    \left< \alpha_{t_2} | e^{-\textbf{H}\Delta t} | \beta_{t_3} \right> = \int p(x_2,y_1,y_2) p(x_3|x_2) p(y_4|x_3) dx_3= p(x_2,y_1,y_2,y_4)
\end{equation}
\begin{center}
    \includegraphics[scale=0.35]{ch4/alpha_t2_e_beta_t3.pdf}
\end{center}
\end{definition}

\begin{definition}[$\left<\alpha^k_{t_{3}}\right|  e^{-\textbf{H} \Delta t} \left|\beta^k_{t_{4}}\right>$]
\begin{equation}
    \left< \alpha_{t_3} | e^{-\textbf{H}\Delta t} | \beta_{t_4} \right> = \int p(x_3,y_1,y_2,y_3) p(x_4|x_3) dx_4= p(x_3,y_1,y_2,y_3)
\end{equation}
\begin{center}
    \includegraphics[scale=0.25]{ch4/alpha_t3_e_beta_t4.pdf}
\end{center}
\end{definition}

\section{Update the equilibrium probability density}
\begin{definition}
    The basis functions in Def.(\ref{basisfunctions}) were used to update
\begin{align}
    p_{\rm eq}^{k+1}(x) &=\mathbb{E}^k_{X|Y} \left[ \delta(x-X) \right] \\
    &= p^k_{\rm{eq}}(x) \sum_{i,j} \mathbb{E}^k_{X|Y}[a_ib_j] \phi_i(x)\phi_j(x) \\
    &= \sum_{i,j} \psi_i(x) \mathbb{E}^k_{X|Y}[a_ib_j] \psi_j(x).
\end{align}
\end{definition}

\begin{definition}[Update from matrix multiplication]
\begin{align}
    p_{\rm eq}^{k+1}(x) = \mathrm{diag}(\Psi \mathbb{E}^k_{X|Y}[a_ib_j] \Psi^{\dagger})
\end{align}
\end{definition}

\begin{example}[$N_v=3$] In the matrix multiplication, I abbreviate $\mathbb{E}^k_{X|Y}[a_ib_j]$ as $a_ib_j$, and the grids are set like the bottom figure. We will show
\begin{align*}
    p_{\rm eq}^{k+1}(x) &=\sum_{i,j} \psi_i(x) \mathbb{E}^k_{X|Y}[a_ib_j] \psi_j(x) \\
    &= \mathrm{diag}(\Psi \mathbb{E}^k_{X|Y}[a_ib_j] \Psi^{\dagger})
\end{align*}
\begin{center}
    \includegraphics[scale=1.5]{ch4/ex1_grids.pdf}
\end{center}
\begin{align*}
&\Psi \mathbb{E}^k_{X|Y}[a_ib_j] \Psi^{\dagger} = \\
&\begin{bmatrix}
    \psi_1(x_1) & \psi_2(x_1) & \psi_3(x_1)  \\
    \psi_1(x_2) & \psi_2(x_2) & \psi_3(x_2) \\
    \psi_1(x_3) & \psi_2(x_3) & \psi_3(x_3)  \\
    \psi_1(x_4) & \psi_2(x_4) & \psi_3(x_4)  \\
    \psi_1(x_5) & \psi_2(x_5) & \psi_3(x_5)
\end{bmatrix}
\begin{bmatrix}
    a_1 b_1 & a_1 b_2 & a_1 b_3  \\
    a_2 b_1 & a_2 b_2 & a_2 b_3 \\
    a_3 b_1 & a_3 b_2 & a_3 b_3
\end{bmatrix}
\begin{bmatrix}
    \psi_1(x_1) & \psi_1(x_2) & \psi_1(x_3) & \psi_1(x_4) & \psi_1(x_5) \\
    \psi_2(x_1) & \psi_2(x_2) & \psi_2(x_3) & \psi_2(x_4) & \psi_2(x_5) \\
    \psi_3(x_1) & \psi_3(x_2) & \psi_3(x_3) & \psi_3(x_4) & \psi_3(x_5)
\end{bmatrix} \\
&=\begin{bmatrix}
    \sum_{i=1}^{3}a_i b_1 \psi_i(x_1) & \sum_{i=1}^{3}a_i b_2 \psi_i(x_1) & \sum_{i=1}^{3}a_i b_3 \psi_i(x_1) \\
    \sum_{i=1}^{3}a_i b_1 \psi_i(x_2) & \sum_{i=1}^{3}a_i b_2 \psi_i(x_2) & \sum_{i=1}^{3}a_i b_3 \psi_i(x_2) \\
    \sum_{i=1}^{3}a_i b_1 \psi_i(x_3) & \sum_{i=1}^{3}a_i b_2 \psi_i(x_3) & \sum_{i=1}^{3}a_i b_3 \psi_i(x_3) \\
    \sum_{i=1}^{3}a_i b_1 \psi_i(x_4) & \sum_{i=1}^{3}a_i b_2 \psi_i(x_4) & \sum_{i=1}^{3}a_i b_3 \psi_i(x_4) \\
    \sum_{i=1}^{3}a_i b_1 \psi_i(x_5) & \sum_{i=1}^{3}a_i b_2 \psi_i(x_5) & \sum_{i=1}^{3}a_i b_3 \psi_i(x_5)
\end{bmatrix}\\
&\begin{bmatrix}
    \psi_1(x_1) & \psi_1(x_2) & \psi_1(x_3) & \psi_1(x_4) & \psi_1(x_5) \\
    \psi_2(x_1) & \psi_2(x_2) & \psi_2(x_3) & \psi_2(x_4) & \psi_2(x_5) \\
    \psi_3(x_1) & \psi_3(x_2) & \psi_3(x_3) & \psi_3(x_4) & \psi_3(x_5)
\end{bmatrix}\\
&=
\begin{bmatrix}
\sum_{j=1}^{3} b_j \psi_j(x_1) \sum_{i=1}^{3}a_i \psi_i(x_1) &  \sum_{j=1}^{3} b_j \psi_j(x_2) \sum_{i=1}^{3}a_i \psi_i(x_1) &
\cdots & \sum_{j=1}^{3} b_j \psi_j(x_5) \sum_{i=1}^{3}a_i \psi_i(x_1) \\
\sum_{j=1}^{3} b_j \psi_j(x_1) \sum_{i=1}^{3}a_i \psi_i(x_2) &  \sum_{j=1}^{3} b_j \psi_j(x_2) \sum_{i=1}^{3}a_i \psi_i(x_2) &
\cdots & \sum_{j=1}^{3} b_j \psi_j(x_5) \sum_{i=1}^{3}a_i \psi_i(x_2) \\
\sum_{j=1}^{3} b_j \psi_j(x_1) \sum_{i=1}^{3}a_i \psi_i(x_3) &  \sum_{j=1}^{3} b_j \psi_j(x_2) \sum_{i=1}^{3}a_i \psi_i(x_3) &
\cdots & \sum_{j=1}^{3} b_j \psi_j(x_5) \sum_{i=1}^{3}a_i \psi_i(x_3) \\
\sum_{j=1}^{3} b_j \psi_j(x_1) \sum_{i=1}^{3}a_i \psi_i(x_4) &  \sum_{j=1}^{3} b_j \psi_j(x_2) \sum_{i=1}^{3}a_i \psi_i(x_4) &
\cdots & \sum_{j=1}^{3} b_j \psi_j(x_5) \sum_{i=1}^{3}a_i \psi_i(x_4) \\
\sum_{j=1}^{3} b_j \psi_j(x_1) \sum_{i=1}^{3}a_i \psi_i(x_5) &  \sum_{j=1}^{3} b_j \psi_j(x_2) \sum_{i=1}^{3}a_i \psi_i(x_5) &
\cdots & \sum_{j=1}^{3} b_j \psi_j(x_5) \sum_{i=1}^{3}a_i \psi_i(x_5)
\end{bmatrix}
\end{align*}
\end{example}

\section{EM Test}
\begin{center}
    \includegraphics[scale=0.36]{ch4/forward_backward_v2.png}
\end{center}

\subsection{Initial Guess Test}
\begin{center}
    \includegraphics[scale=0.55]{ch4/initial_guess_test.pdf}
\end{center}

\subsection{Troubleshooting: Double Peak}
\begin{center}
    \includegraphics[scale=0.55]{ch4/double_peak_problem.pdf}
\end{center}
\subsubsection{Step 1: Detect abrupt change}
\begin{itemize}
    \item Use finite difference to get $\frac{d p^{[k]}_{eq}(x)}{dx}$ and $\frac{d^2 p^{[k]}_{eq}(x)}{dx^2}$
    \item If $|\frac{d^2 p_{eq}(x)}{dx^2}|>1$, put the point into the list storing "change points"
    \item If $\text{Number}(\text{Change points}) > 0$, do smoothing. Else: no smooth
\end{itemize}
\begin{center}
    \includegraphics[scale=0.4]{ch4/double_peak_problem_derivative.pdf}
\end{center}
\begin{center}
    \includegraphics[scale=0.5]{ch4/abrupt_detect.pdf}
\end{center}

\subsubsection{Step 2: The cubic smoothing spline}
\begin{definition}[Smoothing Spline]
    Let  $\{x_{i},Y_{i}:i=1,\dots ,n\}$ be a set of observations, modeled by the relation $\{Y_{i}=f(x_{i})+\epsilon _{i}\}$ where the $\epsilon _{i}$ are independen, zero mean random variables (usually assumed to have constant variance). The cubic smoothing spline estimate $\hat{f}$ of the function $f$ is defined to be the minimizer (over the class of twice differentiable functions) of
    \begin{equation}
         \sum _{i=1}^{n}\{Y_{i}-{\hat {f}}(x_{i})\}^{2}+\lambda \int {\hat {f}}''(x)^{2}\,dx
    \end{equation}
    \begin{itemize}
        \item $\lambda \geq 0$ is a smoothing parameter, controlling the trade-off between fidelity to the data and roughness of the function estimate. This is often estimated by generalized cross-validation, or by restricted marginal likelihood (REML) which exploits the link between spline smoothing and Bayesian estimation (the smoothing penalty can be viewed as being induced by a prior on the $f$.
        \item As $ \lambda \to 0$, the smoothing spline converges to the interpolating spline.
        \item As $\lambda \to \infty$(infinite smoothing), the roughness penalty becomes paramount and the estimate converges to a linear least squares estimate.
    \end{itemize}
\end{definition}
\begin{center}
    \includegraphics[scale=0.45]{ch4/double_peak_smooth_afterEM.pdf}
\end{center}

\subsubsection{Result}
\begin{center}
    \includegraphics[scale=0.6]{ch4/aftersmooth_result.pdf}
\end{center}

\section{Optimize diffusion coefficient D}
Here, we use the following simulation data to understand the procedure of updating D.
\begin{center}
    \includegraphics[scale=0.45]{ch4/simu_ref_learn_D.png}
\end{center}
We will fix $p_{eq}^{[k]}$ as the real answer $p_{eq}$, and change $D$ to see the effect to eigenvalues $\lambda_i$ and log-likelihood $l[\theta]$

\subsection{Hamiltonian and its eigenvalues scale linearly with diffusion coefficient}
\begin{align*}
    \frac{\partial \rho(x,t)}{\partial t} &= -\bm{H}^0 \rho(x,t), \\
    \bm{H}^0 &= -D\nabla^2  + V_{\rm eff}(x), \\
    V_{\rm eff}  &= \frac{DF'(x)}{2} + \frac{DF^2(x)}{4}.
\end{align*}
\begin{center}
    \includegraphics[scale=0.45]{ch4/eigenvalue_linear_with_D.pdf}
\end{center}
I only show the first six eigenvalues, all the rest eigenvalues is linear scaling with $D$.

\subsection{Log-likelihood as a function of D}
\begin{center}
    \includegraphics[scale=0.45]{ch4/D_loglikelihood_broad_search_1.pdf}
\end{center}
\begin{center}
    \includegraphics[scale=0.45]{ch4/D_loglikelihood_broad_search_3.pdf}
\end{center}
\begin{center}
    \includegraphics[scale=0.45]{ch4/D_loglikelihood_broad_search_2.pdf}
\end{center}

\section{Complete EM}
\subsection{Initial Guess by Gaussian Kernel Density Estimation}
\begin{center}
    \includegraphics[scale=0.45]{ch4/Gaussian_Kde_harmonic_well.pdf}
\end{center}

\subsection{Algorithm}
\begin{algorithm}[H]
    \SetAlgoLined
    \KwResult{$p^{k}_{\rm eq}$, $D^k$}
     initialize $p^0_{\rm eq}$ as Gaussian KDE \;
     initialize $D^0=\frac{k_B T}{6\pi \eta a}$\;

     \While{$(\ell[\theta^k] - \ell[\theta^{k-1}] > \num{1e-1})$ \& $(k < k_{\text{max}})$}{
       Eigen-decompose the Hermitian $\bm H$ for $\Psi$ and $\Lambda$\;
       Evaluate $\ell [\theta^k] = \sum_{\tau} |\alpha_{\tau}|$ via normalization\;
       Infer the latent states $\langle \alpha(t)|,|\beta(t) \rangle$\;
       Collect statistics of $\mathbb{E}^k_{X|Y}[a_ib_j] = \sum_{\tau}\Gamma^{\tau}_{ij}$\;
       Update $p_{\rm{eq}}^{k+1} = p^k_{\rm{eq}}(x) \sum_{ij} \mathbb{E}^k_{X|Y}[a_ib_j] \phi_i(x)\phi_j(x) $\;
       %
      \If{$k~\%~ 5 == 0$}{
       Detect abrupt change in $p^{k+1}_{\rm eq}$\;
       \If{abrupt change exists}{
           $p^{k+1}_{\rm eq}$ = Smooth($p^{k+1}_{\rm eq}$)
       }
       Line search $D^{k+1} = \argmax_D \ell[p^{k+1}_{\rm eq},D]$\;
       }
       k = k + 1\;
     }
     \caption{Expectation-Maximization Statistical Learning for $F(x)$ and $D$}
\end{algorithm}

\subsection{The data strucutres for storing results}
\begin{align*}
    \mathrm{p\_container} &=
    \begin{bmatrix}
        p^{0}_{\rm eq} \\ p^{1}_{\rm eq} \\ \vdots \\ p^{k}_{\rm eq}
    \end{bmatrix}\\
    \mathrm{D\_records} &=
    \begin{bmatrix}
        D^{0} \\ D^{1} \\ \vdots \\ D^{k}
    \end{bmatrix}\\
    \mathrm{log\_likelihood\_records} &=
    \begin{bmatrix}
        \ell[\theta^{0}] \\ \ell[\theta^{1}] \\ \vdots \\ \ell[\theta^{k}]
    \end{bmatrix}
\end{align*}

\subsection{Results}
\begin{center}
    \includegraphics[scale=0.45]{ch4/em_p0_kde_pref_xavg_50.pdf}
\end{center}

\section{Regularization by using Trajectory Entropy}
The proposed statistical learning problem of Langevin dynamics from smFRET data is naturally underdetermined because we attempt to extract a continuous profile from a finite number of photons. A Bayesian prior is thus required to break the degeneracy in the parameter set. With the prior, the posterior function, $p(\theta | \textbf{y})$, for parameter optimization becomes
\begin{equation}
    p(\theta | \textbf{y}) = \frac{p(\textbf{y}|\theta) p(\theta)}{p(\textbf{y})}
\end{equation}
A criterion for choosing the prior is to guide the optimization toward $F(x)$ profiles that imply the least amount information of dynamics. The goal is to prevent the statistical learning from overfitting and overinterpreting the measured data. As such, we selet the prior based on maximum trajectory entropy. For Langevin dynamics at equilibrium, the trajectory entropy is
\begin{equation}
    \textbf{S}[F(x), D; D] = S_{\rm eq} - t_{\rm obs} \frac{D}{4}\left< F^2(x)\right>
\end{equation}
In Kevin's EM 2013 JPCB paper,
\begin{align}
    D &= 500~~\text{s}^{-1} \\
    \eta_{F} &= 2 \times 10^{-7} \\
    \eta_{F}D &= 0.0001
\end{align}
Therefore, when including the prior for updating $p_{\rm eq}$
\begin{align*}
    p_{\rm eq}^{k+1}(x) &= \left(\mathbb{E}^k_{X|Y} \left[\delta(x-X) \right]\right)^{1/(1+\eta_FD)} \\
    &= \left(\mathbb{E}^k_{X|Y} \left[\delta(x-X) \right]\right)^{1/(1+0.0001)} \\
    &= \left(\mathbb{E}^k_{X|Y} \left[\delta(x-X) \right]\right)^{1/(1.0001)}
\end{align*}
I think the regularization has no real effect.

\section{Double Well}
\subsection{Case 1: 10000 photons}
$\Delta t = 10^{-9}~\text{s}$
\begin{center}
    \includegraphics[scale=0.45]{ch4/simu_doublewell_10000photons.png}
\end{center}
\begin{center}
    \includegraphics[scale=0.45]{ch4/em_p0_kde_pref_doublewell_10000photons.pdf}
\end{center}

\subsection{Case 2: 20000 photons}
$\Delta t = 10^{-9}~\text{s}$
\begin{center}
    \includegraphics[scale=0.45]{ch4/simu_doublewell_20000photons.png}
\end{center}
\begin{center}
    \includegraphics[scale=0.45]{ch4/em_p0_kde_pref_doublewell_20000photons.pdf}
\end{center}

\subsection{Gaussian mixture model}
\begin{center}
    \includegraphics[scale=0.45]{ch4/gmm_doublewell_1.png}
\end{center}
\begin{center}
    \includegraphics[scale=0.45]{ch4/em_p0_kde_pref_gmm_doublewell_1.pdf}
\end{center}

\section{Triple Well}
\subsection{Gaussian mixture model: 10000 photons}
\begin{center}
    \includegraphics[scale=0.45]{ch4/gmm_triplewell_1.png}
\end{center}
\begin{center}
    \includegraphics[scale=0.45]{ch4/em_p0_kde_pref_gmm_triplewell_1.pdf}
\end{center}

\subsection{Gaussian mixture model: 50000 photons}
\begin{center}
    \includegraphics[scale=0.45]{ch4/gmm_triplewell_2.png}
\end{center}
\begin{center}
    \includegraphics[scale=0.45]{ch4/em_p0_kde_pref_gmm_triplewell_2.pdf}
\end{center}


\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{Sweave}
\begin{document}
\input{hw3_saket-concordance}

%\SweaveOpts{concordance=TRUE}
\title{HW\#3 ||  MDS  Eigen Decomposition using pairwise distances of US cities}
\author{Saket Choudhary}
\maketitle

\begin{Schunk}
\begin{Sinput}
> library(graphics)
> library(ggplot2)
\end{Sinput}
\end{Schunk}

\textbf{Read Data:}
\begin{Schunk}
\begin{Sinput}
> distanceMatrix <- read.csv("distance_matrix.csv", header=T)
> distanceMatrix
\end{Sinput}
\begin{Soutput}
  BOST   NY   DC MIAM CHIC SEAT   SE   LA DENV
1    0  206  429 1504  963 2976 3095 2979 1949
2  206    0  233 1308  802 2815 2934 2786 1771
3  429  233    0 1075  671 2684 2799 2631 1616
4 1504 1308 1075    0 1329 3273 3053 2687 2037
5  963  802  671 1329    0 2013 2142 2054  996
6 2976 2815 2684 3273 2013    0  808 1131 1307
7 3096 2934 2799 3053 2142  808    0  379 1235
8 2979 2786 2631 1687 2054 1131  379    0 1059
9 1949 1771 1616 2037  996 1307 1235 1059    0
\end{Soutput}
\end{Schunk}

\section{MDS}
\begin{figure}

\begin{Schunk}
\begin{Sinput}
> mds <- cmdscale(distanceMatrix)
> mdsPlot  <- qplot(x=mds[,1],
+                   y=-mds[,2],
+                   label=colnames(distanceMatrix))
> mdsPlot +
+   geom_point(color='red') +
+   geom_text(hjust=-.15) +
+   xlab("X1") + ylab("X2") +
+   ggtitle("MDS plot using 2 dimensions")
\end{Sinput}
\end{Schunk}
\includegraphics{hw3_saket-003}
\caption{MDS plot(2D)}
\end{figure}

Coordinates of points are given by:
\begin{Schunk}
\begin{Sinput}
> rownames(mds) <- colnames(distanceMatrix)
> colnames(mds) <- c("X1", "X2")
> print(mds)
\end{Sinput}
\begin{Soutput}
             X1          X2
BOST -1388.4759   401.09561
NY   -1235.5455   281.49474
DC   -1110.4073   156.62867
MIAM -1108.0546 -1273.17629
CHIC  -435.5452   288.46936
SEAT  1601.4477   651.49498
SE    1708.7378    76.02141
LA    1335.1428 -1065.44210
DENV   546.1006    78.38664
\end{Soutput}
\end{Schunk}
%\end{figure}

\section{EigenValue Decomoposition}
\subsection{Using similarity matrix}

\begin{Schunk}
\begin{Sinput}
> similarityMatrix <- apply(distanceMatrix, 1, function(x) exp(-x^2/3000.0^2))
> similarityMatrix
\end{Sinput}
\begin{Soutput}
          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
BOST 1.0000000 0.9952960 0.9797587 0.7777617 0.9020900 0.3737889 0.3447196
NY   0.9952960 1.0000000 0.9939860 0.8268797 0.9310269 0.4145882 0.3842415
DC   0.9797587 0.9939860 1.0000000 0.8794991 0.9512040 0.4491365 0.4187467
MIAM 0.7777617 0.8268797 0.8794991 1.0000000 0.8218076 0.3041358 0.3549972
CHIC 0.9020900 0.9310269 0.9512040 0.8218076 1.0000000 0.6374745 0.6006181
SEAT 0.3737889 0.4145882 0.4491365 0.3041358 0.6374745 1.0000000 0.9300281
SE   0.3449568 0.3842415 0.4187467 0.3549972 0.6006181 0.9300281 1.0000000
LA   0.3730477 0.4221385 0.4634165 0.4483331 0.6257725 0.8675093 0.9841666
DENV 0.6556903 0.7057505 0.7481425 0.6306268 0.8956335 0.8271200 0.8441125
          [,8]      [,9]
BOST 0.3730477 0.6556903
NY   0.4221385 0.7057505
DC   0.4634165 0.7481425
MIAM 0.7289000 0.6306268
CHIC 0.6257725 0.8956335
SEAT 0.8675093 0.8271200
SE   0.9841666 0.8441125
LA   1.0000000 0.8828420
DENV 0.8828420 1.0000000
\end{Soutput}
\end{Schunk}

Perform PCA an similarityMatrix:
\begin{figure}
\begin{Schunk}
\begin{Sinput}
> similarityMatrix.prcomp <- prcomp(similarityMatrix, scale.=T)
> similarityMatrix.PCA <- similarityMatrix.prcomp$x[,1:2]
> similarityMatrix.plot <- qplot(x=similarityMatrix.PCA[,1],
+                           y=similarityMatrix.PCA[,2],
+                           label=colnames(distanceMatrix))
> similarityMatrix.plot +
+   geom_point(color='red') +
+   geom_text(hjust=-.15) +
+   xlab("PC1") + ylab("PC2")+
+   ggtitle("First 2 principle components of similarity Matrix")
\end{Sinput}
\end{Schunk}
\includegraphics{hw3_saket-006}
\caption{PCA using gaussian kernel(using similarity matrix)}
\end{figure}

\subsubsection{EigenValues}

\begin{Schunk}
\begin{Sinput}
> print(similarityMatrix.prcomp$sdev)
\end{Sinput}
\begin{Soutput}
[1] 2.763748e+00 1.011925e+00 5.609621e-01 1.317532e-01 6.715841e-02
[6] 3.342472e-02 6.485914e-03 1.019860e-03 1.743940e-16
\end{Soutput}
\end{Schunk}

\subsubsection{EigenVectors}
\begin{Schunk}
\begin{Sinput}
> print(similarityMatrix.prcomp$rotation[,1:2])
\end{Sinput}
\begin{Soutput}
             PC1         PC2
 [1,] -0.3552454 -0.15532942
 [2,] -0.3556963 -0.17183709
 [3,] -0.3555762 -0.18252044
 [4,] -0.3372374 -0.03256753
 [5,] -0.3160704 -0.47693301
 [6,]  0.3425956 -0.25501975
 [7,]  0.3540793 -0.19295181
 [8,]  0.3348572 -0.03848530
 [9,]  0.2287874 -0.76207529
\end{Soutput}
\end{Schunk}

\subsubsection{Principle  Components(Scaled and Centered)}
\begin{Schunk}
\begin{Sinput}
> print(similarityMatrix.prcomp$x[,1:2])
\end{Sinput}
\begin{Soutput}
           PC1        PC2
BOST -2.763048  0.6631076
NY   -2.646744  0.1721873
DC   -2.517306 -0.2152715
MIAM -1.894466  1.3418267
CHIC -1.324643 -1.4856597
SEAT  3.240198  0.4969233
SE    3.553513  0.5559057
LA    3.222135  0.2212970
DENV  1.130362 -1.7503165
\end{Soutput}
\end{Schunk}

\subsection{Using distance matrix}

Perform PCA an distanceMatrix:
\begin{figure}
\begin{Schunk}
\begin{Sinput}
> distanceMatrix
\end{Sinput}
\begin{Soutput}
  BOST   NY   DC MIAM CHIC SEAT   SE   LA DENV
1    0  206  429 1504  963 2976 3095 2979 1949
2  206    0  233 1308  802 2815 2934 2786 1771
3  429  233    0 1075  671 2684 2799 2631 1616
4 1504 1308 1075    0 1329 3273 3053 2687 2037
5  963  802  671 1329    0 2013 2142 2054  996
6 2976 2815 2684 3273 2013    0  808 1131 1307
7 3096 2934 2799 3053 2142  808    0  379 1235
8 2979 2786 2631 1687 2054 1131  379    0 1059
9 1949 1771 1616 2037  996 1307 1235 1059    0
\end{Soutput}
\begin{Sinput}
> distanceMatrix.prcomp <- prcomp(distanceMatrix, scale.=T)
> distanceMatrix.PCA <- distanceMatrix.prcomp$x[,1:2]
> distanceMatrix.plot <- qplot(x=distanceMatrix.PCA[,1],
+                           y=distanceMatrix.PCA[,2],
+                           label=colnames(distanceMatrix))
> distanceMatrix.plot +
+   geom_point(color='red') +
+   geom_text(hjust=-.15) +
+   xlab("PC1") + ylab("PC2") +
+   ggtitle("First 2 principle components of distanceMatrix")
\end{Sinput}
\end{Schunk}
\includegraphics{hw3_saket-010}
\caption{PCA without using gaussian kernel(using distance matrix)}
\end{figure}

\subsubsection{EigenValues}

\begin{Schunk}
\begin{Sinput}
> print(distanceMatrix.prcomp$sdev)
\end{Sinput}
\begin{Soutput}
[1] 2.666684e+00 1.049368e+00 7.363066e-01 3.395746e-01 2.999203e-01
[6] 1.640774e-01 1.070771e-01 4.272792e-02 1.600394e-17
\end{Soutput}
\end{Schunk}

\subsubsection{EigenVectors}
\begin{Schunk}
\begin{Sinput}
> print(distanceMatrix.prcomp$rotation[,1:2])
\end{Sinput}
\begin{Soutput}
            PC1         PC2
BOST  0.3609929  0.13053243
NY    0.3632938  0.14972372
DC    0.3651761  0.17155008
MIAM  0.2962816 -0.13553983
CHIC  0.2957988  0.54249894
SEAT -0.3516124  0.16804789
SE   -0.3676068  0.08877045
LA   -0.3577376  0.10405688
DENV -0.2057333  0.75596984
\end{Soutput}
\end{Schunk}

\subsubsection{Principle  Components(Scaled and Centered)}

\begin{Schunk}
\begin{Sinput}
> print(distanceMatrix.prcomp$x[,1:2])
\end{Sinput}
\begin{Soutput}
            PC1         PC2
 [1,] -2.594727  0.49402847
 [2,] -2.566601  0.09812092
 [3,] -2.448209 -0.18194241
 [4,] -1.927579  1.48379129
 [5,] -1.307785 -1.43547852
 [6,]  3.143991  0.46313051
 [7,]  3.491687  0.53895796
 [8,]  2.883923  0.42915851
 [9,]  1.325301 -1.88976673
\end{Soutput}
\end{Schunk}

\section{Discussion}

As evident from Figure 1 and Figure 2, transforming original data from pairwise distances to pairwise similairties using gaussian kernel does not seem to have effect on the resulting PCA plots. The most probable reasoning is because the data is linearly separable in its original 9 dimensions. With the gaussian kernel trick each row being a 9-D vector is transformed to a infinite-dimensional space(a function for example satisfies all operations that a vector satisfies: addition/multiplication in 'higher' dimensions and with a gaussian kernel with fixed $\sigma^2$ each original vector is sent to a 'higher' dimensional gaussian blob centered at that point. If any two points in original 9-D space were close, their guassian transformation would lead to the resulting vectors having small angle in the 'higher' dimensional space), assuming that higher dimensions would guarantee linear separation. But in this case, linear separation is guaranteed in the original 9-dimensions itself.

\subsection{Equivalence of MDS and PCA?}
MDS and PCA are expected to have same results when eucliden distances are used.
[Cox, Trevor F., and Michael AA Cox. Multidimensional scaling. CRC Press, 2000.]

\end{document}


% !TeX spellcheck = en_US
% !TeX root = DynELA.tex
%
% LaTeX source file of DynELA FEM Code
%
% (c) by Olivier Pantalé 2020
%
\chapter{DynELA impact sample cases}

\startcontents[chapters]
\printmyminitoc[1]\LETTRINE{T}his chapter deals with some numerical applications of
the \DynELA~for impact applications in 2D, axi-symmetric and 3D
cases. In the subsequent tests, if not specified, a Johnson-Cook constitutive
law is used to model the behavior of the material. The Johnson-Cook
hardening flow law is probably the most widely used flow law for the
simulation of high strain rate deformation processes taking into account
plastic strain, plastic strain rate and temperature effects. Since
a lot of efforts have been made in the past to identify the constitutive
flow law parameters for many materials, it is implemented in numerous
Finite Element codes such as Abaqus \cite{abaqus20146}. The general
formulation of the Johnson-Cook law $\sigma^{y}(\overline{\varepsilon}^{p},\stackrel{\bullet}{\overline{\varepsilon}^{p}},T)$
is given by the following equation:

\begin{equation}
\sigma^{y}=\left(A+B\overline{\varepsilon}^{p^{n}}\right)\left[1+C\ln\left(\frac{\stackrel{\bullet}{\overline{\varepsilon}^{p}}}{\stackrel{\bullet}{\overline{\varepsilon}_{0}}}\right)\right]\left[1-\left(\frac{T-T_{0}}{T_{m}-T_{0}}\right)^{m}\right]\label{eq:Samples!Johnson-Cook}
\end{equation}
where $\stackrel{\bullet}{\overline{\varepsilon}_{0}}$ is the reference
strain rate, $T_{0}$ and $T_{m}$ are the reference temperature and
the melting temperature of the material respectively and $A$, $B$,
$C$, $n$ and $m$ are the five constitutive flow law parameters.
A 42CrMo4 steel following the Johnson-Cook behavior law has been selected
for all those tests, and material properties are reported in Table
\ref{tab:Samples!JohnsonCookParameters}.

\begin{table}[h]
\begin{center}\begin{tcolorbox}[width=.75\textwidth,myTab,tabularx={C|C|C|C|C|C|C}]
$E$ & $\nu$ & $A$ & $B$ & $C$ & $n$ & $m$ \\
\small{($Gpa$)} &  & \small{($MPa$)} & \small{($MPa$)} &  &  & \\ \hline
$206.9$ & $0.3$ & $806$ & $614$ & $0.0089$ & $0.168$ & $1.1$ \\ \hline\hline
$\rho$ & $\lambda$ & $C_{p}$ & $\eta$ & $\stackrel{\bullet}{\overline{\varepsilon}_{0}}$ & $T_{0}$ & $T_{m}$ \\
\small{$(kg/m^{3})$} & \small{$(W/m^{\circ}C)$} & \small{$(J/Kg^{\circ}C)$} & & \small{$(s^{-1})$} & \small{$(^{\circ}C)$} & \small{$(^{\circ}C)$} \\ \hline
$7830$ & $34.0$ & $460$ & $0.9$ & $1.0$ & $20$ & $1540$
\end{tcolorbox}\end{center}\caption{Material parameters of the Johnson-Cook behavior for the numerical
tests\label{tab:Samples!JohnsonCookParameters}}
\end{table}

\section{Taylor impact sample}

\subsection{Axisymmetric Taylor impact}

The performance of the proposed code is validated under high deformation
rate with the simulation of the Taylor impact test \cite{taylor_1946}.
In the Taylor impact test, a cylindrical specimen is launched to impact
a rigid target with a prescribed initial velocity. The numerical model,
reported in Figure \ref{fig:Samples!Impact!TaylorAxi} is established
as axisymmetric. The height is $32.4\,mm$ and the radius is $3.2\,mm$.
The axial displacement is restrained on the right side of the specimen
while the radial displacement is free (to figure a perfect contact
without friction of the projectile onto the target). A predefined
velocity of $V_{c}=287\,m/s$ is imposed on the specimen. The mesh
consists of $250$ elements ($5\times50$ elements). The total simulation
time for the Taylor impact test is $t=8.0\,10^{-5}s$.

\begin{figure}[h]
\begin{centering}
\includegraphics[width=0.75\columnwidth]{Figures/TaylorAxi}
\par\end{centering}
\caption{Numerical model for the Axisymmetric Taylor impact test\label{fig:Samples!Impact!TaylorAxi}}
\end{figure}

Figure \ref{fig:Samples!Impact!TaylorAxi-temp-contour} shows the
temperature contourplot of the deformed rod for both the \DynELA~and
Abaqus. The distributions of the temperatures are almost the same
for both models. The maximum temperature $T$ is located into the
center element of the model (the red element in Figure \ref{fig:Samples!Impact!TaylorAxi})
and the models give quite the same results as reported in Table \ref{tab:Samples!Impact!TaylorAxi-comparison}
for $\overline{\varepsilon}^{p}$, $T$ and the final dimensions of
the specimen $L_{f}$ (final length) and $D_{f}$ (final diameter
of the impacting face).

Figure \ref{fig:Samples!Impact!TaylorAxi-comparison} shows the evolution
of the the final dimensions of the specimen $L_{f}$ (final length)
and $R_{f}$ (final radius of the impacting face), the equivalent
plastic strain $\overline{\varepsilon}^{p}$, the temperature $T$,
the von Mises stress $\overline{\sigma}$ and the timeStep $\Delta t$
for the different models for the element at the center of the impacting
face (the red element in Figure \ref{fig:Samples!Impact!TaylorAxi}).

As reported in this figure and according to the results presented
in Table \ref{tab:Samples!Impact!TaylorAxi-comparison}, a quite good
agreement between the results is obtained.

\begin{figure}[h]
\begin{centering}
\includegraphics[height=0.5\columnwidth]{Figures/Samples/Impact/Taylor-Axi_temperatureCP}\hspace*{3cm}\includegraphics[height=0.5\columnwidth]{Figures/Samples/Impact/Taylor-Axi-Abaqus_Temperature}
\par\end{centering}
\caption{Temperature contourplots for Axisymmetric Taylor impact test (DynELA
left and Abaqus right)\label{fig:Samples!Impact!TaylorAxi-temp-contour}}
\end{figure}

\begin{table}[h]
\begin{center}\begin{tcolorbox}[width=.75\textwidth,myTab,tabularx={C|C|C|C|C}]
code & $L_f$ & $D_f$ & $T$ & $\overline{\varepsilon}^{p}$ \\
 & \small{($mm$)} & \small{($mm$)} & \small{($^{\circ}C$)} & \\ \hline\hline
DynELA & $26.52$ & $11.15$ & $582.34$ & $1.78$ \\ \hline
Abaqus & $26.56$ & $11.16$ & $590.96$ & $1.81$
\end{tcolorbox}\end{center}\caption{Comparison of numerical results for the Axisymmetric Taylor impact
test\label{tab:Samples!Impact!TaylorAxi-comparison}}
\end{table}

\begin{figure}[h]
\begin{centering}
\begin{tabular}{cc}
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-Axi_radius} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-Axi_height}\tabularnewline
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-Axi_temperature} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-Axi_plasticStrain}\tabularnewline
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-Axi_vonMises} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-Axi_timeStep}\tabularnewline
\end{tabular}
\par\end{centering}
\caption{Comparison of numerical and analytical results for the Axisymmetric
Taylor impact test\label{fig:Samples!Impact!TaylorAxi-comparison}}
\end{figure}

\subsection{3D Taylor impact}

The performance of the proposed code is validated under high deformation
rate with the simulation of the Taylor impact test \cite{taylor_1946}.
In the Taylor impact test, a cylindrical specimen is launched to impact
a rigid target with a prescribed initial velocity. The numerical model,
reported in Figure \ref{fig:Samples!Impact!Taylor3D} is established
as axisymmetric. The height is $32.4\,mm$ and the radius is $3.2\,mm$.
The axial displacement is restrained on the right side of the specimen
while the radial displacement is free (to figure a perfect contact
without friction of the projectile onto the target). A predefined
velocity of $V_{c}=287\,m/s$ is imposed on the specimen. The mesh
consists of $4455$ elements ($55\times81$ elements). The total simulation
time for the Taylor impact test is $t=8.0\,10^{-5}s$.

\begin{figure}[h]
\begin{centering}
\includegraphics[width=0.5\columnwidth]{Figures/Samples/Impact/Taylor-3D_mesh}
\par\end{centering}
\caption{Numerical model for the 3D Taylor impact test\label{fig:Samples!Impact!Taylor3D}}
\end{figure}

Figure \ref{fig:Samples!Impact!Taylor3D-temp-contour} shows the temperature
contourplot of the deformed rod for both the \DynELA~and Abaqus.
The distributions of the temperatures are almost the same for both
models. The maximum temperature $T$ is located into the center element
of the model (the red element in Figure \ref{fig:Samples!Impact!Taylor3D})
and the models give quite the same results as reported in Table \ref{tab:Samples!Impact!Taylor3D-comparison}
for $\overline{\varepsilon}^{p}$, $T$ and the final dimensions of
the specimen $L_{f}$ (final length) and $D_{f}$ (final diameter
of the impacting face).

Figure \ref{fig:Samples!Impact!Taylor3D-comparison} shows the evolution
of the the final dimensions of the specimen $L_{f}$ (final length)
and $R_{f}$ (final radius of the impacting face), the equivalent
plastic strain $\overline{\varepsilon}^{p}$, the temperature $T$,
the von Mises stress $\overline{\sigma}$ and the timeStep $\Delta t$
for the different models for the element at the center of the impacting
face (the red element in Figure \ref{fig:Samples!Impact!Taylor3D}).

As reported in this figure and according to the results presented
in Table \ref{tab:Samples!Impact!Taylor3D-comparison}, a quite good
agreement between the results is obtained.

\begin{figure}[h]
\begin{centering}
\includegraphics[width=0.8\columnwidth]{Figures/Samples/Impact/Taylor-3D_temperatureCP}
\par\end{centering}
\caption{Temperature contourplot for the 3D Taylor impact test\label{fig:Samples!Impact!Taylor3D-temp-contour}}
\end{figure}

\begin{table}[h]
\begin{center}\begin{tcolorbox}[width=.75\textwidth,myTab,tabularx={C|C|C|C|C}]
code & $L_f$ & $D_f$ & $T$ & $\overline{\varepsilon}^{p}$ \\
 & \small{($mm$)} & \small{($mm$)} & \small{($^{\circ}C$)} & \\ \hline\hline
DynELA & $26.52$ & $11.18$ & $597.10$ & $1.84$ \\ \hline
Abaqus & $26.55$ & $11.22$ & $597.01$ & $1.84$
\end{tcolorbox}\end{center}\caption{Comparison of numerical results for the 3D Taylor impact test\label{tab:Samples!Impact!Taylor3D-comparison}}
\end{table}

\begin{figure}[h]
\begin{centering}
\begin{tabular}{cc}
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-3D_radius} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-3D_height}\tabularnewline
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-3D_temperature} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-3D_plasticStrain}\tabularnewline
\includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-3D_vonMises} & \includegraphics[width=0.45\columnwidth]{Figures/Samples/Impact/Taylor-3D_timeStep}\tabularnewline
\end{tabular}
\par\end{centering}
\caption{Comparison of numerical and analytical results for the 3D Taylor impact
test\label{fig:Samples!Impact!Taylor3D-comparison}}
\end{figure}


\documentclass[Main.tex]{subfiles}

\begin{document}

\chapter{1}{Introduction and time-domain signal representation}

\section{Signals}
\subsection{Definitions}
\begin{definitions}
\begin{itemize}
    \item Signal: Function of an independent variable, usually time $t$.
    \begin{itemize}
        \item This course will only be about 1D signals, e.g.\ $f(t) = A \cos(\omega t + \theta )$, $t \in \R$.
        \item 2D signals are things like black and white images, i.e.\ $f(x,y)=$ intensity of pixel at $(x, y)$.
    \end{itemize}
    \item Continuous \textbf{Time} Signals: A signal that has a domain $t \in \R$, e.g.\ $f(t)= e^{-t}, t \leq 0$.
    \item Discrete \textbf{Time} Signals: A signal that has a domain $t \in \Z$.
    \item Digital Signals: A discrete signal that has been quantized further in $f(t)$.
    \item Periodic Signals: A signal is periodic when $f(t) \equiv f(t+T)$, where T is as small as possible to satisfy the equation.
    \item Causal Signals:
    \begin{itemize}
        \item Causal: $f(t) = 0, \forall t < 0$
        \item Anticausal: $f(t) = 0, \forall t \geq 0$
        \item Otherwise, noncausal.
    \end{itemize}
\end{itemize}
\end{definitions}
\subsection{Even and Odd signals}
\begin{itemize}
    \item Even: $f(t) = f(-t)$
    \item Odd: $f(t) = -f(t)$
\end{itemize}

\end{document}


\section{Discontinuous Galerkin Scheme}
\label{sec:dgMethod}

We assume a spacetime metric
\begin{equation}
  ds^{2}=-\alpha^{2}\,dt^{2}+\gamma_{ij}\,dx^{i}\,dx^{j},
\end{equation}
and consider the system of conservation laws with sources
\begin{equation}
  \pd{}{t}\big(\sqrt{\gamma}\,\bU\big)+\sum_{i=1}^{d}\pd{}{i}\big(\alpha\,\sqrt{\gamma}\,\bF^{i}(\bU)\big)=\alpha\,\sqrt{\gamma}\,\bG(\bU),
  \label{eq:conservationLaws}
\end{equation}
where
\begin{align}
  \bU
  &=\big(D,\,S_{j},\,\tau\big)^{\mbox{\tiny T}}
  =\big(\rho\,W,\,\rho\,h\,W^{2}\,v_{j},\,\rho\,W\left(h\,W-1\right)-p\big)^{\mbox{\tiny T}}, \\
  \bF^{i}(\bU)
  &=\big(D\,v^{i},\,\big)^{\mbox{\tiny T}}
\end{align}


\section{Model Description}

	\subsection{Derivation of Equations of Motion - Newtonian Mechanics}

\begin{figure}[H]
	\centering
	\includegraphics[]{Figures/Flex_Slosh_Figure}
	\caption{Frame and variable definitions used for formulation}
	\label{fig:Flex_Slosh_Figure}
\end{figure}

\subsubsection{Rigid Spacecraft Hub Translational Motion}

Following a similar derivation as in previous work \cite{Allard2016rz}, the derivation begins with Newton's second law for the center of mass of the spacecraft.
\begin{equation}
	\ddot{\bm r}_{C/N} = \frac{\bm{F}}{m_{\text{\text{sc}}}}
	\label{eq:Newtons1Law}
\end{equation}
Ultimately the acceleration of the body frame or point $B$ is desired
\begin{equation}
	\ddot{\bm r}_{B/N} = \ddot{\bm r}_{C/N}-\ddot{\bm c}
	\label{eq:RcRbacc}
\end{equation}
The definition of $\bm{c}$ can be seen in Eq. (\ref{eq:c}).
\begin{equation}
	\bm{c} = \frac{1}{m_{\text{sc}}}\Big(m_{\text{\text{hub}}}\bm{r}_{B_{c}/B} + \sum_{j=1}^{N_{P}}m_j\bm{r}_{P_{c,j}/B}\Big)
	\label{eq:c}
\end{equation}
To find the inertial time derivative of $\bm{c}$, it is first necessary to find the time derivative of $\bm{c}$ with respect to the body frame. A time derivative of any vector, $\bm{v}$, with respect to the body frame is denoted by $\bm{v}'$; the inertial time derivative is labeled as $\dot{\bm{v}}$. The first and second body-relative time derivatives of $\bm{c}$ can be seen in Eqs. (\ref{eq:cprime}) and (\ref{eq:cdprime}).

$\bm{r}_{P_{c,j}/B}$ is defined in the following
\begin{equation}
	\bm{r}_{P_{c,j}/B} = \bm{r}_{P_{j}/B} + \rho_j \hat{\bm p}_j
\end{equation}
And, the first and second body time derivatives of $\bm{r}_{P_{c,j}/B}$ are
\begin{align}
	\bm{r}'_{P_{c,j}/B} &= \dot{\rho}_j \hat{\bm p}_j
	\\
	\bm{r}''_{P_{c,j}/B} &= \ddot{\rho}_j \hat{\bm p}_j
\end{align}
$\bm{c}'$ and $\bm{c}''$ are defined in the following equations
\begin{equation}
	\bm{c}' = \frac{1}{m_{\text{sc}}}\sum_{j=1}^{N_{P}}m_j\dot{\rho}_j \hat{\bm p}_j
	\label{eq:cprime}
\end{equation}
\begin{equation}
	\bm{c}'' = \frac{1}{m_{\text{sc}}}\sum_{j=1}^{N_{P}}m_j\ddot{\rho}_j \hat{\bm p}_j
	\label{eq:cdprime}
\end{equation}
Using the transport theorem\cite{schaub} yields the following definition for $\ddot{\bm c}$
\begin{equation}
	\ddot{\bm c} = \bm{c}'' + 2\bm\omega_{\cal B/N}\times\bm{c}'+\dot{\bm\omega}_{\cal B/N}\times\bm{c}+\bm\omega_{\cal B/N}\times\left(\bm\omega_{\cal B/N}\times\bm{c}\right)
	\label{eq:cddot}
\end{equation}
Eq.~\eqref{eq:RcRbacc} is updated to include Eq.~\eqref{eq:cddot}
\begin{equation}
	\ddot{\bm r}_{B/N} = \ddot{\bm r}_{C/N}-\bm{c}'' - 2\bm\omega_{\cal B/N}\times\bm{c}'-\dot{\bm\omega}_{\cal B/N}\times\bm{c}-\bm\omega_{\cal B/N}\times\left(\bm\omega_{\cal B/N}\times\bm{c}\right)
	\label{eq:Rbddot}
\end{equation}
Substituting Eq.\eqref{eq:cdprime} into Eq.\eqref{eq:Rbddot} results in
\begin{equation}
	\ddot{\bm r}_{B/N} = \ddot{\bm r}_{C/N}-\frac{1}{m_{\text{sc}}}\sum_{j=1}^{N_{P}}m_j\ddot{\rho}_j \hat{\bm p}_j =
	- 2\bm\omega_{\cal B/N}\times\bm c'
	-\dot{\bm\omega}_{\cal B/N}\times\bm{c}-\bm\omega_{\cal B/N}\times\left(\bm\omega_{\cal B/N}\times\bm{c}\right)
	\label{eq:Rbddot2}
\end{equation}
Moving second order terms to the left hand side and introducing the tilde matrix\cite{schaub} to replace the cross product operators simplifies the equation to
\begin{equation}
	m_{\text{sc}} \ddot{\bm r}_{B/N}-m_{\text{sc}} [\tilde{\bm{c}}] \dot{\bm\omega}_{\cal B/N} +\sum_{j=1}^{N_{P}}m_j \hat{\bm p}_j \ddot{\rho}_j = \bm F_{\text{ext}}	- 2 m_{\text{sc}} [\tilde{\bm\omega}_{\cal B/N}] \bm c'
	- m_{\text{sc}} [\tilde{\bm\omega}_{\cal B/N}][\tilde{\bm\omega}_{\cal B/N}]\bm{c}
	\label{eq:Rbddot3}
\end{equation}

Equation~\eqref{eq:Rbddot3} is the translational motion equation and is the first EOM needed to describe the motion of the spacecraft. The following section develops the rotational EOM.

\subsubsection{Rigid Spacecraft Hub Rotational Motion}

Starting with Euler's equation when the body fixed coordinate frame origin is not coincident with the center of mass of the body\cite{schaub}
\begin{equation}
	\bm{\dot{H}}_{\text{sc},B} = \bm{L}_B+m_{\text{\text{sc}}}\ddot{\bm r}_{B/N}\times\bm{c}
	\label{eq:Euler}
\end{equation}
where $\bm{L}_B$ is the total external torque about point $B$. The definition of the angular momentum vector of the spacecraft about point $B$ is
\begin{equation}
	\bm{H}_{\text{sc},B} = [I_{\text{hub},B_c}] \bm\omega_{\cal B/N} + m_{\text{\text{hub}}}\bm{r}_{B_{c}/B} \times \dot{\bm{r}}_{B_{c}/B} + \sum\limits_{j=1}^{N_P}m_j \bm r_{P_{c,j}/B}\times \dot{\bm r}_{P_{c,j}/B}
	\label{eq:Hb2}
\end{equation}

Now the inertial time derivative of Eq. \eqref{eq:Hb2} is taken and yields
\begin{equation}
	\dot{\bm{H}}_{\text{sc},B} = [I_{\text{hub},B_c}] \dot{\bm\omega}_{\cal B/N} + \bm\omega_{\cal B/N} \times [I_{\text{hub},B_c}] \bm\omega_{\cal B/N} + m_{\text{\text{hub}}}\bm{r}_{B_{c}/B} \times \ddot{\bm{r}}_{B_{c}/B} +  \sum\limits_{j=1}^{N_P}m_j \bm r_{P_{c,j}/B}\times \ddot{\bm r}_{P_{c,j}/B}
	\label{eq:Hbdot}
\end{equation}
$\ddot{\bm r}_{P_{c,j}/B}$ is
\begin{align}
	\ddot{\bm{r}}_{P_{c,j}/B}  &= \bm{r}''_{P_{c,j}/B} +2 \bm\omega_{\cal B/N} \times \bm{r}'_{P_{c,j}/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{P_{c,j}/B}  +\bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{P_{c,j}/B})
	\label{eq:rpddot}
\end{align}
Incorporating Eq.-~\eqref{eq:rpddot} into Eq.~\eqref{eq:Hbdot} results in
\begin{multline}
	\dot{\bm{H}}_{\text{sc},B} = [I_{\text{hub},B_c}] \dot{\bm\omega}_{\cal B/N} + \bm\omega_{\cal B/N} \times [I_{\text{hub},B_c}] \bm\omega_{\cal B/N} + m_{\text{\text{hub}}}\bm{r}_{B_{c}/B} \times \ddot{\bm{r}}_{B_{c}/B}\\ + \sum\limits_{j=1}^{N_P}m_j \bm r_{P_{c,j}/B}\times \Bigl[\bm{r}''_{P_{c,j}/B} +2 \bm\omega_{\cal B/N} \times \bm{r}'_{P_{c,j}/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{P_{c,j}/B} +\bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{P_{c,j}/B})\Bigr]
	\label{eq:Hbdot2}
\end{multline}
Applying the parallel axis theorem the following inertia tensor terms are defined as
\begin{align}
	[I_{\text{sc},B}] &= [I_{\text{hub},B}] + m_{\text{hub}} [\tilde{\bm{r}}_{B_{c}/B}] [\tilde{\bm{r}}_{B_{c}/B}]^T + \sum\limits_{j=1}^{N_P} m_j [\tilde{\bm{r}}_{P_{c,j}/B}] [\tilde{\bm{r}}_{P_{c,j}/B}]^T
	\label{eq:IscB}
\end{align}
Taking the body-relative time derivative of Equation~\eqref{eq:IscB} yields
\begin{equation}
	[I'_{\text{sc},B}] =
	- \sum\limits_{j=1}^{N_P} m_j \Bigl(  [\tilde{\bm{r}}'_{P_{c,j}/B}] [\tilde{\bm{r}}_{P_{c,j}/B}] + [\tilde{\bm{r}}_{P_{c,j}/B}] [\tilde{\bm{r}}'_{P_{c,j}/B}]  \Bigr)
\end{equation}
The Jacobi Identity, $(\bm a \times \bm b)\times \bm c = \bm a \times (\bm b\times \bm c) - \bm b \times (\bm a\times \bm c)$, is used to combine terms and produce the following simplified equation
\begin{multline}
	\dot{\bm{H}}_{\text{sc},B} = [I_{\text{sc},B}] \dot{\bm\omega}_{\cal B/N} + \bm\omega_{\cal B/N} \times [I_{\text{sc},B}] \bm\omega_{\cal B/N} + [I'_{\text{sc},B}] \bm\omega_{\cal B/N}
	\\+ \sum\limits_{j=1}^{N_P}\biggl[m_j \bm r_{P_{c,j}/B}\times\bm{r}''_{P_{c,j}/B}
	+ m_j \bm\omega_{\cal B/N} \times \Bigl(\bm{r}_{P_{c,j}/B} \times \bm{r}'_{P_{c,j}/B}\Bigr)\biggr]
	\label{eq:Hbdot4}
\end{multline}

Eqs. (\ref{eq:Euler}) and (\ref{eq:Hbdot4}) are equated and yield
\begin{multline}
	\bm{L}_B+m_{\text{sc}}\ddot{\bm r}_{B/N}\times\bm{c} = [I_{\text{sc},B}] \dot{\bm\omega}_{\cal B/N} + \bm\omega_{\cal B/N} \times [I_{\text{sc},B}] \bm\omega_{\cal B/N} + [I'_{\text{sc},B}] \bm\omega_{\cal B/N}
	\\+ \sum\limits_{j=1}^{N_P}\biggl[m_j \bm r_{P_{c,j}/B}\times\bm{r}''_{P_{c,j}/B}
	+ m_j \bm\omega_{\cal B/N} \times \Bigl(\bm{r}_{P_{c,j}/B} \times \bm{r}'_{P_{c,j}/B}\Bigr)\biggr]
	\label{eq:Hbdot5}
\end{multline}
Finally, using tilde matrix and simplifying yields the modified Euler equation, which is the second EOM necessary to describe the motion of the spacecraft.
\begin{multline}
	[I_{\text{sc},B}] \dot{\bm\omega}_{\cal B/N} = -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{sc},B}] \bm\omega_{\cal B/N} - [I'_{\text{sc},B}] \bm\omega_{\cal B/N}	\\- \sum\limits_{j=1}^{N_P}\biggl(m_j [\tilde{\bm r}_{P_{c,j}/B}]\bm{r}''_{P_{c,j}/B}
	+ m_j [\tilde{\bm\omega}_{\cal B/N}] [\tilde{\bm{r}}_{P_{c,j}/B}] \bm{r}'_{P_{c,j}/B}\biggr)
	+ \bm{L}_B - m_{\text{sc}} [\tilde{\bm{c}}] \ddot{\bm r}_{B/N}
	\label{eq:Final5}
\end{multline}
Rearranging Eq.~\eqref{eq:Final5} to be in the same form as the previous sections results in
\begin{multline}
	m_{\text{sc}}[\tilde{\bm{c}}]\ddot{\bm r}_{B/N}+[I_{\text{sc},B}] \dot{\bm\omega}_{\cal B/N} + \sum\limits_{j=1}^{N_P}m_j [\tilde{\bm r}_{P_{c,j}/B}] \hat{\bm p}_j \ddot{\rho}_j = \\
	-[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{sc},B}] \bm\omega_{\cal B/N}
	- [I'_{\text{sc},B}] \bm\omega_{\cal B/N} 	- \sum\limits_{j=1}^{N_P} m_j [\tilde{\bm\omega}_{\cal B/N}] [\tilde{\bm{r}}_{P_{c,j}/B}] \bm{r}'_{P_{c,j}/B} + \bm{L}_B
	\label{eq:Final6}
\end{multline}

\subsubsection{Fuel Slosh Motion}
Figure~\ref{fig:Flex_Slosh_Figure} shows that a single fuel slosh particle is free to move along its corresponding $\hat{\bm p}_j$ direction and this formulation is generalized to include $N_P$ number of fuel slosh particles. The derivation begins with Newton's law for each fuel slosh particle:
\begin{equation}
	m_j \ddot{\bm{r}}_{P_{c,j}/N} = \bm F_G + \bm F_C- k_j \rho_j \hat{\bm p}_j - c_j \dot{\rho_j} \hat{\bm p}_j
	\label{eq:sloshaccel}
\end{equation}
Where $\bm F_C$ is the constraint force that maintains the fuel slosh mass to travel along the direction $\hat{\bm p}_j$. The forces due to the spring and damper are explicitly included in Eq.~\eqref{eq:sloshaccel} and result in a restoring force and damping force. $\ddot{\bm{r}}_{P_{c,j}/N}$ is defined in the following equation.
\begin{equation}
	\ddot{\bm{r}}_{P_{c,j}/N} = \ddot{\bm{r}}_{B/N} + \ddot{\bm{r}}_{P_{c,j}/B}
\end{equation}
The inertial acceleration vector $\ddot{\bm{r}}_{P_{c,j}/B}$ is defined in Eq.~\eqref{eq:rpddot}. Plugging this definition into Eq.~\eqref{eq:sloshaccel} results in
\begin{multline}
	m_j \Big[\ddot{\bm{r}}_{B/N} + \ddot{\rho}_j \hat{\bm p}_j  +2 \bm\omega_{\cal B/N} \times \bm{r}'_{P_{c,j}/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{P_{c,j}/B}  +\bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{P_{c,j}/B})\Big]\\
	=  \bm F_G + \bm F_C - k_j \rho_j \hat{\bm p}_j - c_j \dot{\rho_j} \hat{\bm p}_j
	\label{eq:sloshaccel3}
\end{multline}

Equation~\eqref{eq:sloshaccel3} is the dynamical equation for a fuel slosh particle, however, the constraint force, $\bm F_C$, is undefined. Since the fuel slosh particle is free to move in the $\hat{\bm p_j}$ direction, the component of $\bm F_C$ along the $\hat{\bm p_j}$ direction is zero. Leveraging this insight, Eq.~\eqref{eq:sloshaccel3} is projected into the $\hat{\bm p_j}$ direction by multiplying both sides of the equation by $\hat{\bm p_j}^T$.
\begin{multline}
	m_j \Bigl(\hat{\bm p_j}^T \ddot{\bm{r}}_{B/N} + \ddot{\rho}_j  +2 \hat{\bm p_j}^T  \bm\omega_{\cal B/N} \times \bm{r}'_{P_{c,j}/B} + \hat{\bm p_j}^T \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{P_{c,j}/B}  + \hat{\bm p_j}^T \bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{P_{c,j}/B})\Bigr)\\
	= \hat{\bm p_j}^T \bm F_G - k_j \rho_j - c_j \dot{\rho_j}
	\label{eq:sloshaccel4}
\end{multline}
Moving the second order terms to the left hand side and introducing the tilde matrix notation yields the final equation needed to describe the motion of the spacecraft.
\begin{multline}
	m_j \hat{\bm p_j}^T \ddot{\bm{r}}_{B/N} - m_j \hat{\bm p_j}^T [\tilde{\bm{r}}_{P_{c,j}/B}] \dot{\bm\omega}_{\cal B/N} + m_j \ddot{\rho}_j  \\
	= \hat{\bm p_j}^T \bm F_G - k_j \rho_j - c_j \dot{\rho_j} - 2 m_j \hat{\bm p_j}^T  [\tilde{\bm\omega}_{\cal B/N}] \bm{r}'_{P_{c,j}/B}  - m_j \hat{\bm p_j}^T [\tilde{\bm\omega}_{\cal B/N}] [\tilde{\bm\omega}_{\cal B/N}] \bm{r}_{P_{c,j}/B}
	\label{eq:sloshaccel5}
\end{multline}

\subsection{Derivation of Equations of Motion - Kane's Method}

The choice of generalized coordinates and their respective generalized speeds are:

\begin{equation}
	\bm q =
	\begin{bmatrix}
		\bm r_{B/N}\\
		\bm \sigma_{\cal{B/N}}\\
		\rho_1\\
		\cdot\\
		\rho_{N_P}
	\end{bmatrix}
	\quad
	\bm u = \begin{bmatrix}
		\dot{\bm r}_{B/N}\\
		\bm \omega_{\cal{B/N}}\\
		\dot{\rho}_1\\
		\cdot\\
		\dot{\rho}_{N_P}
	\end{bmatrix}
\end{equation}

The necessary velocities needed to be defined are as follows

\begin{equation}
\dot{\bm r}_{B_c/N} = \dot{\bm r}_{B/N} + \bm \omega_{\cal{B/N}} \times {\bm r}_{B_c/B} = \dot{\bm r}_{B/N}  - [\tilde{{\bm r}}_{B_c/B}] \bm \omega_{\cal{B/N}} \\
\end{equation}

\begin{equation}
	\dot{\bm r}_{C/N} = \dot{\bm r}_{B/N} + \dot{\bm c}\\
	\label{eq:rDot_CN}
\end{equation}

\begin{equation}
	\bm \omega_{\cal{B/N}} = \bm \omega_{\cal{B/N}}
\end{equation}

\begin{equation}
	\dot{\bm r}_{P_{c,j}/N} = \dot{\bm r}_{B/N} + {\bm r}'_{P_{c,j}/B} + \bm \omega_{\cal{B/N}} \times {\bm r}_{P_{c,j}/B} = \dot{\bm r}_{B/N} + \dot{\rho}_j \hat{\bm p}_j  - [\tilde{{\bm r}}_{P_{c,j}/B}] \bm \omega_{\cal{B/N}}
\end{equation}

Now the following partial velocity table can be created:

\begin{table}[htbp]
	\caption{Partial Velocity Table}
	\label{tab:hub}
	\centering \fontsize{10}{10}\selectfont
	\begin{tabular}{ c | c | c | c } % Column formatting,
		\hline
		$r$  & $\bm v^{B_c}_{r}$  & $\bm \omega_{\textit{r}}^{\cal{B}}$ & $\bm v^{P_c}_{r}$ \\
		\hline
		$1-3$  & $[I_{3\times 3}]$ & $[0_{3\times 3}]$ & $[I_{3\times 3}]$ \\
		$4-6$ & $- [\tilde{{\bm r}}_{B_c/B}]$ & $[I_{3\times 3}]$ & $- [\tilde{{\bm r}}_{P_{c,j}/B}]$ \\
		$7-{N_P}$ &$[0_{3\times 1}]$ & $[0_{3\times 1}]$ & $\hat{\bm p}_j$ \\
		\hline
	\end{tabular}
\end{table}

An additional partial velocity that is needed is $[\bm v^C_{1-3}]$ for the external force applied on the spacecraft, $\bm F_{\text{ext}}$. Using Eq.\eqref{eq:rDot_CN} the following is defined:

\begin{equation}
	[\bm v^C_{1-3}] = [I_{3\times 3}]
\end{equation}

Using these partial velocity definitions, the follow sections will step through the formulation for the translational, rotational and slosh EOMs developed using Kane's method.

\subsubsection{Rigid Spacecraft Hub Translational Motion}

Starting with the definition of a generalized force:

\begin{equation}
	\bm F_r = \bm v_r^T \bm F
	\label{eq:genActive}
\end{equation}
Using this definition the external force applied on the spacecraft for the translational equations is defined as:

\begin{equation}
	\bm F_{1-3} = [\bm v^C_{1-3}]^T \bm F_{\text{ext}} = \bm F_{\text{ext}}
\end{equation}

Using the definition of generalized inertia forces,
\begin{equation}
	\bm F^*_r = \sum\limits_{r}^{N}\Big[\bm \omega_r^T \bm T^* +  \bm v_r^T (- m_r \bm a_r)\Big]
	\label{eq:genInert}
\end{equation}
the inertia forces for the hub translational motion are defined as

\begin{equation}
	\bm F^*_{1-3} = [\bm v^B_{1-3}]^T (-m_{\text{hub}} \ddot{\bm r}_{B_c/N}) + \sum\limits_{j}^{N_P}[\bm v^{P_c}_{1-3}]^T (-m_j \ddot{\bm r}_{P_{c,j}/N}) = -m_{\text{hub}} \ddot{\bm r}_{B_c/N} + \sum\limits_{j}^{N_P} -m_j \ddot{\bm r}_{P_{c,j}/N}
\end{equation}

Finally, Kane's equation is:

\begin{equation}
	\bm F_r + \bm F^*_r = 0
	\label{eq:KanesEq}
\end{equation}
therefore
\begin{equation}
	\bm F_{\text{ext}} -m_{\text{hub}} \ddot{\bm r}_{B_c/N} + \sum\limits_{j}^{N_P} -m_j \ddot{\bm r}_{P_{c,j}/N} = 0
\end{equation}
Expanding and rearranging results in
\begin{equation}
	m_{\text{hub}} \ddot{\bm r}_{B_c/N} + \sum\limits_{j}^{N_P} m_j (\ddot{\bm r}_{B/N} + \ddot{\bm r}_{P_{c,j}/B}) = \bm F_{\text{ext}}
	\label{eq:KanesTrans}
\end{equation}
Plugging Eq.~\eqref{eq:rpddot} into Eq.~\eqref{eq:KanesTrans} results in
\begin{multline}
	m_{\text{hub}} (\ddot{\bm r}_{B_c/N} + \ddot{\bm r}_{B_c/B}) + \sum\limits_{j}^{N_P} m_j \Big[\ddot{\bm r}_{B/N} + \ddot{\rho}_j \hat{\bm p}_j  +2 \bm\omega_{\cal B/N} \times \bm{r}'_{P_{c,j}/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{P_{c,j}/B}  \\
	+\bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{P_{c,j}/B})\Big] = \bm F_{\text{ext}}
\end{multline}
Combining like terms and rearranging results in
\begin{equation}
	m_{\text{sc}} \ddot{\bm r}_{B/N}-m_{\text{sc}} [\tilde{\bm{c}}] \dot{\bm\omega}_{\cal B/N} +\sum_{j=1}^{N_{P}}m_j \hat{\bm p}_j \ddot{\rho}_j = \bm F_{\text{ext}}	- 2 m_{\text{sc}} [\tilde{\bm\omega}_{\cal B/N}] \bm c'
	- m_{\text{sc}} [\tilde{\bm\omega}_{\cal B/N}][\tilde{\bm\omega}_{\cal B/N}]\bm{c}
	\label{eq:Rbddot4}
\end{equation}
Which is identical to Eq.~\eqref{eq:Rbddot3} found using Newtonian mechanics.
\subsubsection{Rigid Spacecraft Hub Rotational Motion}

The torque acting on the spacecraft, $\bm L_B$ needs to be defined as a general active force. Using Eq.~\eqref{eq:genActive} active forces acting on the spacecraft for the rotational equations can be defined as:

\begin{equation}
	\bm F_{4-6} = [\bm \omega_{4-6}^{\cal{B}}]^T \bm L_B = \bm L_B
\end{equation}

To define the generalized inertia forces, using Eq.~\eqref{eq:genInert} the definition of $\bm T^*$ needs to be defined for a rigid body and applying it to the hub:

\begin{equation}
	\bm T^* = -[I_{\text{hub},B}] \dot{\bm\omega}_{\cal B/N}  -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{hub},B}] \bm\omega_{\cal B/N}
\end{equation}

\begin{multline}
	\bm F^*_{4-6} = [\bm \omega_{4-6}^{\cal{B}}]^T \bm T^* + [\bm v^{B_c}_{4-6}]^T (-m_{\text{hub}} \ddot{\bm r}_{B_c/N}) + \sum\limits_{j}^{N_P}[\bm v^{P_c}_{4-6}]^T (-m_j \ddot{\bm r}_{P_{c,j}/N}) \\
	= -[I_{\text{hub},B}] \dot{\bm\omega}_{\cal B/N}  -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{hub},B}] \bm\omega_{\cal B/N} - m_{\text{hub}} [\tilde{{\bm r}}_{B_c/B}] \ddot{\bm r}_{B_c/N}  + \sum\limits_{j}^{N_P}- [\tilde{{\bm r}}_{P_{c,j}/B}]^T (-m_j \ddot{\bm r}_{P_{c,j}/N})
\end{multline}

Using Kane's equation, Eq.~\eqref{eq:KanesEq}, the following equations of motion for the rotational dynamics are defined:

\begin{equation}
	\bm L_B  -[I_{\text{hub},B}] \dot{\bm\omega}_{\cal B/N}  -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{hub},B}] \bm\omega_{\cal B/N} -  m_{\text{hub}} [\tilde{{\bm r}}_{B_c/B}] \ddot{\bm r}_{B_c/N}  + \sum\limits_{j}^{N_P}- [\tilde{{\bm r}}_{P_{c,j}/B}] (m_j \ddot{\bm r}_{P_{c,j}/N}) = 0
\end{equation}
Plugging in some definitions
\begin{multline}
	[I_{\text{hub},B}] \dot{\bm\omega}_{\cal B/N}  + m_{\text{hub}} [\tilde{{\bm r}}_{B_c/B}] \ddot{\bm r}_{B_c/N}  + \sum\limits_{j}^{N_P} m_j [\tilde{{\bm r}}_{P_{c,j}/B}] \Big[\ddot{\bm r}_{B/N} + \ddot{\rho}_j \hat{\bm p}_j  +2 \bm\omega_{\cal B/N} \times \bm{r}'_{P_{c,j}/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{P_{c,j}/B}  \\
	+\bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{P_{c,j}/B})\Big] = -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{hub},B}] \bm\omega_{\cal B/N} + \bm L_B
\end{multline}
Combining like terms results in the same equation seen in Eq.~\eqref{eq:Final6} found using Newtonian mechanics.
\begin{multline}
	m_{\text{sc}}[\tilde{\bm{c}}]\ddot{\bm r}_{B/N}+[I_{\text{sc},B}] \dot{\bm\omega}_{\cal B/N} + \sum\limits_{j=1}^{N_P}m_j [\tilde{\bm r}_{P_{c,j}/B}] \hat{\bm p}_j \ddot{\rho}_j = \\
	-[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{sc},B}] \bm\omega_{\cal B/N}
	- [I'_{\text{sc},B}] \bm\omega_{\cal B/N} 	- \sum\limits_{j=1}^{N_P} m_j [\tilde{\bm\omega}_{\cal B/N}] [\tilde{\bm{r}}_{P_{c,j}/B}] \bm{r}'_{P_{c,j}/B} + \bm{L}_B
	\label{eq:Final7}
\end{multline}

\subsubsection{Fuel Slosh Motion}
Following the similar pattern for translational and rotational equations the generalized active forces are defined:

\begin{equation}
	\bm F_{7} = \bm v^{P_c}_{r} \cdot (\bm F_G + \bm F_C -k\rho_j \hat{\bm p}_j - c \dot{\rho} \hat{\bm p}_j) = \hat{\bm p_j}^T \bm F_G -k\rho_j - c \dot{\rho}
\end{equation}
The generalized inertia forces are defined as:

\begin{equation}
	\bm F^*_{7} = \bm v^{P_c}_{r} \cdot (-m_j \ddot{\bm r}_{P_{c,j}/N}) = \hat{\bm p}_j^T (-m_j \ddot{\bm r}_{P_{c,j}/N})
\end{equation}
Using Kane's equation the following equations of motion are defined:

\begin{multline}
	\hat{\bm p_j}^T \bm F_G -k\rho_j - c \dot{\rho} - m_j \hat{\bm p}_j^T \Big[\ddot{\bm r}_{B/N} + \ddot{\rho}_j \hat{\bm p}_j  +2 \bm\omega_{\cal B/N} \times \bm{r}'_{P_{c,j}/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{P_{c,j}/B}  \\
	+\bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{P_{c,j}/B})\Big] = 0
\end{multline}
Rearranging and combining like terms results in:

\begin{multline}
	m_j \hat{\bm p_j}^T \ddot{\bm{r}}_{B/N} - m_j \hat{\bm p_j}^T [\tilde{\bm{r}}_{P_{c,j}/B}] \dot{\bm\omega}_{\cal B/N} + m_j \ddot{\rho}_j  \\
	= \hat{\bm p_j}^T \bm F_G - k_j \rho_j - c_j \dot{\rho_j} - 2 m_j \hat{\bm p_j}^T  [\tilde{\bm\omega}_{\cal B/N}] \bm{r}'_{P_{c,j}/B}  - m_j \hat{\bm p_j}^T [\tilde{\bm\omega}_{\cal B/N}] [\tilde{\bm\omega}_{\cal B/N}] \bm{r}_{P_{c,j}/B}
	\label{eq:sloshaccel6}
\end{multline}
Which is identical to Eq.~\eqref{eq:sloshaccel5}!


\documentclass[12pt]{cdblatex}
\usepackage{exercises}
\usepackage{fancyhdr}
\usepackage{footer}

\begin{document}

% --------------------------------------------------------------------------------------------
\section*{Exercise 3.5 Commutation of covariant derivatives}

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w#}::Indices(position=independent).

   \nabla{#}::Derivative.

   expr :=   \nabla_{d}{\nabla_{c}{A_{a} B_{b}}}
           - \nabla_{c}{\nabla_{d}{A_{a} B_{b}}}.  # cdb(ex-0305.100,expr)

   product_rule (expr)                             # cdb(ex-0305.101,expr)
   distribute   (expr)                             # cdb(ex-0305.102,expr)
   product_rule (expr)                             # cdb(ex-0305.103,expr)
   factor_out   (expr,$A_{a?},B_{b?}$)             # cdb(ex-0305.104,expr)

\end{cadabra}

\begin{dgroup*}[spread={3pt}]
   \Dmath*{\cdb{ex-0305.100} = \Cdb*{ex-0305.101}
                             = \Cdb*{ex-0305.102}
                             = \Cdb*{ex-0305.103}
                             = \Cdb*{ex-0305.104}}
\end{dgroup*}

\end{document}


% Chapter 1

\chapter{Random Walk Approach} % Main chapter title

\label{Chapter3} % For referencing the chapter elsewhere, use \ref{Chapter1}

\section{Aldous, Broder}

Aldous \cite{aldous1990random} and Broder \cite{63516} independently invented the following simple random walk based algortihm.

\begin{figure}[h!]
  % \centering
  % \scalebox{0.7}{
  \begin{algorithm}[H]
    \KwIn{$G = (V,E)$}
    \KwOut{A random spanning tree}

    Choose a starting vertex $s$ arbitrarily

    $T_V \leftarrow \{s\}, T_E \leftarrow \emptyset$

    \While{$|T_V| < |V$} {

      $next =_{u.a.r} N(s)$

      \If{$next \not\in T_V$} {
        $T_V = T_V \cup \{next\}$

        $T_E = T_E \cup \{(s, next)\}$
      }

      $s = next$

    }

    \KwRet{$T = (T_V, T_E)$}

    \caption{Aldous-Broder Algorithm}
  \end{algorithm}
  % }
\end{figure}

\subsection{Running Time}

\textbf{Cover Time}

$cov_G(u) := $ The expected number of steps for a random walk starting at $u$ to visit all the vertices in $G$ \\

\textbf{Cover Time of $G$}

$cov_G := \max_{u \in V_G} cov_G(u)$

It is known that $cov_G = \mathcal{O}(|V|\ |E|) = \mathcal{O}(|V|^3)$

\subsection{An Example}

\begin{figure}[h!]
  \begin{center}
  \begin{subfigure}{.3\textwidth}
    \centering
    \begin {tikzpicture}[auto ,node distance =3 cm and 3cm ,on grid ,
      semithick ,
      state/.style ={ circle  ,
        draw,black , text=black , minimum width =1 cm}]
      \node[state] (C){$C$};
      \node[state, fill=white!50!green] (A) [above =of C] {$A$};
      \node[state] (B) [above right =of C] {$B$};
      \node[state] (D) [right =of C] {$D$};
      \path (C) edge[very thick] (D);
      \path (B) edge[very thick] (D);
      \path (A) edge[very thick] (B);
      \path (C) edge[very thick] (A);
      \path (D) edge[very thick] (A);
    \end{tikzpicture}
    \caption{Iteration xxx}
  \end{subfigure}
  \begin{subfigure}{.3\textwidth}
    \centering
    \begin {tikzpicture}[auto ,node distance =3 cm and 3cm ,on grid ,
      semithick ,
      state/.style ={ circle  ,
        draw,black , text=black , minimum width =1 cm}]
      \node[state] (C){$C$};
      \node[state, fill=white!50!red] (A) [above =of C] {$A$};
      \node[state, fill=white!50!green] (B) [above right =of C] {$B$};
      \node[state] (D) [right =of C] {$D$};
      \path (C) edge[very thick] (D);
      \path (B) edge[very thick] (D);
      \path (A) edge[very thick,blue] (B);
      \path (C) edge[very thick] (A);
      \path (D) edge[very thick] (A);
    \end{tikzpicture}
    \caption{Iteration xxy}
  \end{subfigure}
  \begin{subfigure}{.3\textwidth}
    \centering
    \begin {tikzpicture}[auto ,node distance =3 cm and 3cm ,on grid ,
      semithick ,
      state/.style ={ circle  ,
        draw,black , text=black , minimum width =1 cm}]
      \node[state] (C){$C$};
      \node[state, fill=white!50!green] (A) [above =of C] {$A$};
      \node[state, fill=white!50!red] (B) [above right =of C] {$B$};
      \node[state] (D) [right =of C] {$D$};
      \path (C) edge[very thick] (D);
      \path (B) edge[very thick] (D);
      \path (A) edge[very thick,blue] (B);
      \path (C) edge[very thick] (A);
      \path (D) edge[very thick] (A);
    \end{tikzpicture}
    \caption{Iteration xxz}
  \end{subfigure}
\end{center}

  \begin{center}
  \begin{subfigure}{.3\textwidth}
    \centering
    \begin {tikzpicture}[auto ,node distance =3 cm and 3cm ,on grid ,
      semithick ,
      state/.style ={ circle  ,
        draw,black , text=black , minimum width =1 cm}]
      \node[state] (C){$C$};
      \node[state, fill=white!50!red] (A) [above =of C] {$A$};
      \node[state, fill=white!50!red] (B) [above right =of C] {$B$};
      \node[state, fill=white!50!green] (D) [right =of C] {$D$};
      \path (C) edge[very thick] (D);
      \path (B) edge[very thick] (D);
      \path (A) edge[very thick,blue] (B);
      \path (C) edge[very thick] (A);
      \path (D) edge[very thick, blue] (A);
    \end{tikzpicture}
    \caption{Iteration xyx}
  \end{subfigure}
  \begin{subfigure}{.3\textwidth}
    \centering
    \begin {tikzpicture}[auto ,node distance =3 cm and 3cm ,on grid ,
      semithick ,
      state/.style ={ circle  ,
        draw,black , text=black , minimum width =1 cm}]
      \node[state] (C){$C$};
      \node[state, fill=white!50!red] (A) [above =of C] {$A$};
      \node[state, fill=white!50!green] (B) [above right =of C] {$B$};
      \node[state, fill=white!50!red] (D) [right =of C] {$D$};
      \path (C) edge[very thick] (D);
      \path (B) edge[very thick] (D);
      \path (A) edge[very thick,blue] (B);
      \path (C) edge[very thick] (A);
      \path (D) edge[very thick, blue] (A);
    \end{tikzpicture}
    \caption{Iteration xyy}
  \end{subfigure}
  \begin{subfigure}{.3\textwidth}
    \centering
    \begin {tikzpicture}[auto ,node distance =3 cm and 3cm ,on grid ,
      semithick ,
      state/.style ={ circle  ,
        draw,black , text=black , minimum width =1 cm}]
      \node[state] (C){$C$};
      \node[state, fill=white!50!red] (A) [above =of C] {$A$};
      \node[state, fill=white!50!red] (B) [above right =of C] {$B$};
      \node[state, fill=white!50!green] (D) [right =of C] {$D$};
      \path (C) edge[very thick] (D);
      \path (B) edge[very thick] (D);
      \path (A) edge[very thick,blue] (B);
      \path (C) edge[very thick] (A);
      \path (D) edge[very thick, blue] (A);
    \end{tikzpicture}
    \caption{Iteration xyz}
  \end{subfigure}
\end{center}
  \begin{subfigure}{1.0\textwidth}
    \centering
    \begin {tikzpicture}[auto ,node distance =3 cm and 3cm ,on grid ,
      semithick ,
      state/.style ={ circle  ,
        draw,black , text=black , minimum width =1 cm}]
      \node[state, fill=white!50!green] (C){$C$};
      \node[state, fill=white!50!red] (A) [above =of C] {$A$};
      \node[state, fill=white!50!red] (B) [above right =of C] {$B$};
      \node[state, fill=white!50!red] (D) [right =of C] {$D$};
      \path (C) edge[very thick, blue] (D);
      \path (B) edge[very thick] (D);
      \path (A) edge[very thick,blue] (B);
      \path (C) edge[very thick] (A);
      \path (D) edge[very thick, blue] (A);
    \end{tikzpicture}
    \caption{Iteration xzx}
  \end{subfigure}
\end{figure}

% \pagebreak
%
% \section{Wilson's Algorithm}
%
% \citet{10.1145/237814.237880} proposed a different variant of random walk based algorithm which runs faster than the cover time of the graph.

% ----------------------------------------------------------------------------------------

% ----------------------------------------------------------------------------------------


\section{Technical Introduction}
Here is a brief description of why Proposition FIXME(0.2) might be amenable to
computer-assisted proof.
If a shortest geodesic $\delta$ in a hyperbolic $3$-manifold $N$ does not have
a $\ln(3)/2$
tube then there is a 2-generator subgroup $G$ of $\pi_1(N) = \Gamma$
which also does not have that property.
Specifically, take $G$ generated by $f$ and $w$,
with $f \in \Gamma$ a primitive hyperbolic isometry
whose fixed axis $\delta_0 \subset {\bf H}^3$ projects to $\delta$, and
with $w \in \Gamma$ a hyperbolic isometry
which takes $\delta_0$ to a nearest translate.
Then, after identifying $N={\bf H}^3/\Gamma$ and letting
$Z={\bf H}^3/G$,
we see that the shortest geodesic in $Z$ (which corresponds to $\delta$)
does not have
a $\ln(3)/2$ tube.
Thus, to understand solid tubes around shortest geodesics in hyperbolic
$3$-manifolds, we need to understand appropriate 2-generator groups, and this
can be done by a parameter space analysis as follows.  (Parameter space
analyses are naturally amenable to
computer proofs.)

The space of {\it relevant} (see Definition FIXME(2.8)) 2-generator groups
in ${\rm Isom}_+({\bf H}^3)$ is naturally
parametrized by a subset ${\cal P}$ of ${\bf C}^3.$
Each parameter corresponds to a
2-generator group $G$ with specified generators $f$ and $w$, and we call
such a group a {\it marked group}.
The marked groups of particular interest are those in which $G$ is
discrete, torsion-free, parabolic-free, $f$ corresponds to a shortest
geodesic $\delta$, and $w$ corresponds to a
covering translation of a particular lift of
$\delta$ to a nearest translate.
We denote this set of particularly interesting marked groups by ${\cal T}.$
We show that if tuberadius($\delta) \le \ln(3)/2$
in a hyperbolic $3$-manifold $N,$ then
$G$ must correspond to a parameter lying in one of seven small regions
${\cal R}_n,\ n=0,\ldots,6$
in ${\cal P}$.
With respect to this notation, we have:

\vglue8pt {\elevensc Proposition FIXME(2.19)}.
${\cal T} \cap ({\cal P} - \mathbold{\cup}_{n=0,\ldots,6}{\cal R}_n) = \emptyset.$
\vfill

The full statement of Proposition FIXME(2.19)
explicitly describes the seven small
regions of the parameter space as well as some associated data.

Here is the idea of the proof.
Roughly speaking, we subdivide ${\cal P}$ into a billion regions
of varying sizes,
and show that all but the seven exceptional regions cannot contain
a parameter corresponding to a
``shortest/nearest" marked group.
For example we would know that
a region ${\cal R}$ contained no such group if we knew that for each
point $\rho\in {\cal R}$,
Relength($f_\rho) > {\rm Relength}(w_\rho).$
(Here Relength($f_\rho$) (resp.\ Relength($w_\rho^{\phantom{|}}$))
denotes the real translation length of the isometry of ${\bf H}^3$
corresponding to
the element $f$ (resp.\ $w$) in the marked group with parameter~$\rho.$)
This inequality would contradict the fact that $f$ corresponds to $\delta$
which is a {\it shortest} geodesic.  Similarly, there are {\it nearest}
contradictions.


% -*-latex-*-

\title{Orbiter Technical Notes: Distributed Vessel Mass}
\author{Martin Schweiger}
\date{September 27, 2005}

\documentclass[a4paper]{article}
\usepackage[dvips]{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{times}
\usepackage{cite}

\begin{document}
\bibliographystyle{unsrt}

%\renewcommand{\vec}[1]{\ensuremath{\mathbf{#1}}}

\newcommand{\vR}[1]{\ensuremath{\vec{R}_{#1}}}
\newcommand{\nR}[1]{\ensuremath{|\vR{#1}|}}
\newcommand{\mat}[1]{\ensuremath{\mathsf{#1}}}

\maketitle

\section{Introduction}
A point mass $m$ placed at position $\vec{r}_0$ in a gravitational field $\vec{g}(\vec{r})$ experiences a force $\vec{F}_G = m\vec{g}(\vec{r}_0)$.
For an extended object with a density distribution $\rho(\vec{r})$ the resulting force can be obtained by integrating over its volume $V \subset \mathbb{R}^3$:
\begin{equation*}
\vec{F}_G = \int_V \vec{g}(\vec{r})\rho(\vec{r}) d\vec{r}
\end{equation*}
For numerical calculations it is sometimes useful to discretise the object into a rigid system of point masses $m_i$ whose relative positions are defined by their barycentric coordinates $\vec{s}_i$. Then,
\begin{equation*}
\vec{F}_G = \sum_i m_i \vec{g}(\vec{s}_i+\vec{r}_\text{CG})
\end{equation*}
where $\vec{r}_\text{CG}$ is the position of the barycentre. For the calculation of the linear force $\vec{F}_G$ Orbiter makes the assumption $\vec{g}(\vec{s}_i + \vec{r}_\text{CG}) = \vec{g}(\vec{r}_\text{CG})$, i.e. the gravitational field is homogeneous over the volume of the object. This approximation is justified when calculating the gravitational force on a spacecraft which is small compared to its orbital radius vector, $|\vec{s}_i| \ll |\vec{r}_\text{CG}|$. With this assumption, we arrive back at the expression for a point mass:
\begin{equation*}
\vec{F}_G = \vec{g}(\vec{r}_\text{CG}) \sum_i m_i = m \vec{g}(\vec{r}_\text{CG})
\end{equation*}
However, an inhomogeneous potential will also induce an angular moment $\vec{M}_G$ in an extended object, and this can generally not be neglected.
In the continuous case, $\vec{M}_G$ is given by
\begin{equation}\label{eq:cont_torque}
\vec{M}_G = \int_V \vec{g}(\vec{r}) \rho(\vec{r}) \times (\vec{r}-\vec{r}_\text{CG}) d\vec{r},
\end{equation}
and after discretisation this becomes
\begin{equation}\label{eq:torque}
\vec{M}_G = \sum_i m_i \vec{g}(\vec{s}_i + \vec{r}_\text{CG}) \times \vec{s}_i
\end{equation}

\section{Symmetric gravitational potential}\label{sec:sympot}
If we assume that
\begin{equation}\label{eq:gravpot}
\vec{g}(\vec{r}) = -GMr^{-3}\vec{r},
\end{equation}
i.e. the central body is a sphere of mass $M$ with homogeneous density distribution, and further that $|\vec{r}| = |\vec{r}_\text{CG} + \vec{s}| \gg |\vec{s}|$ over the volume $V$ of the spacecraft, then we can approximate~\cite{wertz1978}:
\begin{equation}\label{eq:radapprox}
r^{-3} = (\vec{r}\cdot\vec{r})^{-3/2} =
\left\{ r_\text{CG}^2 \left[ 1 + \frac{2\vec{r}_\text{CG}\cdot\vec{s}}{r_\text{CG}^2} + \frac{\vec{s}^2}{r_\text{CG}^2} \right] \right\}^{-3/2} \approx
r_\text{CG}^{-3} \left[ 1 - \frac{3 \vec{r}_\text{CG}\cdot\vec{s}}{r_\text{CG}^2} \right]
\end{equation}
Substituting Eqns.~\ref{eq:gravpot} and \ref{eq:radapprox} into Eq.~\ref{eq:cont_torque} leads to
\begin{equation}
\vec{M}_G = \frac{3GM}{r_\text{CG}^3} \int_V (\hat{r}_\text{CG} \times \vec{s}) (\hat{r}_\text{CG} \cdot \vec{s}) \rho(\vec{r}) d\vec{r}
\end{equation}
If the vectors $\vec{s}$ and $\hat{r}_\text{CG}$ are expressed in the vessel reference system, then $\vec{M}_G$ can be written as
\begin{equation}
\vec{M}_G = \frac{3GM}{r_\text{CG}^3} [(\mat{L}\hat{r}_\text{CG}) \times \hat{r}_\text{CG}]
\end{equation}
where $\mat{L}$ is the vessel's inertia tensor expressed in the same frame. (Note that Orbiter currently assumes that the vessel frame of reference is orientated so that $\mat{L}$ is diagonal.)

\section{Discrete point mass systems}
Orbiter implements gravity gradient torque as discussed in Section~\ref{sec:sympot}, assuming that the vessel's inertia tensor is known. In this section we give an alternative method that describes the vessel as a rigid system of point masses. This method is not currently implemented in Orbiter.

\subsection{2-point systems}
In the simplest case, a vessel can be expressed as a rigid system of two point masses. This allows to simulate an angular moment as a result of a gradient in the gravitational potential $\vec{g}(\vec{r})$.

\setlength{\unitlength}{1mm}
\begin{picture}(100,50)(0,35)
\put(40,70){\circle*{3}}
\put(40,70){\vector(0,-1){25}}
\put(45,58){\makebox(0,0){$\vec{g}_\text{CG}$}}
\put(42,74){\makebox(0,0){CG}}
\put(40,70){\vector(-3,1){20}}
\put(30,77){\makebox(0,0){$\vec{s}_1$}}
\put(40,70){\vector(3,-1){41}}
\put(62,66){\makebox(0,0){$\vec{s}_2$}}
\put(19,77){\vector(0,-1){30}}
\put(15,62){\makebox(0,0){$\vec{g}_1$}}
\put(82,56){\vector(0,-1){15}}
\put(86,48){\makebox(0,0){$\vec{g}_2$}}
\put(19,77){\circle*{2}}
\put(14,77){\makebox(0,0){$m_1$}}
\put(82,56){\circle*{2}}
\put(87,56){\makebox(0,0){$m_2$}}
\end{picture}

\noindent We want to calculate the angular moment induced by the difference of the gravitational fields at $\vec{s}_1$ and $\vec{s}_2$. Let the ratio of masses be denoted by $m_1/m_2 = \gamma$. Then $\vec{s}_2 = -\gamma \vec{s}_1$, and the forces acting on the two mass points are
\begin{equation*}
\vec{F}_1 = m_1 \vec{g}_1,
\qquad \vec{F}_2 = m_2 \vec{g}_2 = \frac{m_1}{\gamma} \vec{g}_2.
\end{equation*}
The angular moment is obtained by adding both components,
\begin{equation}\label{eq:moment}
\begin{split}
\vec{M}_G &= \vec{F}_1 \times \vec{s}_1 + \vec{F}_2 \times \vec{s}_2 \\
&= m_1 \vec{g}_1 \times \vec{s}_1 - \frac{m_1}{\gamma} \vec{g}_2 \times \gamma \vec{s}_1 \\
&= m_1 \left(\vec{g}_1 - \vec{g}_2\right) \times \vec{s}_1
\end{split}
\end{equation}
which is now expressed as a function of the local field gradient $\vec{g}_1 - \vec{g}_2$.

\subsection{Numerical implementation}
The field difference is usually small compared to the magnitude of the field acting on the vessel:
\begin{equation*}
|\vec{g}_1 - \vec{g}_2| \ll |\vec{g}_{1,2}|
\end{equation*}
resulting in a significant loss of precision when the field difference in Eq.~\ref{eq:moment} is calculated directly.

To avoid this problem, we can simplify Eq.~\ref{eq:moment} if the field $\vec{g}(\vec{r})$ can be condsidered to be generated by a single point mass $M$ at position $\vec{R}_0$ relative to CG.
Let $\vR{1} = \vR{0} - \vec{s}_1$ and $\vR{2} = \vR{0} - \vec{s}_2$ be the position of $M$ relative to $m_1$ and $m_2$, and let $\vec{s} = \vec{s}_2-\vec{s}_1$.

\setlength{\unitlength}{0.5mm}
\begin{picture}(100,120)(-50,-35)
\put(34,62){\makebox(0,0){CG}}
\put(40,66.5){\circle*{3}}
\put(19,77){\circle*{2}}
\put(81,46){\circle*{2}}
\put(19,77){\vector(2,-1){61}}
\put(19,77){\vector(0,-1){100}}
\put(40,67){\vector(0,-1){89.5}}
\put(81,46){\vector(0,-1){69}}
\put(51,66){\makebox(0,0){$\vec{s}$}}
\put(20,-28){\makebox(0,0){$\vR{1}$}}
\put(41,-28){\makebox(0,0){$\vR{0}$}}
\put(81,-28){\makebox(0,0){$\vR{2}$}}
\put(13,77){\makebox(0,0){$m_1$}}
\put(88,46){\makebox(0,0){$m_2$}}
\put(19,46){\line(1,0){61}}
\put(15,60){\makebox(0,0){$h$}}
\put(19,50){\line(1,0){4}}
\put(23,46){\line(0,1){4}}
\put(19,46){\makebox(4,4){$\cdot$}}
\end{picture}

\noindent Since $\nR{0} \gg |\vec{s}|$, we can find the difference $h = \nR{1} - \nR{2}$ of the distances between the point masses $m_1$ and $m_2$ from $M$ by
\begin{equation*}
h = |\vec{s}| \cos \sphericalangle (\vec{s},\vR{0})
= \frac{\vec{s} \vR{0}}{\nR{0}}
\end{equation*}
We can now write the field difference $\vec{g}_1 - \vec{g}_2$ as
\begin{equation*}
\vec{g}_1 - \vec{g}_2 =
GM \left( \frac{\vR{1}}{\nR{1}^3} - \frac{\vR{2}}{\nR{2}^3} \right)
\end{equation*}
and by substituting $\vR{2} = \vR{1} - \vec{s}$ and $\nR{2} = \nR{1} - h$, and omitting higher-order terms,
\begin{equation*}
\begin{split}
\frac{\vec{g}_1 - \vec{g}_2}{GM} &= \frac{\vR{1}}{\nR{1}^3} - \frac{\vR{1} - \vec{s}}{(\nR{1}-h)^3} \\
&= \frac{h (- 3\nR{1}^2 + 3\nR{1} h - h^2) \vR{1} + \nR{1}^3 \vec{s}}
{\nR{1}^3 (\nR{1}-h)^3} \\
&= \frac{3h(h - \nR{1})\vR{1} + \nR{1}^2\vec{s}}
{\nR{1}^4 (\nR{1} - 3h)} + O(2)
\end{split}
\end{equation*}
Substituting into Eq.~\ref{eq:moment} and utilising $\vec{s} \parallel \vec{s}_1$ leads to
\begin{equation*}
\vec{M}_G \approx 3 G M m_1 \frac{h(h-\nR{1})}{\nR{1}^4(\nR{1}-3h)}
\vR{1} \times \vec{s}_1
\end{equation*}

\subsection{Multi-point systems}
For objects composed of more than two mass points, the formulation must be somewhat extended. We split the gravitational potential acting on mass point $m_i$ into a barycentric and a perturbation component: $\vec{g}(\vec{r}_\text{CG} + \vec{s}_i) = \vec{g}_\text{CG} + \vec{\gamma}_i$.
Then Eq.~\ref{eq:torque} becomes
\begin{equation}\label{eq:multitorque}
\begin{split}
\vec{M}_G &= \sum_i (\vec{g}_\text{CG} + \vec{\gamma}_i) \times m_i \vec{s}_i\\
&= \vec{g}_\text{CG} \times \sum_i m_i \vec{s}_i + \sum_i \vec{\gamma}_i \times m_i \vec{s}_i\\
&= \sum_i \vec{\gamma}_i \times m_i \vec{s}_i
\end{split}
\end{equation}
since the definition of the barycentre demands $\sum_i m_i \vec{s}_i = 0$.

The perturbation components are calculated in the same way as in the 2-point problem, assuming that the gravitational potential is generated by a single point mass $M$ at position $\vec{R}_0$ in barycentric coordinates of the spacecraft, with $|\vec{R}_0| \gg |\vec{s}_i|\;\forall i$.
Given $\vec{R}_i = \vec{R}_0 - \vec{s}_i$, the difference $h_i$ between the distances of $m_i$ and the CG from $M$ is given by
\begin{equation*}
h_i = |\vec{s}_i| \cos\sphericalangle (-\vec{s}_i, \vec{R}_0)
= -\frac{\vec{s}_i \vec{R}_0}{|\vec{R}_0|}
\end{equation*}
Then as before,
\begin{equation*}
\begin{split}
\frac{\vec{\gamma}_i}{GM} &= \frac{\vec{R}_0 - \vec{s}_i}{(|\vec{R}_0|+h_i)^3} - \frac{\vec{R}_0}{|\vec{R}_0|^3} \\
&= -\frac{h_i(3|\vec{R}_0|^2 + 3|\vec{R}_0| h_i + h_i^2) \vec{R}_0 + |\vec{R}_0^3| \vec{s}_i}{(|\vec{R}_0|+h_i)^3 |\vec{R}_0|^3} \\
&= -\frac{3h_i(|\vec{R}_0|+h_i) \vec{R}_0 + |\vec{R}_0|^2 \vec{s}_i}{|\vec{R}_0|^4 (|\vec{R}_0| + 3h_i)} + O(2)
\end{split}
\end{equation*}
and inserting into Eq.~\ref{eq:multitorque} leads to
\begin{equation*}
\vec{M}_G = -\frac{3GM}{|\vec{R}_0|^4} \vec{R}_0 \times \sum_i
\frac{m_i h_i(|\vec{R}_0|+h_i)}{|\vec{R}_0| + 3h_i} \vec{s}_i
\end{equation*}

\section{Damping}
The model defined above has equilibrium states ($\vec{M}_G = 0$) for the attitudes $\vec{s} \parallel \vR{0}$ (vessel axis aligned with radius vector) and $\vec{s} \perp \vR{0}$ (vessel axis perpendicular to radius vector). Only the first of these is stable because an attitude perturbation will generate a torque in the opposite direction, leading to an undamped oscillation around the equilibrium attitude.

Orbiter allows to introduce a damping term
\begin{equation*}
\vec{M}_D = -\alpha\vec{\omega}_G
\end{equation*}
where $\vec{\omega}_G$ is the angular velocity induced by torque $\vec{M}_G$, and $\alpha$ is a user-defined damping coefficient. The physical source for the damping term may be the deformation of the vessel by tidal forces, or redistribution of liquid propellants.

\bibliography{../ref}

\end{document}


% Created 2021-12-09 Thu 23:56
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkcolor=blue}
\date{\today}
\title{On discontinuity of derivatives in Calculus}
\hypersetup{
 pdfauthor={Iman Alavi Fazel},
 pdftitle={On discontinuity of derivatives in Calculus},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 27.2 (Org mode 9.4.4)},
 pdflang={English}}
\begin{document}

\maketitle
\tableofcontents

\section{Prologue}
\label{sec:orgbf28a93}
Derivatives appear in almost every engineering subject.
For example, Faraday's law of induction which is written as:

\begin{equation}
  \varepsilon = -N\frac{d\phi}{dt}
\end{equation}

Or the famous Newton's law:

\begin{equation}
  F = m\frac{dv}{dt}
\end{equation}

A question that I was prompted with, was that how much discontinuous derivative function can be?
Because the fundamental theorem of Calculus (Part II) tells us that:
if a function has derivatives at all point (in its domain), and the values of these derivatives are \textbf{changing continuously}, then integral cancels the effect of differentiation and gives back the original function.
But does having the equation $$f(x) = \frac{dy}{dx}$$ automatically implies that $$f(x)$$ can only be continuous?
If not, how much discontinuous our function can be?

I've spent a good amount of time looking for this starightforward question, which doesn't get addressed in a standard Calculus course (at least in the engineering curriculums).
The answer turned out to be a bit tricky because we should first be clear that of what do we mean by "how much discontinouos".
But first, let's first start with a classic example where discontinuity of derivative occure at a \emph{single} point.

\section{Discontinuity of derivative at a single point}
\label{sec:org7485e62}
The function below is a well-known function that has derivative at all points, and the value of these derivatives are all continuous except at a single point, \(x = 0\).

\begin{equation}
\[
f(x) =
     \begin{cases}
       \equation{x^2 sin(1/x)} &\quad\text{if }\equation{x \neq 0} \\
       \equation{0} &\quad\text{if }\equation{x = 0} \\
     \end{cases}
\]
\end{equation}

It has the following graph:

\begin{figure}[htbp]
\centering
\includegraphics[width=.9\linewidth]{./img/figure1.png}
\caption{\label{fig:org4e02768}}
\end{figure}

The derivative of this function (by plugging into the definition of derivative) is:

\begin{equation}
\[
f'(x) =
     \begin{cases}
       \equation{x^2 sin(1/x) - cos(1/x)} &\quad\text{if }\equation{x \neq 0} \\
       \equation{0} &\quad\text{if }\equation{x = 0} \\
     \end{cases}
\]
\end{equation}

With the following graph:

\begin{figure}[htbp]
\centering
\includegraphics[width=.9\linewidth]{./img/figure2.png}
\label{fig:org3cf45b4}
\end{figure}

Which clearly shows that it is discontinuous at \(x = 0\).
As a side note, we may ask ourselves under which conditions does the discontinuity of derivative can occure?
Is the discontinuity in above example a special type of discontinuity?
or can it be of any type, such as "jumps" discontinuity?

As it turns out, even though derivatives can be discontinuous,
they have to preserve the \emph{Intermediate Value theorem}.

\textbf{Theorem} Suppose \(f\) is a real-valued differentiable function on \([a,b]\).
Then for every \(y\) value between \(f'(a)\) and \(f'(b)\), there exists an \(x\) in \([a,b]\) such that \(f'(x) = y\).

What does that imply?
It simply implies that our function has to be either continuous or if there is any form of discontinuity, either \textbf{right-hand-side} or \textbf{left-hand-side}, or both limits of that point should not be defined
(as with our function at \(x = 0\)).
\footnote{This kind of discontinuity is referred to as \emph{the second type} discontinuity compared to more well-known \emph{first type} like "jumps" in graphs.}

Now \emph{how much} discontinuous a derivative function can be?
For example, the following function:

\begin{equation}
\[
f(x) =
     \begin{cases}
       \equation{1} &\quad\text{if }\equation{x} \text{ rational} \\
       \equation{0} &\quad\text{if }\equation{x} \text{ irrational} \\
     \end{cases}
\]
\end{equation}

Has second type discontinuity at every point \(x\) in \(\mathbb{R}\).
Can this function be a derivative function?
The answer is \emph{no}, because all derivative functions are said to be of \emph{Baire class 1 functions} (also written as "Baire-1 function") in topology.
And there are restrictions on how much discontinuous Baire-1 functions can be.
Let's first define what Baire-1 functions are.

\section{Baire-1 functions}
\label{sec:orgdcde0a7}
Baire-1 function that we mentioned in the previous section, has the following definition:
\footnote{This section requires familiarity with functional sequences and pointwise convergence mean. I highly recommend to watch "Functional sequences (Part 1 of 2)" by Rob Shone on YouTube; here I assume you already know what these terms mean}

\textbf{Def.} If $$f(x) = \lim_{n\to\infty}{f_n(x)}$$ exists (as a real number) for each $$x \in \mathbb{R}$$, then the function $$f$$ is Baire-1 function.

Derivative functions are Baire-1 class functions, because from elementary Calculus we know that:

\begin{equation}
  f'(x) = \lim_{h\to0} \frac{f(x + h) - f(x)}{h}
\end{equation}

Now we have to express it in form of infinite sum. Therefore:

\begin{equation}
  f'(x) = \lim_{n\to\infty} \frac{f(x + \frac{1}{n}) - f(x)}{\frac{1}{n}}
\end{equation}

\begin{equation}
  f'(x) = \lim_{n\to\infty} n [f(x + \frac{1}{n}) - f(x)]
\end{equation}

Lastly just naming the whole expression on the right-hand-side as \(f_n(x)\), we get:

\begin{equation}
  f'(x) = \lim_{n\to\infty} {f_n(x)}
\end{equation}

and $$f_n(x)$$ is continuous for n $$=$$ 1, 2, 3, \ldots{} because our assumption was that \(f\) is differentiable at all points and that, implies continuity at all points as well.

Now, we only need to mention one theorem until we can answer our original question. But before that, we first have to define some terminologies.

\emph{Topoligcal space}: This term has a rigorous definition in mathematics, but here, we are interseted is a specific example of topological space namely "metric space".
Real numbers are a form of metric space.

Next we have the following definitions:

\emph{Closure}: a subset $$S$$ of points in a topological space consists of all points in \(S\) together with all limit points of \(S\) (points that are arbitrarily close).

\emph{Nowhere dense subset}: A subset of a topological space is called "nowhere dense" if its closure has empty interior.
For instance, the integers are nowhere dense in real numbers.

\emph{Dense subset}:  subset \(A\) of a topological space \(X\) is dense, if every point x in X either belongs to A or is a limit point of A (points that are arbitrarily close).
For instance, the rational numbers are a dense subset of the real numbers because every real number either is a rational number or has a rational number arbitrarily close to it.

\emph{Meagre set} or first category: is a set that is a subset of a usually larger set, and it is negligible compared to that (larger) set.
Mathematically it is defined as \emph{a set countable union of nowhere dense sets}.

An example of a meagre set is Contor set with respect to the real numbers.
This set is constructed as below:

\begin{enumerate}
\item Take the interval of [1,0] and divide it into 3 pieces.
\item Remove the middle piece (excluding its endpoints).
\item Leave the union of the two remaining parts (\([0,\frac{1}{3}] \cup [\frac{2}{3},1]\))
\item \textbf{Indefinitely} repeat the 2nd and 3rd step of each remaining part.

Contruction of a Cantor set is visualized as below:

\begin{figure}[htbp]
\centering
\includegraphics[width=.9\linewidth]{./img/figure3.png}
\caption{\label{fig:org10ba7a6}}
\end{figure}

\emph{Non-meagre set} or second category: a set that is not meagre.

\textbf{Def.} \emph{Residual set}: The complement of a meagre set is called residual set; in other words, what is left of a (larger) set after removing the meagre sets.
\end{enumerate}

\section{Baire-Osgood theorem}
\label{sec:org77ec466}

Finally, we shall mention a theorem that would answer our original question.

\textbf{Theorem} Let \(f\) be a \uline{Baire-1 function} on the \uline{complete metric space} \(X\). Then \(f\) is continuous on a \uline{residual subset} of \(X\).
\footnote{This theorem is a result of "Baire category theorem" and the proof can be found on N.L. Carothers, "Real Analysis" P. 183}

Therefore, if our function is differentiable everywhere, the derivative function should have a dense set of points where it is continouous.

And moreover:

\textbf{Theorem} Let \(f\) be a real-valued function on \(\mathbb{R}\). The set of points of discontinuity of \(f\) is of first category (meagre set) if and only if \(f\) is continuous at a dense set of points.

One thing to mention in the end is that even though discontinuity points are meagre set, a derivative function can be non-integrable in the classical definition of integral i.e. Riemann integral.
An example of such a function is called \emph{Volterra's function}.
This function is differentiable everywhere but it is discontiuous on a set of nowhere dense but positive measures.
Therefore, it is not Riemann integralable.
\end{document}