\newcommand{\specialcell}[2][c]{%
	\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}

\section{Model Description}

\subsection{Introduction}
$\theta_i = \theta_{i,d} + \theta_{i,0}$ positive angle is in the upward direction.
\begin{figure}[H]
	\centerline{
	\includegraphics[scale=0.5]{Figures/conn_panels5.pdf}}
	\caption{Frame and variable definitions for the system discussed here, where $N_p=2$.}
	\label{fig:flexNPanel}
\end{figure}
\subsection{Derivation of Equations of Motion - Kane's Method}

The choice of state variables and their respective chosen generalized speeds are:

\begin{equation}
	\bm X =
	\begin{bmatrix}
		\bm r_{B/N}\\
		\bm \sigma_{\cal{B/N}}\\
		\theta_1\\
		\cdot\\
		\theta_{N_p}
	\end{bmatrix}
	\quad
	\bm u = \begin{bmatrix}
		\dot{\bm r}_{B/N}\\
		\bm \omega_{\cal{B/N}}\\
		\dot{\theta}_1\\
		\cdot\\
		\dot{\theta}_{N_p}
	\end{bmatrix}
\end{equation}
To create the partial velocity table, some velocities first need to be defined

\begin{equation}
	\dot{\bm r}_{B/N} = \dot{\bm r}_{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}
	\bm \omega_{\cal S_{\textit{i}/N}} = \bm \omega_{\cal{B/N}} + \Big(\sum_{k=1}^{i} \dot{\theta}_k \Big) \bm{\hat{s}}_{i,2}
\end{equation}

\begin{equation}
	\label{eq:rsin}
	\bm r_{S_{i}/N} = \bm r_{B/N} + \bm r_{S_{i}/B} = \bm r_{B/N} + \bm r_{H/B} - [d\bm{\hat{s}}_{i,1} + \sum_{n=1}^{i-1} 2d\bm{\hat{s}}_{n,1} ]
\end{equation}

\begin{equation}
	\label{eq:rsindot}
	\dot{\bm r}_{S_{i}/N} = \dot{\bm r}_{B/N} + {\bm r}'_{S_{i}/B} + \bm \omega_{\cal{B/N}} \times {\bm r}_{S_{i}/B} = \dot{\bm r}_{B/N} + d\Big[\Big(\sum_{k=1}^{i} \dot{\theta}_k \Big) \bm{\hat{s}}_{i,3} + \sum_{n=1}^{i-1} 2\bm{\hat{s}}_{n,3}\Big(\sum_{k=1}^{n} \dot{\theta}_k \Big) \Big]  - [\tilde{{\bm r}}_{S_{i}/B}] \bm \omega_{\cal{B/N}}
\end{equation}
Where
\begin{equation}
	\label{eq:sijp}
	\hat{\bm s}'_{i,j} = \bm\omega_{\cal{S}_{\textit{i}}/\cal{B}}\times\hat{\bm s}_{i,j}=\Big(\sum_{k=1}^{i} \dot{\theta}_k \Big)\hat{\bm s}_{i,2}\times\hat{\bm s}_{i,j}
\end{equation}
is used to get the derivative.\\
The summation in equation \ref{eq:rsin} and \ref{eq:rsindot} can be out of bounds for certain values of $i$. When this occurs, the summation becomes equal to zero. $\bm c$ is defined as the position vector between the body frame and the COM of the system:
\begin{equation}
	\bm c = \frac{1}{m_{sc}}\Big[ \sum_{i=1}^{N_p} m_p {\bm r}_{S_i/B}\Big]
\end{equation}
\begin{equation}
	\dot{\bm c} = {\bm c}' - [\tilde{\bm c}]{\bm \omega}_{\cal{B/N}}
\end{equation}
\begin{equation}
	{\bm c}' = \frac{m_p d}{m_{sc}} \sum_{i=1}^{N_p} \Big[\Big(\sum_{k=1}^{i} \dot{\theta}_k \Big) \bm{\hat{s}}_{i,3} + \sum_{n=1}^{i-1} 2\bm{\hat{s}}_{n,3}\Big(\sum_{k=1}^{n} \dot{\theta}_k \Big) \Big]
	\label{eq:cprime1}
\end{equation}
\begin{equation}
	{\bm c}' = \frac{m_p d}{m_{sc}} \Big[\sum_{i=1}^{N_p} \dot{\theta}_i  \sum_{n=i}^{N_p} (2[N_p - n]+1 )\bm{\hat{s}}_{n,3}\Big]
	\label{eq:cprime2}
\end{equation}
Now the following partial velocity table can be created (here: $j = r-6$):

\begin{table}[H]
	\caption{Partial Velocity Table}
	\label{tab:hub}
	\centering \fontsize{10}{10}\selectfont
	\begin{tabular}{ |c | c | c | c | c | c |} % Column formatting,
		\hline
		$r$ & $\bm v^{C}_{r}$ & $\bm v^{B}_{r}$  & $\bm \omega_{\textit{r}}^{\cal{B}}$ & $\bm v^{S_i}_{r}$ & $\bm \omega_{\textit{r}}^{\cal{S}_\textit{i}}$ \\
		\hline \hline
		$1-3$ & $[I_{3\times 3}]$ & $[I_{3\times 3}]$ & $[0_{3\times 3}]$ & $ [I_{3\times 3}]$ & $[0_{3\times 3}]$ \\ \hline
		$4-6$ & $-[\tilde{\bm c}]$ & $[0_{3\times 3}]$ & $[I_{3\times 3}]$ & $ - [\tilde{{\bm r}}_{S_{i}/B}]$ & $[I_{3\times 3}]$ \\ \hline
		$7-{N_p}$ & $\sum_{n=j}^{N_p} (2[N_p - n]+1 )\bm{\hat{s}}_{n,3} $ & $[0_{3\times 1}]$ & $[0_{3\times 1}]$ & \specialcell{if $j \leq i$ : \\ $d [\bm{\hat{s}}_{i,3} + \sum^{i-1}_{n=j} 2\bm{\hat{s}}_{n,3}] $ \\ else:\\ $[0_{3\times 1}]$\\  }& \specialcell{if $j \leq i$ : \\ $\bm{\hat{s}}_{i,2} $ \\ else:\\ $[0_{3\times 1}]$} \\
		\hline
	\end{tabular}
\end{table}
Using these partial velocity definitions, the follow sections will step through the formulation for the translational, rotational and panel EOMs developed using Kane's method.

\subsubsection{Hub Translational Motion}
Starting with the definition of a generalized force:

\begin{equation}
	\bm F_r = \sum\limits_{r}^{N} \bm v_r^T \bm F
	\label{eq:genActive}
\end{equation}
Using this definition the external force applied on the system 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/N}) + \sum\limits_{i=1}^{N_p}[\bm v^{S_i}_{1-3}]^T (-m_{\text{p}_i} \ddot{\bm r}_{S_{i}/N}) = -m_{\text{hub}} \ddot{\bm r}_{B/N} + \sum\limits_{i=1}^{N_p} -m_{\text{p}_i}\ddot{\bm r}_{S_{i}/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/N} + \sum\limits_{i=1}^{N_p} -m_{\text{p}_i}\ddot{\bm r}_{S_{i}/N} = 0
\end{equation}
Expanding and rearranging results in
\begin{equation}
	m_{\text{hub}} \ddot{\bm r}_{B/N}  + \sum\limits_{i=1}^{N_p} m_{\text{p}} (\ddot{\bm r}_{B/N} + \ddot{\bm r}_{S_{i}/B}) = \bm F_{\text{ext}}
	\label{eq:KanesTrans}
\end{equation}
Where
\begin{equation}
	\ddot{\bm r}_{S_i/B} = \bm{r}''_{S_i/B} + 2 \bm\omega_{\cal B/N} \times \bm{r}'_{S_i/B} +  \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{S_i/B} + \bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{S_i/B})
	\label{eq:rsddot}
\end{equation}
Plugging Eq.~\eqref{eq:rsddot} into Eq.~\eqref{eq:KanesTrans} results in
\begin{multline}
	m_{\text{hub}} \ddot{\bm r}_{B/N} +  \sum\limits_{i=1}^{N_p} m_{\text{p}} \Big[\ddot{\bm r}_{B/N} +  \bm{r}''_{S_i/B}
	+ 2 \bm\omega_{\cal B/N} \times \bm{r}'_{S_i/B} +  \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{S_i/B}
	\\ + \bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{S_i/B})\Big] = \bm F_{\text{ext}}
\end{multline}
The body frame derivative can be written explicitly using the simplification used in Eqs. \ref{eq:cprime1} and \ref{eq:cprime2} (this simplification only works when $\bm{r}''_{S_i/B}$ is summed over all panels)
\begin{equation}
	m_{\text{p}} \sum^{N_p}_{i=1} \bm{r}''_{S_i/B} = \sum^{N_p}_{i=1} \Big[ \ddot{\theta}_i \sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3} + \Big(\sum^{i}_{k=1}\dot{\theta}_k\Big)^2 (2[N_p-i]+1) d m_{\text{p}} \bm{\hat{s}}_{i,1} \Big]
\end{equation}
Combining like terms and rearranging results in
\begin{multline}
	m_{\textnormal{sc}} \ddot{\bm r}_{B/N}-m_{\textnormal{sc}} [\tilde{\bm{c}}]\dot{\bm\omega}_{\cal B/N}+\sum^{N_p}_{i=1} \Big[ \sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3}\Big] \ddot{\theta}_i = \bm F_{\textnormal{ext}} - 2 m_{\textnormal{sc}} [\tilde{\bm\omega}_{\cal B/N}]\bm{c}'\\
	- m_{\textnormal{sc}} [\tilde{\bm\omega}_{\cal B/N}][\tilde{\bm\omega}_{\cal B/N}]\bm{c}-\sum^{N_p}_{i=1} \Big[ \Big(\sum^{i}_{k=1}\dot{\theta}_k\Big)^2 (2[N_p-i]+1) d m_{\text{p}} \bm{\hat{s}}_{i,1} \Big]
	\label{eq:Rbddot4}
\end{multline}

\subsubsection{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:

\begin{equation}
	\bm T^* = -[I_c] \dot{\bm\omega}  -[\bm{\tilde{\omega}}] [I_c] \bm\omega
\end{equation}
\begin{multline}
	\bm F^*_{4-6} = [\bm \omega_{4-6}^{\cal{B}}]^T \bm T^*_{\text{hub}} + [\bm v^{B}_{4-6}]^T (-m_{\text{hub}} \ddot{\bm r}_{B/N}) + \sum\limits_{i=1}^{N_p}\bigg([\bm v^{S_i}_{4-6}]^T (-m_{\text{p}} \ddot{\bm r}_{S_{i}/N}) + [\bm \omega_{\text{4-6}}^{\cal{S}_\textit{i}}]^T \bm T^*_{\text{p}_i}\bigg) \\
	= -[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} \\
	+ \sum\limits_{i}^{N_p}\bigg(- m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \ddot{\bm r}_{S_{i}/N} -[I_{\text{p}_i,S_i}] \dot{\bm\omega}_{\cal S_{\textit{i}/N}}  -[\bm{\tilde{\omega}}_{\cal S_{\textit{i}/N}}] [I_{\text{p}_i,S_i}] \bm\omega_{\cal S_{\textit{i}/N}}\bigg)
\end{multline}
Using Kane's equation, Eq.~\eqref{eq:KanesEq}, the following equations of motion for the rotational dynamics are defined:

\begin{multline}
	\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}\\ + \sum\limits_{i}^{N_p}\bigg(- m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \ddot{\bm r}_{S_{i}/N} -[I_{\text{p}_i,S_i}] \dot{\bm\omega}_{\cal S_{\textit{i}/N}}  -[\bm{\tilde{\omega}}_{\cal S_{\textit{i}/N}}] [I_{\text{p}_i,S_i}] \bm\omega_{\cal S_{\textit{i}/N}}\bigg) = 0
	\label{eq:rotKane}
\end{multline}

\begin{equation}
	\bm{\dot{\omega}}_{\cal S_{\textit{i}/N}} = \dot{\bm\omega}_{\cal B/N} + \sum^{i}_{k=i} \ddot{\theta}_k  \bm{\hat{s}}_{i,1} + \sum^{i}_{k=i} \dot{\theta}_k (\bm\omega_{\cal B/N} \times \bm{\hat{s}}_{i,2})
	\label{eq:omegasidot}
\end{equation}
Plugging Eq. (\ref{eq:omegasidot}) into Eq. (\ref{eq:rotKane})

\begin{multline}
	\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} \\
	+ \sum\limits_{i=1}^{N_p}\bigg(- m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \ddot{\bm r}_{S_{i}/N} -[I_{\text{p}_i,S_i}] \dot{\bm\omega}_{\cal B/N} - I_{s_{i,2}} \sum^{i}_{k=i} \ddot{\theta}_k \bm{\hat{s}}_{i,2} + [I_{\text{p}_i,S_i}] \sum^{i}_{k=i} \dot{\theta}_k (\bm{\hat{s}}_{i,2} \times \bm\omega_{\cal B/N}) \\-[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{p}_i,S_i}] \bm\omega_{\cal B/N}
	- [\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{p}_i,S_i}] \big(\sum^{i}_{k=i} \dot{\theta}_k \big) \bm{\hat{s}}_{i,2} -  \big(\sum^{i}_{k=i} \dot{\theta}_k \big) \bm{\hat{s}}_{i,2} \times [I_{\text{p}_i,S_i}] \bm\omega_{\cal B/N} \bigg) = 0
\end{multline}

\begin{multline}
	\bm L_B -[I_{\text{hub},B}] \dot{\bm\omega}_{\cal B/N} - \sum\limits_{i=1}^{N_p}[I_{\text{p}_i,S_i}] \dot{\bm\omega}_{\cal B/N} - \sum\limits_{i=1}^{N_p} I_{s_{i,2}}\sum^{i}_{k=i} \ddot{\theta}_k \bm{\hat{s}}_{i,2} -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{hub},B}] \bm\omega_{\cal B/N} - \sum\limits_{i=1}^{N_p}[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{p}_i,S_i}] \bm\omega_{\cal B/N} \\
	+ \sum\limits_{i=1}^{N_p}\bigg(- m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \Big[\ddot{\bm r}_{B/N} + \ddot{\bm r}_{S_{i}/B}\Big]
	- I_{s_{i,2}} \sum^{i}_{k=i} \dot{\theta}_k [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \\
	+ \sum^{i}_{k=i} \dot{\theta}_k \Big[I_{s_{i,1}}\bm{\hat{s}}_{i,1} \bm{\hat{s}}_{i,3}^T -  I_{s_{i,3}} \bm{\hat{s}}_{i,3} \bm{\hat{s}}_{i,1}^T\Big] \bm\omega_{\cal B/N} -  \sum^{i}_{k=i} \dot{\theta}_k \Big[I_{s_{i,3}}\bm{\hat{s}}_{i,1} \bm{\hat{s}}_{i,3}^T -  I_{s_{i,1}} \bm{\hat{s}}_{i,3} \bm{\hat{s}}_{i,1}^T\Big] \bm\omega_{\cal B/N} \bigg) = 0
\end{multline}
\begin{multline}
	\sum\limits_{i=1}^{N_p} - m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \bm r''_{S_{i}/B} = -m_{\text{p}} d \sum\limits_{i=1}^{N_p} \Bigg(\ddot{\theta}\sum\limits_{k=i}^{N_p}\Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]\bm{\hat{s}}_{k,3} \\
	+ \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] + \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]\bm{\hat{s}}_{i,1} \Bigg)
\end{multline}
\begin{multline}
	\bm L_B - m_{\text{sc}}[\tilde{\bm{c}}]\ddot{\bm r}_{B/N} -[I_{\text{hub},B}] \dot{\bm\omega}_{\cal B/N} - \sum\limits_{i=1}^{N_p}[I_{\text{sp}_i,S_i}] \dot{\bm\omega}_{\cal B/N} - \sum\limits_{i=1}^{N_p} \ddot{\theta}_i \sum^{N_p}_{k=i}I_{s_{k,2}} \bm{\hat{s}}_{k,2} -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{hub},B}] \bm\omega_{\cal B/N} \\
	- \sum\limits_{i=1}^{N_p}[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{p}_i,S_i}] \bm\omega_{\cal B/N}
	+ \sum\limits_{i=1}^{N_p}\bigg( - \ddot{\theta}\sum\limits_{k=i}^{N_p}\Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} \\
	- \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] + \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}
	- m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \Big[
	2 \bm\omega_{\cal B/N} \times \bm{r}'_{S_i/B} +  \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{S_i/B}
	\\
	+ \bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{S_i/B})\Big]
	- I_{s_{i,2}} \sum^{i}_{k=i} \dot{\theta}_k [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \\
	-\sum^{i}_{k=i} \dot{\theta}_k (I_{s_{i,3}}-I_{s_{i,1}})(\hat{\bm s}_{i,1}\hat{\bm s}_{i,3}^{T}+\hat{\bm s}_{i,3}\hat{\bm s}_{i,1}^{T}) \bm\omega_{\cal B/N} \bigg) = 0
\end{multline}

\begin{multline}
	\bm L_B - m_{\text{sc}}[\tilde{\bm{c}}]\ddot{\bm r}_{B/N} -[I_{\text{sc},B}] \dot{\bm\omega}_{\cal B/N} - \sum\limits_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i}I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \sum\limits_{k=i}^{N_p}\Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} \Big] \ddot{\theta}_i \\
	-[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{sc},B}] \bm\omega_{\cal B/N}
	+ \sum\limits_{i=1}^{N_p}\bigg(- 2 m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \Big[\bm\omega_{\cal B/N} \times \bm{r}'_{S_i/B}\Big] -\big(\sum^{i}_{k=1}\dot{\theta}_k\big)(I_{s_{i,3}}-I_{s_{i,1}})(\hat{\bm s}_{i,1}\hat{\bm s}_{i,3}^{T}+\hat{\bm s}_{i,3}\hat{\bm s}_{i,1}^{T}) \bm\omega_{\cal B/N} \\
	- \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] + \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}
	- I_{s_{i,2}} \big(\sum^{i}_{k=1}\dot{\theta}_k\big) [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \bigg) = 0
\end{multline}
Moving things to the correct sides
\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_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i}I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \sum\limits_{k=i}^{N_p}\Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} \Big] \ddot{\theta}_i \\
	= -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{sc},B}] \bm\omega_{\cal B/N} - \sum\limits_{i=1}^{N_p}\bigg(2 m_{\text{p}} [\tilde{{\bm r}}_{S_{i}/B}] \Big[\bm\omega_{\cal B/N} \times \bm{r}'_{S_i/B}\Big] + \big(\sum^{i}_{k=1}\dot{\theta}_k\big)(I_{s_{i,3}}-I_{s_{i,1}})(\hat{\bm s}_{i,1}\hat{\bm s}_{i,3}^{T}+\hat{\bm s}_{i,3}\hat{\bm s}_{i,1}^{T}) \bm\omega_{\cal B/N} \\
	+ \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] + \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}
	+ I_{s_{i,2}} \big(\sum^{i}_{k=1}\dot{\theta}_k\big) [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \bigg) + \bm L_B
\end{multline}

\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_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i}I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \sum\limits_{k=i}^{N_p}\Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} \Big] \ddot{\theta}_i
	\\
	= -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{sc},B}] \bm\omega_{\cal B/N} - \sum\limits_{i=1}^{N_p}\bigg( - m_{\text{p}}\Big[[\bm{\tilde{r}}'_{S_i/B}] [\bm{\tilde{r}}_{S_i/B}] + [\bm{\tilde{r}}_{S_i/B}] [\bm{\tilde{r}}'_{S_i/B}]\Big] \bm\omega_{\cal B/N} \\
	+\big(\sum^{i}_{k=1}\dot{\theta}_k\big)(I_{s_{i,3}}-I_{s_{i,1}})(\hat{\bm s}_{i,1}\hat{\bm s}_{i,3}^{T}+\hat{\bm s}_{i,3}\hat{\bm s}_{i,1}^{T}) \bm\omega_{\cal B/N}
	+ m_{\text{p}} [\tilde{\bm\omega}_{\cal B/N}] [\tilde{{\bm r}}_{S_{i}/B}] \bm{r}'_{S_i/B} \\
	+ \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}]
	+ \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}
	+ I_{s_{i,2}} \big(\sum^{i}_{k=1}\dot{\theta}_k\big) [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \bigg) + \bm L_B
\end{multline}
End
\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_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i}I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \sum\limits_{k=i}^{N_p}\Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} \Big] \ddot{\theta}_i
	\\
	= -[\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_{i=1}^{N_p}\bigg( m_{\text{p}} [\tilde{\bm\omega}_{\cal B/N}] [\tilde{{\bm r}}_{S_{i}/B}] \bm{r}'_{S_i/B} \\
	+ \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] + \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}
	+ I_{s_{i,2}} \big(\sum^{i}_{k=1}\dot{\theta}_k\big) [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \bigg) + \bm L_B
	\label{eq:rotmot}
\end{multline}

\subsubsection{Panel Motions}
Following the similar pattern for translational and rotational equations the generalized active forces are defined, where $j=r-6$:

\begin{multline}
	\bm F_{r} = \bm \omega_{\textit{r}}^{\cal{S}_\textit{j}} \cdot (-k_j (\theta_j-\theta_{j,0}) \bm{\hat{s}}_{j,2} - c_j \dot{\theta}_j \bm{\hat{s}}_{j,2}  +k_{j+1} (\theta_{j+1}-\theta_{j+1,0}) \bm{\hat{s}}_{j,2} +c_{j+1} \dot{\theta}_{j+1} \bm{\hat{s}}_{j+1,2})\\
	+ 2d\bm{\hat{s}}_{j,3}\cdot(\bm F_{ext,j+1} - m_{\textit{conn},j}\bm{\ddot{r}_{\textit{conn},j}}) =
	-k_j (\theta_j-\theta_{j,0}) - c_j \dot{\theta}_j + k_{j+1} (\theta_{j+1}-\theta_{j+1,0}) + c_{j+1} \dot{\theta}_{j+1}\\
	+ 2d\bm{\hat{s}}_{j,3}\cdot(\bm F_{ext,j+1} - m_{\textit{conn},j}\bm{\ddot{r}_{\textit{conn},j}}) = \textit{K} + 2d\bm{\hat{s}}_{j,3}\cdot(\bm F_{ext,j+1} - m_{\textit{conn},j}\bm{\ddot{r}_{\textit{conn},j}})
\end{multline}
Where $m_{\textit{conn},j}$ and $\bm{\ddot{r}_{\textit{conn},j}}$ are the mass and acceleration of the connected panels after the jth panel, and:
\begin{equation}
	K= -k_j (\theta_j-\theta_{j,0}) - c_j \dot{\theta}_j + k_{j+1} (\theta_{j+1}-\theta_{j+1,0}) + c_{j+1} \dot{\theta}_{j+1}
\end{equation}
The generalized inertia forces are defined as:
\begin{multline}
	\bm F^*_{r} = \bm \omega_{\textit{r}}^{\cal{S}_\textit{j}} \cdot \bm T^*_{\text{p}_j}  +\bm v^{S_j}_{r} \cdot (-m_{\text{p}} \ddot{\bm r}_{S_{j}/N}) = \\ % + \bm v^{C}_{r} \cdot (-m_{\text{p}} \ddot{\bm r}_{C/N})
	\bm \omega_{\textit{r}}^{\cal{S}_\textit{j}} \cdot \Big[-[I_{\text{p}_j,S_j}] \dot{\bm\omega}_{\cal S_{\textit{j}/N}}  -[\bm{\tilde{\omega}}_{\cal S_{\textit{j}/N}}] [I_{\text{p}_j,S_j}] \bm\omega_{\cal S_{\textit{j}/N}} \Big] + \bm v^{S_j}_{r} \cdot (-m_{\text{p}} \ddot{\bm r}_{S_{j}/N}) % + \bm v^{C}_{r} \cdot (-m_{\text{sc}} \ddot{\bm r}_{C/N})
\end{multline}
Using Kane's equation the following equations of motion are defined:
\begin{multline}
	\textit{K} + 2d\bm{\hat{s}}_{j,3}\cdot(\bm F_{ext,j+1} - m_{\textit{conn},j}\bm{\ddot{r}_{\textit{conn},j}}) + \bm{\hat{s}}_{i,2} \cdot \Big[-[I_{\text{p}_i,S_i}] \dot{\bm\omega}_{\cal S_{\textit{i}/N}}  -[\bm{\tilde{\omega}}_{\cal S_{\textit{i}/N}}] [I_{\text{p}_i,S_i}] \bm\omega_{\cal S_{\textit{i}/N}} \Big]\\
	+ d\bm{\hat{s}}_{j,3} \cdot (-m_{\text{p}} \ddot{\bm r}_{S_{j}/N}) = 0 % + (2[N_p - i]+1 )\bm{\hat{s}}_{i,3} \cdot (-m_{\text{sc}} \ddot{\bm r}_{C/N}) \Bigg)
	\label{eq:afterkane}
\end{multline}
Defining the inertial derivative:
\begin{equation}
	\dot{\bm \omega}_{\mathcal{S}_{j}/\mathcal{N}} = \dot{\bm \omega}_{\cal{B/N}} + \sum^{N_p}_{i=1}\ddot{\theta}_{i} \hat{\bm s}_{j,2} + \sum^{N_p}_{i=1}\dot{\theta}_{i} \bm \omega_{\cal{B/N}} \times \hat{\bm s}_{j,2}
\end{equation}
Which can be plugged into Eq. (\ref{eq:afterkane}):
\begin{multline}
	\textit{K} - I_{s_j,2} \bm{\hat{s}}_{j,2}^T \dot{\bm\omega}_{\cal B/N} - I_{s_j,2} \sum^{N_p}_{i=1}\ddot{\theta}_i - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}}\\
	+ 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1} - 2d\bm{\hat{s}}^{T}_{j,3}\sum^{N_p}_{i=j+1}m_{\text{p}} \ddot{\bm r}_{S_{i}/N} - d\bm{\hat{s}}^{T}_{j,3} m_{\text{p}} \ddot{\bm r}_{S_{j}/N} = 0 %- m_{\text{sc}} (2[N_p - i]+1 )\bm{\hat{s}}_{i,3} \cdot  [\ddot{\bm r}_{B/N} + \ddot{\bm c}] \Bigg)
\end{multline}

\begin{multline}
	\textit{K} - I_{s_j,2} \bm{\hat{s}}_{j,2}^T \dot{\bm\omega}_{\cal B/N} - I_{s_j,2} \sum^{N_p}_{i=1}\ddot{\theta}_i - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}}\\
	+ 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1} - 2d\bm{\hat{s}}^{T}_{j,3}\sum^{N_p}_{i=j+1}m_{\text{p}} [\ddot{\bm r}_{B/N} + \ddot{\bm r}_{S_{i}/B}] - d\bm{\hat{s}}^{T}_{j,3} m_{\text{p}} [\ddot{\bm r}_{B/N} + \ddot{\bm r}_{S_{j}/B}] = 0 %- m_{\text{sc}} (2[N_p - i]+1 )\bm{\hat{s}}_{i,3} \cdot  [\ddot{\bm r}_{B/N} + \ddot{\bm c}] \Bigg)
\end{multline}

\begin{multline}
	\textit{K} - [d\bm{\hat{s}}^{T}_{j,3}+\sum^{N_p}_{i=j+1}2d\bm{\hat{s}}^{T}_{j,3}]\ddot{\bm r}_{B/N} - I_{s_j,2} \bm{\hat{s}}_{j,2}^T \dot{\bm\omega}_{\cal B/N} - I_{s_j,2} \sum^{N_p}_{i=1}\ddot{\theta}_i - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}}\\
	+ 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1} - 2d\bm{\hat{s}}^{T}_{j,3}\sum^{N_p}_{i=j+1}m_{\text{p}} [\bm r''_{S_{i}/B}+ 2 \bm\omega_{\cal B/N} \times \bm{r}'_{S_i/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{S_i/B}
	+ \bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{S_i/B})\Big] \\ - d\bm{\hat{s}}^{T}_{j,3} m_{\text{p}} [\bm r''_{S_{j}/B}+ 2 \bm\omega_{\cal B/N} \times \bm{r}'_{S_j/B} + \dot{\bm\omega}_{\cal B/N} \times \bm{r}_{S_j/B}
	+ \bm\omega_{\cal B/N} \times (\bm\omega_{\cal B/N} \times \bm{r}_{S_j/B})\Big] = 0 %- m_{\text{sc}} (2[N_p - i]+1 )\bm{\hat{s}}_{i,3} \cdot  [\ddot{\bm r}_{B/N} + \ddot{\bm c}] \Bigg)
\end{multline}
\begin{multline}
	\textit{K} - \Big[d m_p\bm{\hat{s}}^{T}_{j,3}+\sum^{N_p}_{i=j+1}2 d m_p\bm{\hat{s}}^{T}_{j,3}\Big]\ddot{\bm r}_{B/N} - \Big[I_{s_j,2} \bm{\hat{s}}_{j,2}^T -m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]-\sum^{N_p}_{i=j+1} 2 m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]\Big]\dot{\bm\omega}_{\cal B/N} \\
	-I_{s_j,2} \sum^{N_p}_{i=1}\ddot{\theta}_i - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}}+ 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1}
	-m_p d \hat{s}^{T}_{j,3}[\bm r''_{S_{j}/B} + \sum^{N_p}_{i=1} 2 \bm r''_{S_{i}/B}]\\
	-m_p d \hat{s}^{T}_{j,3}\Big[2[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + [\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B}\\
	+\sum^{N_p}_{i=j+1}\Big(4[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B}
	+ 2[\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B} \Big)\Big] = 0
\end{multline}
The $\bm r''_{S_{j}/B}$ terms contain $\ddot{\theta}$ terms and thus need to be rewritten to a usable form. This is done by writing it out for several panels and finding a pattern, the result of this is shown next:
\begin{multline}
	\textit{K} - \Big[d m_p\bm{\hat{s}}^{T}_{j,3}+\sum^{N_p}_{i=j+1}2 d m_p\bm{\hat{s}}^{T}_{j,3}\Big]\ddot{\bm r}_{B/N} - \Big[I_{s_j,2} \bm{\hat{s}}_{j,2}^T -m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]-\sum^{N_p}_{i=j+1} 2 m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]\Big]\dot{\bm\omega}_{\cal B/N} \\
	-I_{s_j,2} \sum^{N_p}_{i=1}\ddot{\theta}_i - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}}+ 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1}\\
	-m_p d \hat{s}^{T}_{j,3}\Big[2[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + [\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B}+\sum^{N_p}_{i=j+1}\Big(4[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + 2[\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B} \Big)\Big]\\
	-m_p d^2 \hat{s}^{T}_{j,3}\sum^{N_p}_{i=1}\Big[\ddot{\theta}_i \sum^{N_p}_{k=i}(2\hat{s}_{k,3}+4\hat{s}_{k,3}(N_p-j) -H[k-j] 4\hat{s}_{k,3}(k-j)) - H[j-i]\hat{s}_{j,3} + \\
	\Big( \sum^{i}_{n=1} \dot{\theta}\Big)^2 (2\hat{s}_{i,1}+4\hat{s}_{i,1}(N_p-j) -H[i-j] 4\hat{s}_{i,1}(i-j) - \Big( \sum^{i}_{n=1} \dot{\theta}_i\Big)^2 \hat{s}_{j,1} ) \Big] = 0
\end{multline}
This finally leads to:
\begin{multline}
	\Big[d m_p\bm{\hat{s}}^{T}_{j,3}+\sum^{N_p}_{i=j+1}2 d m_p\bm{\hat{s}}^{T}_{j,3}\Big]\ddot{\bm r}_{B/N} + \Big[I_{s_j,2} \bm{\hat{s}}_{j,2}^T -m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]-\sum^{N_p}_{i=j+1} 2 m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]\Big]\dot{\bm\omega}_{\cal B/N} +\\
	\sum^{N_p}_{i=1}\Big[I_{s_j,2} H[j-i] + m_p d^2 \hat{s}^{T}_{j,3} \sum^{N_p}_{k=i}(2\hat{s}_{k,3}+4\hat{s}_{k,3}(N_p-j) -H[k-j] 4\hat{s}_{k,3}(k-j)) - H[j-i]\hat{s}_{j,3} \Big] \ddot{\theta}_i\\
	= K + 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1} - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}} - m_p d \hat{s}^{T}_{j,3}\Big[2[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + [\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B}+\\
	\sum^{N_p}_{i=j+1}\Big(4[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + 2[\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B} \Big) \\
	+ \Big( \sum^{i}_{n=1} \dot{\theta}_i \Big)^2 (2\hat{s}_{i,1}+4\hat{s}_{i,1}(N_p-j) -H[i-j] 4\hat{s}_{i,1}(i-j) - \Big( \sum^{i}_{n=1} \dot{\theta}_i\Big)^2 \hat{s}_{j,1} )\Big]
	\label{eq:flexr}
\end{multline}
Where $H[x]$ is the Heaviside function.

\subsection{Back Substitution Method}
The Back substitution method is used to gain a simpler expression that combines the three equations of motion. First, Eq.~\eqref{eq:flexr} is rearranged so that the second order state variables for the panel motions are isolated on the left hand side:
\begin{multline}
	\sum^{N_p}_{i=1}\Big[I_{s_j,2} H[j-i] + m_p d^2 \hat{s}^{T}_{j,3} \sum^{N_p}_{k=i}(2\hat{s}_{k,3}+4\hat{s}_{k,3}(N_p-j) -H[k-j] 4\hat{s}_{k,3}(k-j)) - H[j-i]\hat{s}_{j,3} \Big] \ddot{\theta}_i \\
	= - \Big[d m_p\bm{\hat{s}}^{T}_{j,3}+\sum^{N_p}_{i=j+1}2 d m_p\bm{\hat{s}}^{T}_{j,3}\Big]\ddot{\bm r}_{B/N} - \Big[I_{s_j,2} \bm{\hat{s}}_{j,2}^T -m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]-\sum^{N_p}_{i=j+1} 2 m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]\Big]\dot{\bm\omega}_{\cal B/N} \\
	+ K + 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1} - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}} - m_p d \hat{s}^{T}_{j,3}\Big[2[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + [\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B}\\
	+\sum^{N_p}_{i=j+1}\Big(4[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + 2[\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B} \Big) \\
	+ \Big( \sum^{i}_{n=1} \dot{\theta}_i \Big)^2 (2\hat{s}_{i,1}+4\hat{s}_{i,1}(N_p-j) -H[i-j] 4\hat{s}_{i,1}(i-j) - \Big( \sum^{i}_{n=1} \dot{\theta}_i\Big)^2 \hat{s}_{j,1} )\Big]
	\label{eq:spMotion1}
\end{multline}
Now, defining the elements of a matrix $[A]$ as:
\begin{equation}
	a_{j,i} = I_{s_j,2} H[j-i] + m_p d^2 \hat{s}^{T}_{j,3} \sum^{N_p}_{k=i}\Big(2\hat{s}_{k,3}+4\hat{s}_{k,3}(N_p-j) -H[k-j] 4\hat{s}_{k,3}(k-j)\Big) - H[j-i]\hat{s}_{j,3}
\end{equation}
And defining the row elements of a matrix $[F]$ as:
\begin{equation}
	\bm f_{j,1} =  - [d m_p \bm{\hat{s}}^{T}_{j,3}+\sum^{N_p}_{i=j+1}2 d m_p\bm{\hat{s}}^{T}_{j,3}]
\end{equation}
With a matrix $[G]$ which has row elements defined as:
\begin{equation}
	\bm g_{j,1} =  -[I_{s_j,2} \bm{\hat{s}}_{j,2}^T -m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]-\sum^{N_p}_{i=j+1} 2 m_p d \hat{s}^{T}_{j,3}[\tilde{{\bm r}}_{S_{i}/B}]
\end{equation}
Also defining the vector $\bm v$
\begin{multline}
	\bm v_{j,1} =  K + 2d\bm{\hat{s}}^{T}_{j,3}\bm F_{ext,j+1} - \left( I_{s_{j,1}} - I_{s_{j,3}}\right) \omega_{s_{j,3}} \omega_{s_{j,1}} - m_p d \hat{s}^{T}_{j,3}\Big[2[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + [\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B}\\
	+\sum^{N_p}_{i=j+1}\Big(4[\bm{\tilde{\omega}}_{\cal B/N}]\bm r'_{S_{j}/B} + 2[\bm{\tilde{\omega}}_{\cal B/N}][\bm{\tilde{\omega}}_{\cal B/N}]\bm r_{S_{j}/B} \Big) \\
	+ \Big( \sum^{i}_{n=1} \dot{\theta}_i \Big)^2 (2\hat{s}_{i,1}+4\hat{s}_{i,1}(N_p-j) -H[i-j] 4\hat{s}_{i,1}(i-j) - \Big( \sum^{i}_{n=1} \dot{\theta}_i\Big)^2 \hat{s}_{j,1} )\Big]
\end{multline}
Eq.~\eqref{eq:spMotion1} can then be written in matrix form to utilize some linear algebra techniques.

\begin{equation}
	[A]\begin{bmatrix}
		\ddot \theta_{1}\\
		\vdots \\
		\ddot \theta_{N_p}
	\end{bmatrix}
	= [F] \ddot{\bm r}_{B/N} + [G]\dot{\bm\omega}_{\cal B/N} + \bm v
	\label{eq:thetadot}
\end{equation}
Eq.~\eqref{eq:thetadot} can now be solved by inverting matrix $[A]$. Note the definition $[E] = [A]^{-1}$.

\begin{equation}
	\begin{bmatrix}
		\ddot \theta_{1}\\
		\vdots \\
		\ddot \theta_{N_p}
	\end{bmatrix}
	= [E][F] \ddot{\bm r}_{B/N} + [E][G]\dot{\bm\omega}_{\cal B/N} + [E]\bm v
	\label{eq:thetadot2}
\end{equation}
And the subcomponents of $[E]$ are defined as

\begin{equation}
	[E] = \begin{bmatrix}
		\bm e_{1}^T\\
		\vdots \\
		\bm e_{N_p}^T
	\end{bmatrix}
	\label{eq:E}
\end{equation}
Since the modified Euler's equation, Eq.~\eqref{eq:rotmot}, has $\ddot \theta_{i}$ terms, it is more convenient to use the expression for $\ddot \theta_i$ as
\begin{equation}
	\ddot \theta_{i}
	= e_{i}^T[F] \ddot{\bm r}_{B/N} + e_{i}^T[G]\dot{\bm\omega}_{\cal B/N} + e_{i}^T\bm v
	\label{eq:thetadot4}
\end{equation}
The next step in the back substitution method is to analytically substitute Eq.~\eqref{eq:thetadot4} into the translational and rotational EOMs. Performing this substitution for translation yields:

\begin{multline}
	m_{\textnormal{sc}} \ddot{\bm r}_{B/N}-m_{\textnormal{sc}} [\tilde{\bm{c}}]\dot{\bm\omega}_{\cal B/N}+\sum^{N_p}_{i=1} \Big[ \sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3} [e_{i}^T[F] \ddot{\bm r}_{B/N} + e_{i}^T[G]\dot{\bm\omega}_{\cal B/N} + e_{i}^T\bm v] \Big] \\
	= \bm F_{\textnormal{ext}} - 2 m_{\textnormal{sc}} [\tilde{\bm\omega}_{\cal B/N}]\bm{c}'
	- m_{\textnormal{sc}} [\tilde{\bm\omega}_{\cal B/N}][\tilde{\bm\omega}_{\cal B/N}]\bm{c}-\sum^{N_p}_{i=1} \Big[ \Big(\sum^{i}_{k=1}\dot{\theta}_k\Big)^2 (2[N_p-i]+1) d m_{\text{p}} \bm{\hat{s}}_{i,1} \Big]
	\label{eq:Rbddot5}
\end{multline}
Combining like terms yields:

\begin{multline}
	\Bigg \lbrace m_{\textnormal{sc}}[I_{3\times 3}] + \sum^{N_p}_{i=1} \Big[\sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3}\Big] e_{i}^T[F] \Bigg \rbrace \ddot{\bm r}_{B/N}
	\\
	+ \Bigg \lbrace -m_{\textnormal{sc}} [\tilde{\bm{c}}]  + \sum^{N_p}_{i=1} \Big[\sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3}\Big] e_{i}^T[G]\Bigg \rbrace \dot{\bm\omega}_{\cal B/N}\\
	=  \bm F_{\textnormal{ext}} - 2 m_{\textnormal{sc}} [\tilde{\bm\omega}_{\cal B/N}]\bm{c}'
	- m_{\textnormal{sc}} [\tilde{\bm\omega}_{\cal B/N}][\tilde{\bm\omega}_{\cal B/N}]\bm{c}-\sum^{N_p}_{i=1} \Big[ \Big(\sum^{i}_{k=1}\dot{\theta}_k\Big)^2 (2[N_p-i]+1) d m_{\text{p}} \bm{\hat{s}}_{i,1} \Big]\\
	- \sum^{N_p}_{i=1} \Big[\sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3} e_{i}^T \bm v \Big]
	\label{eq:Rbddot6}
\end{multline}
Substitution into the rotational equation of motion:
\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_{i=1}^{N_p} \Big[ \sum^{N_p}_{k=i} (I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \Big[ [\tilde{{\bm r}}_{S_{k}/B}] \\
	+ \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} ) [e_{i}^T[F] \ddot{\bm r}_{B/N} + e_{i}^T[G]\dot{\bm\omega}_{\cal B/N} + e_{i}^T\bm v]\Big]
	= -[\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_{i=1}^{N_p}\bigg( m_{\text{p}} [\tilde{\bm\omega}_{\cal B/N}] [\tilde{{\bm r}}_{S_{i}/B}] \bm{r}'_{S_i/B} + \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] + \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}\\
	+ I_{s_{i,2}} \big(\sum^{i}_{k=1}\dot{\theta}_k\big) [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \bigg) + \bm L_B
	\label{eq:Final7sub}
\end{multline}
And combining like terms yields:
\begin{multline}
	\Bigg \lbrace m_{\text{sc}} [\tilde{\bm{c}}] + \sum\limits_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i} (I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} ) e_{i}^T[F] \Big] \Bigg \rbrace \ddot{\bm r}_{B/N} \\
	+ \Bigg \lbrace [I_{\text{sc},B}] + \sum\limits_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i} (I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} ) e_{i}^T[G] \Big] \Bigg \rbrace \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_{i=1}^{N_p}\bigg( m_{\text{p}} [\tilde{\bm\omega}_{\cal B/N}] [\tilde{{\bm r}}_{S_{i}/B}] \bm{r}'_{S_i/B} + \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] \\
	+ \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}
	+ I_{s_{i,2}} \big(\sum^{i}_{k=1}\dot{\theta}_k\big) [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \bigg) + \bm L_B - \sum\limits_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i} (I_{s_{k,2}} \bm{\hat{s}}_{k,2} \\+ \Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} ) e_{i}^T \bm v \Big]
	\label{eq:Final8}
\end{multline}
With the following definitions:
\begin{equation}
	[A_{\text{contr}}] = \sum^{N_p}_{i=1} \Big[\sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3}\Big] e_{i}^T[F]
\end{equation}
\begin{equation}
	[B_{\text{contr}}] =  \sum^{N_p}_{i=1} \Big[\sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3}\Big] e_{i}^T[G]
\end{equation}
\begin{equation}
	\bm v_{\text{trans,contr}} = -\sum^{N_p}_{i=1} \Big[ \Big(\sum^{i}_{k=1}\dot{\theta}_k\Big)^2 (2[N_p-i]+1) d m_{\text{p}} \bm{\hat{s}}_{i,1} \Big]\\
	- \sum^{N_p}_{i=1} \Big[\sum^{N_p}_{k=i} (2[N_p-k]+1) d m_{\text{p}} \bm{\hat{s}}_{k,3} e_{i}^T \bm v \Big]
\end{equation}
\begin{equation}
	[C_{\text{contr}}] = \sum\limits_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i} (I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} ) \Big]e_{i}^T[F]
\end{equation}
\begin{equation}
	[D_{\text{contr}}] = \sum\limits_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i} (I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} )\Big] e_{i}^T[G]
\end{equation}
\begin{multline}
	[v_{\text{rot,contr}}] = - \sum\limits_{i=1}^{N_p}\bigg( m_{\text{p}} [\tilde{\bm\omega}_{\cal B/N}] [\tilde{{\bm r}}_{S_{i}/B}] \bm{r}'_{S_i/B} + \Big( \sum\limits_{k=1}^{i} \dot{\theta}\Big)^2 \Big[[\tilde{{\bm r}}_{S_{i}/B}] + \sum\limits_{n=i+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big] m_{\text{p}} d \bm{\hat{s}}_{i,1}\\
	+ I_{s_{i,2}} \big(\sum^{i}_{k=1}\dot{\theta}_k\big) [\bm{\tilde{\omega}}_{\cal B/N}] \bm{\hat{s}}_{i,2} \bigg)
	- \sum\limits_{i=1}^{N_p} \Big[\sum^{N_p}_{k=i} (I_{s_{k,2}} \bm{\hat{s}}_{k,2} + \Big[ [\tilde{{\bm r}}_{S_{k}/B}] + \sum\limits_{n=k+1}^{N_p}2[\tilde{{\bm r}}_{S_{n}/B}]\Big]m_{\text{p}} d \bm{\hat{s}}_{k,3} )\Big]  e_{i}^T \bm v
\end{multline}
The full back substitution matrices then become:
\begin{equation}
	[A]  = m_\text{sc} [I_{3\times 3}] + [A_{\text{contr}}]
\end{equation}\begin{equation}
	[B] = -m_\text{sc} [\tilde{\bm{c}}] + [B_{\text{contr}}]
\end{equation}\begin{equation}
	\bm v_{\text{trans}} = \bm F - 2m_\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} + \bm v_{\text{trans,contr}}
\end{equation}\begin{equation}
	[C] = m_{\text{sc}} + [C_{\text{contr}}]
\end{equation}\begin{equation}
	[D] =  [I_{\text{sc},B}] + [D_{\text{contr}}]
\end{equation}\begin{equation}
	\bm v_{\text{rot}} = -[\bm{\tilde{\omega}}_{\cal B/N}] [I_{\text{sc},B}] \bm\omega_{\cal B/N} - [I'_{\text{sc},B}] \bm\omega_{\cal B/N} + \bm{L}_B + \bm v_{\text{rot,contr}}
\end{equation}

This produces the following simplified equations:

\begin{equation}
	\begin{bmatrix}
		[A] & [B]\\
		[C] & [D]
	\end{bmatrix} \begin{bmatrix}
		\ddot{\bm r}_{B/N}\\
		\dot{\bm\omega}_{\cal B/N}
	\end{bmatrix} = \begin{bmatrix}
		\bm v_{\text{trans}}\\
		\bm v_{\text{rot}}
	\end{bmatrix}
\end{equation}

Solving the system-of-equations by

\begin{equation}
	\dot{\bm\omega}_{\cal B/N} = \Big([D] - [C]][A]^{-1}[B]\Big)^{-1}(\bm v_{\text{rot}} - [C][A]^{-1}\bm v_{\text{trans}})
	\label{eq:omegaDot}
\end{equation}

\begin{equation}
	\ddot{\bm r}_{B/N} = [A]^{-1} (\bm v_{\text{trans}} - [B]\dot{\bm\omega}_{\cal B/N})
	\label{eq:rBNDDot}
\end{equation}

Now Eq.~\eqref{eq:omegaDot} and ~\eqref{eq:rBNDDot} can be used to solve for $\dot{\bm\omega}_{\cal B/N}$ and $\ddot{\bm r}_{B/N}$. Once these second order state variables are solved for, Eq.~\eqref{eq:thetadot4} can be used to directly solve for $\ddot \theta_{i}$. This shows that the back substitution method can work seamlessly for interconnected bodies.


\documentclass[a4paper]{article}
\usepackage{graphics}
%%\usepackage[english,greek]{babel}
\setlength{\parindent}{0mm}
\setlength{\parskip}{1.8mm}
\newtheorem{definition}{Definition}
\newtheorem{theorem}{Theorem}
\newtheorem{proof}{Proof}
\title{Finite difference scheme for a Kirchoff thin plate with free edges}
%%\date{$28^{th}$ August, 2007}
\author{Daniel Tang}
%%\linespread{1.3}

\begin{document}
%%\selectlanguage{english}
\maketitle
The vibrations in a thin, isotropic, homogeneous plate can be described as
\[
\frac{\partial^2 u}{\partial t^2} = -\kappa^2 \nabla^2 \nabla^2 u
\]
where
\[
\kappa = \frac{EH^2}{12\rho(1-\nu^2)}
\]
where $E$ is the Youngs modulus of the material, $H$ is the thickness of the plate, $\rho$ is its density and $\nu$ is its Poisson ratio.

For free edges, we have the boundary conditions (along a left-hand edge):
\[
\frac{\partial^2u}{\partial x^2} + \nu \frac{\partial^2u}{\partial y^2} = 0
\]
and
\[
\frac{\partial^3u}{\partial x^3} + (2-\nu) \frac{\partial^3u}{\partial xy^2} = 0
\]
while at a corner
\[
\frac{\partial^2u}{\partial xy} = 0
\]
Boundary conditions for other edge orientations can be inferred by symmetry.

Using the notation $\partial_x$, $\partial_{xx}$ etc to mean the second order, central finite difference approximation of $\frac{\partial}{\partial x}$, $\frac{\partial^2}{\partial x^2}$ etc. and $\partial_{x+}$ and $\partial_{x-}$ to mean the second order, forward and backward finite difference respectively, we can express the thin plate equation as a finite difference scheme:
\[
\partial_{tt} u = -\kappa (\partial_{xx} + \partial_{yy})(\partial_{xx} + \partial_{yy})u
\]
The boundary conditions along a left-hand edge can be expressed
\begin{equation}
\partial_{xx}u + \nu \partial_{yy}u = 0
\label{boundary1}
\end{equation}
\begin{equation}
\partial_{x-}(\partial_{xx}u + (2-\nu)\partial_{yy}u) = 0
\label{boundary2}
\end{equation}
and at a bottom-left corner as
\begin{equation}
\partial_{x-y-}u = 0
\label{boundarycorner}
\end{equation}

\subsection{Laplacian finite difference at an edge}
At a left-hand edge, from equation \ref{boundary1} we have
\[
\partial_{xx} = - \nu \partial_{yy}
\]
so
\begin{equation}
\nabla^2 = \partial_{xx} + \partial_{yy} = (1-\nu)\partial_{yy}
\label{delta}
\end{equation}

Rearranging equation \ref{boundary2} gives
\[
\partial_{x-}(\nabla^2 + (1-\nu)\partial_{yy}) = 0
\]
so, at a left-hand edge
\begin{equation}
\partial_{x-}\nabla^2 = (1-\nu)\partial_{x-yy}
\end{equation}
but
\begin{equation}
\partial_{xx}\nabla^2 = \frac{\partial_{x+}\nabla^2 - \partial_{x-}\nabla^2}{\Delta x} = \frac{\partial_{x+}\nabla^2 - (1-\nu)\partial_{x-yy}}{\Delta x}
\label{xdelta}
\end{equation}
where $\Delta x$ is the grid spacing in the $x$ direction.

Differentiating equation \ref{boundary1} with respect to y gives
\[
\partial_{xxyy} = \frac{\partial_{x+yy} - \partial_{x-yy}}{\Delta x}= -\nu\partial_{yyyy}
\]
so
\[
\partial_{x-yy} = \partial_{x+yy} + \Delta x\nu\partial_{yyyy}
\]
substituting back into equation \ref{xdelta}
\[
\partial_{xx}\nabla^2 = \frac{\partial_{x+}\nabla^2 -(1-\nu)(\partial_{x+yy} + \Delta x\nu\partial_{yyyy})}{\Delta x}
\]
but, differentiating equation \ref{delta} by y gives
\[
\partial_{yy}\nabla^2 = (1-\nu)\partial_{yyyy}
\]
so, at a left-hand edge
\begin{equation}
\nabla^2\nabla^2 = \frac{\partial_{x+}\nabla^2 -(1-\nu)\partial_{x+yy}}{\Delta x} - (1-\nu)^2\partial_{yyyy}
\end{equation}
simplifying gives
\begin{equation}
\nabla^2\nabla^2 = \frac{\partial_{x+}(\partial_{xx} +\nu\partial_{yy})}{\Delta x} - (1-\nu)^2\partial_{yyyy}
\label{DeltaDelta}
\end{equation}
this is convenient to calculate since, on the left-hand edge,
\[
\partial_{xx} +\nu\partial_{yy} = 0
\]
\subsection{Laplacian finite difference at a corner}
At the bottom-left corner we have, from equation \ref{boundary1},
\[
\partial_{xx} = - \nu \partial_{yy}
\]
and
\[
\partial_{yy} = - \nu \partial_{xx}
\]
Since $\nu$ is positive, this implies $\partial_{xx} = 0$ and $\partial_{yy} = 0$ so $\nabla^2 = 0$

At the corner, we cannot differentiate past the corner, so we need to calculate $\partial_{x-yy}$ in a different way:
\[
\partial_{x-yy} = \frac{\partial_{x-}(\partial_{y+} - \partial_{y-})}{\Delta y}
\]
so, from equation \ref{boundarycorner}
\[
\partial_{x-yy} = \frac{\partial_{x-y+}}{\Delta y}
\]
However,  along the left-hand edge
\[
\frac{\partial_{x+} - \partial_{x-}}{\Delta x}=-\nu\partial_{yy}
\]
so
\[
 \partial_{x-}=\Delta x\nu\partial_{yy} + \partial_{x+}
\]
so
\[
\partial_{x-yy} = \frac{\partial_{y+}(\Delta x\nu\partial_{yy} + \partial_{x+})}{\Delta y}
\]
substituting this into equation \ref{xdelta}
\[
\partial_{xx}\nabla^2 = \frac{\Delta y\partial_{x+}\nabla^2 - (1-\nu)\partial_{y+}(\Delta x\nu\partial_{yy} + \partial_{x+})}{\Delta x\Delta y}
\]
by symmetry
\[
\partial_{yy}\nabla^2 = \frac{\Delta x\partial_{y+}\nabla^2 - (1-\nu)\partial_{x+}(\Delta y\nu\partial_{xx} + \partial_{y+})}{\Delta x\Delta y}
\]
so, at the bottom-left corner
\begin{equation}
\nabla^2\nabla^2 = \frac{\Delta x\partial_{y+}\nabla^2 + \Delta y\partial_{x+}\nabla^2 - (1-\nu)(\partial_{y+}(\Delta x\nu\partial_{yy} + \partial_{x+}) + \partial_{x+}(\Delta y\nu\partial_{xx} + \partial_{y+}))}{\Delta x\Delta y}
\end{equation}
simplifying gives
\begin{equation}
\nabla^2\nabla^2 = \frac{\partial_{y+}(\nabla^2- \nu(1-\nu)\partial_{yy})}{\Delta y} + \frac{\partial_{x+}(\nabla^2-\nu(1-\nu)\partial_{xx} )}{\Delta x} - \frac{2(1-\nu)\partial_{x+y+}}{\Delta x\Delta y}
\end{equation}
which is convenient to calculate as, on the corner, $\nabla^2 - \nu(1-\nu)\partial_{yy} = 0$ and $\nabla^2 - \nu(1-\nu)\partial_{xx} = 0$
%%\tableofcontents

%%\appendix

\end{document}


\documentclass[11pt, a4paper, twoside]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[margin=0.8in]{geometry}
\usepackage{listings}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage{indentfirst}
\usepackage[inline]{enumitem}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{array}
\usepackage{minted}
\usemintedstyle{vs}
\usepackage[belowskip=0pt,aboveskip=0pt,font=small,labelfont=small]{caption}
\captionsetup{width=\linewidth}
\setlength\intextsep{0pt}
\graphicspath{{Plots/}}
\setlist[itemize]{noitemsep, topsep=0pt}
\fancyhead[RO,LE]{EE2703: Assignment 7}
\fancyhead[LO,RE]{Akilesh Kannan}
\cfoot{\thepage}

\title{EE2703: Assignment 7}
\author{Akilesh Kannan (EE18B122)}
\date{\today}

\pagestyle{fancy}

\begin{document}
\maketitle

\section{Introduction}
The aim of this assignment is to analyse circuits using the Symbolic algebra capabilities of \texttt{Sympy}.

\section{Low-Pass Filter}
    In this section, we analyse the following circuit:
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.25]{circuits/ckt1.png}
        \caption{Op-Amp based Low-Pass Filter}
        \label{fig:ckt1}
    \end{figure}
    Writing KCL equations (in $s$-domain) of the nodes marked on the figure, we get the following matrix:
    \begin{equation}
        \begin{pmatrix}
            0&0&1&\frac{-1}{G}\\
            \frac{-1}{1+sR_2C_2}&1&0&0\\
            0&-G&G&1\\
            -\frac{1}{R_1}-\frac{1}{R_2}-sC_1&\frac{1}{R_2}&0&sC_1\\
        \end{pmatrix}
        \begin{pmatrix}
            V_1(s)\\
            V_p(s)\\
            V_m(s)\\
            V_o(s)\\
        \end{pmatrix}
        =
        \begin{pmatrix}
            0\\
            0\\
            0\\
            \frac{V_i(s)}{R_1}\\
        \end{pmatrix}
    \end{equation}
    \texttt{Sympy} allows us to create matrices with symbolic entries, and also perform mathematical operations on them, as if they were \texttt{numpy} arrays. In the above circuit, the values of $R_1$, $R_2$, $C_1$, $C_2$ are $10k\Omega$, $10k\Omega$, $10$pF, $10$pF respectively.\\

    Solving for $V_o(s)$, (with the above given values) we get:
    \begin{equation}
        V_o(s) = \frac{-0.0001586\cdot V_i(s)}{2\times10^{-14}s^2 + 4.414\times10^{-9}s + 0.0002}
        \label{eq2}
    \end{equation}

    From \eqref{eq2}, we get the step response of the circuit as:
    \begin{equation}
        V_o(s) = \frac{-0.0001586\cdot \frac{1}{s}}{2\times10^{-14}s^2 + 4.414\times10^{-9}s + 0.0002}
    \end{equation}

    \texttt{Sympy} allows us to convert a symbolic expression into functions that are compatible with other packages like \texttt{numpy}, \texttt{scipy} etc. This can be accomplished by converting the expression into a \textit{lambda}\footnote{Lambda functions are, in a nutshell, \textit{one-time use} functions. They are short-lived functions, very useful for quick manipulations, especially inside other functions.} function. For this purpose, \texttt{sympy} has a method called \textit{lambdify}, which takes in as arguments, the symbols in the expression (which are to be treated as variables), the expression itself, and also the package with which the resulting function has to be compatible with.

    However, since we are required to use the \texttt{scipy.signal} toolbox, we have to convert the above the symbolic expression to a format with which we can easily create a \texttt{signal.lti} object. For that, we extract the coefficients of the numerator and denominator polynomials of $V_o(s)$ and create a \texttt{signal.lti} object using the same. The below piece of code accomplishes this:
    \inputminted[breaklines, linenos]{python}{code/sympyToLTI.py}

    Now, we can easily create a \texttt{signal.lti} object with the coefficients we got, and use \texttt{signal.bode} to obtain the Bode magnitude and phase plots, which are shown below.
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.4]{plots/Fig 1.png}
        \caption{Bode Magnitude and Phase plots of step response of LPF}
        \label{fig:Fig2}
    \end{figure}

    To see the step response of the system, we can use \texttt{signal.step}. The step response of the system is shown below.
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.4]{plots/Fig 2.png}
        \caption{Step response of LPF}
        \label{fig:Fig3}
    \end{figure}

    Now, we shall see that the circuit is indeed a low-pass filter by plotting the output for a mixed-frequency input, which has both high frequency and low frequency components.

    We shall give the following input to the filter:
    \begin{equation}
        v_i(t) = (sin(2\pi\times 10^3t)+cos(2\pi\times 10^6t))u(t)
        \label{eq4}
    \end{equation}

    We shall use \texttt{signal.lsim} to calculate the time-domain response of the system.

    \begin{figure}[H]
        \centering
        \setlength\tabcolsep{1pt}
        \begin{tabular}{cc}
            \includegraphics[width=0.55\textwidth]{plots/Fig 3.png} &
            \includegraphics[width=0.55\textwidth]{plots/Fig 4.png}\\
        \end{tabular}
        \caption{\textit{Left}: Mixed frequency input\\\textit{Right}: Filtered Output}
    \end{figure}

    We can easily see that the output contains only the low frequency component of the input ($1\ KHz$ sinusoid). Thus, the circuit is a low-pass filter. It's cut-off frequency for the values of $R_1$, $R_2$, $C_1$, $C_2$ used is $\frac{1}{2\pi}\ MHz$.

\section{High-Pass Filter}

We shall now look at a slightly modified version of the above circuit.
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.25]{circuits/ckt2.png}
    \caption{Op-amp based High-Pass Filter}
    \label{fig:fig5}
\end{figure}

Performing a similar procedure like before, we get the KCL matrix as:
\begin{gather}
    \begin{pmatrix}
            0&0&1&\frac{-1}{G}\\
            \frac{sR_3C_2}{1+sR_3C_2}&0&-1&0\\
            0&-G&G&1\\
            -\frac{1}{R_1}-sC_2-sC_1&0&sC_2&\frac{1}{R_1}\\
        \end{pmatrix}
        \begin{pmatrix}
            V_1(s)\\
            V_p(s)\\
            V_m(s)\\
            V_o(s)\\
        \end{pmatrix}
        =
        \begin{pmatrix}
            0\\
            0\\
            0\\
            -sC_1V_i(s)\\
        \end{pmatrix}
\end{gather}

Solving it for $V_o(s)$, we get,
\begin{equation}
    V_o(s) = \frac{1.586\times10^{-14}s^2\cdot V_i(s)}{2\times10^{-14}s^2 + 4.414\times10^{-9}s + 0.0002}
\end{equation}
The Bode magnitude and phase plots of the transfer function as:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.4]{plots/Fig 5.png}
    \caption{Bode Magnitude and Phase plots of step response of HPF}
    \label{fig:Fig6}
\end{figure}

The step response of the circuit was obtained as:

\begin{figure}[H]
    \centering
    \includegraphics[scale=0.4]{plots/Fig 10.png}
    \caption{Step Response of HPF}
    \label{fig:Fig7}
\end{figure}

The response to the mixed frequency input in Eq \eqref{eq4} is:

\begin{figure}[H]
    \centering
    \setlength\tabcolsep{1pt}
    \begin{tabular}{cc}
        \includegraphics[width=0.55\textwidth]{plots/Fig 6.png} &
        \includegraphics[width=0.55\textwidth]{plots/Fig 7.png}\\
    \end{tabular}
    \caption{\textit{Left}: Mixed frequency input\\\textit{Right}: Filtered Output}
\end{figure}

We shall look at the response of the system to a damped sinusoid. We shall consider two of them - one of high frequency (0.1 MHz) and the other of low frequency (1 Hz).

\begin{figure}[H]
    \centering
    \setlength\tabcolsep{1pt}
    \begin{tabular}{cc}
        \includegraphics[width=0.55\textwidth]{plots/Fig 8.png} &
        \includegraphics[width=0.55\textwidth]{plots/Fig 9.png}\\
    \end{tabular}
    \caption{\textit{Left}: Low frequency input\\\textit{Right}:High frequency input}
\end{figure}

We get that the output of the filter if the input is a low frequency damped sinusoid is 0, except for initial transients. This is expected due to the inherent nature of the circuit to act as a high-pass filter. This is why we can see that it allows the high-frequency input to pass through.

\section{Conclusion}
\texttt{Sympy} provides a convenient way to analyse LTI systems using their Laplace transforms.  The toolbox was used to study the behaviour of a low pass filter,implemented using an op-amp of gain G. For a mixed frequency sinusoid as input,  it  was  found  that  the  filter  suppressed  the  high  frequencies  while allowing  the  low  frequency  components.   Similarly,  a  high  pass  filter  was implemented using an op-amp with the same gain.  The magnitude response of the filter was plotted and its output was analysed for damped sinusoids.The step response of the filter was found to have a non-zero peak at $t= 0$ ,due to the sudden change in the input voltage.
\end{document}


\documentclass{article}
\usepackage{palatino}
\usepackage{a4}
\usepackage{alltt}
\usepackage{xspace}
\usepackage{pig}

\include{macros}

\ColourEpigram

\begin{document}

\section*{Notion of \emph{equivalence relation}:}

\[
\stkl{
\SYMBequivrel : \PI{\V{A}}{\Set}
                (\V{A} \To \V{A} \To \Prop) \To
                \Prop \\
\begin{array}{@{}lcl}
\equivrel{\V{A}}{\V{R}} \mapsto &        & \eforall{\V{x}}
                                              {\V{A}}
                                              {\V{x} \mathop{\V{R}} \V{x}} \\
                        & \SYMBeand & \eforall{\V{x}\, \V{y}}
                                              {\V{A}}
                                              {\V{x} \mathop{\V{R}} \V{y}
                                               \Imp \V{y} \mathop{\V{R}} \V{x}} \\
                        & \SYMBeand & \eforall{\V{x}\, \V{y}\, \V{z}}
                                              {\V{A}}
                                              {\V{x} \mathop{\V{R}} \V{y}
                                               \Imp \V{y} \mathop{\V{R}} \V{z}
                                               \Imp \V{x} \mathop{\V{R}} \V{z}}
\end{array}
}
\]

\section*{Type formers:}

Given a set \(\V{A}\) and an equivalence relation \(\V{R}\) over
\(\V{A}\), the quotient of \(\V{A}\) by \(\V{R}\) is denoted
\(\Quotient{\V{A}}{\V{R}}{\V{p}}\), with \(\V{p}\) the proof that
\(\V{R}\) is indeed an equivalence relation. The equivalence class of
\(\V{x}\) is denoted \(\class{\V{x}}\).

\[
\stkl{
\Rule{\stkc{\Bhab{\V{A}}{\Set} \quad
            \Bhab{\V{R}}{\V{A} \To \V{A} \To \Prop} \\
            \Bhab{\V{p}}{\prf{(\equivrel{\V{A}}{\V{R}})}}}}
     {\Bhab{\Quotient{\V{A}}{\V{R}}{\V{p}}}{\Set}}
\qquad

\Rule{\Bhab{\V{x}}{A}}
     {\Bhab{\class{\V{x}}}{\Quotient{A}{R}{p}}}
}
\]

\section*{Elimination rule:}

\[
\stkl{
\begin{array}{@{}ll}
\SYMBelimQuotient : & \PITEL{\V{A}}{\Set}
                      \PITEL{\V{R}}{\V{A} \To \V{A} \To \Prop}
                      \PITEL{\V{p}}{\prf{(\equivrel{\V{A}}{\V{R}})}} \\
                    & \PITEL{\V{z}}{\Quotient{\V{A}}{\V{R}}{\V{p}}}
                      \PITEL{\V{P}}{\Quotient{\V{A}}{\V{R}}{\V{p}} \To \Set} \\
                    & \PITEL{\V{m}}{\PI{\V{x}}{\V{A}}{\V{P}\:\class{\V{x}}}}
                      \PI{\V{h}}{\prf{(\eforall{\V{x}\, \V{y}}{\V{A}}
                                       \V{x} \mathop{\V{R}} \V{y}
                                       \Imp (\Bhab{\V{m}\: \V{x}}{\V{P}\: \V{x}})
                                              \PropEq
                                            (\Bhab{\V{m}\: \V{y}}{\V{P}\: \V{y}}))}}
                      \V{P}\: \V{z}
\end{array}\\
\elimQuotient{\V{A}}{\V{R}}{\V{p}}{\class{\V{x}}}{\V{P}}{\V{m}}{\V{h}} \mapsto \V{m}\: \V{z}
}
\]

\section*{Propositional equality:}

\[
\Rule{\eforall{\V{b}}{\V{B}}
      (\Bhab{\V{x}}{\V{A}}) \PropEq (\Bhab{\V{b}}{\V{B}})
       \Imp \V{b} \mathop{S} \V{y}}
     {(\Bhab{\class{\V{x}}}{\Quotient{A}{R}{p}})
        \PropEq
      (\Bhab{\class{\V{y}}}{\Quotient{B}{S}{q}})}
\]

\section*{Note:}

The notion of propositional equality in use here comes from the
``Observational Equality, Now!'' paper. In particular, the \(\PropEq\)
equality is heterogeneous (hence the type ascriptions). The \(\prf{}\)
constructor embeds objects of \(\Prop\) into \(\Set\).

\end{document}


\section{Higher-order functions}

\begin{frame}{Remember $\lggeE$?}
  \input{language-e-syntax}
\end{frame}

\begin{frame}
  \frametitle{Introduction}
  In $\lggeE$, to multiply a number by $2$, we can write:
  \[
  \clet{4}{x}{\etimes{\enum{2}}{\enum{x}}}
  \]
  whenever we want to double a number with have to ``redefine''
  the concept of doubling.

  \bigskip

  What if I don't want to write the concept of ``doubling'' several times in, e.g.,
  $(10\times2)+(4\times2)+(5\times2)$?

  \bigskip

  \pause

  \bigskip

  What concept(s) are we missing?
\end{frame}

\subsection{Syntax and types}

\begin{frame}[fragile]
  \frametitle{Language $\lggeEF$}

  \pause

  \[
  \begin{array}{llclll}
    \TYPES & \tau & \Coloneqq & \ldots {\color{gray} (\text{as in } \lggeE)}
    \\
           &&& \tyarr{\tau_1}{\tau_2}  & \tau_1 \rightarrow \tau_2 & \text{function}
    \\
    \\\pause
    \EXPS & e & \Coloneqq & \ldots {\color{gray} (\text{as in } \lggeE)}
    \\
           &&& \elam{\tau}{x}{e} & \clam{\tau}{x}{e} & \text{abstraction}
    \\
           &&& \eapp{e_1}{e_2} & \capp{e_1}{e_2} & \text{application}
  \end{array}
  \]

  \bigskip
  \pause

  In other programming languages:
\begin{lstlisting}
  (Object x) -> x.getClass() // Java

  \x -> x + 1                -- Haskell
\end{lstlisting}

  \pause

  \[
  \quad
  \begin{array}{ll}
    \text{Example:} \quad &
                            \cleta{\clam{\enum{}}{x}{\etimes{\var{x}}{\enum{2}}}}{double}
    \\
                          &
                            \quad
                            \cletb
                            {
                            \eplus{
                            \capp{\var{double}}{\enum{4}}
                            }
                            {
                            \capp{\var{double}}{{\enum{10}}}
                            }
                            }
  \end{array}
  \]
\end{frame}

\begin{frame}
  \frametitle{Statics}
  \[
  \tyrule
  {\eftyrulename{lam}}
  {
    \only<2->{
      \tyjudge{\Gamma, \var{x} : \tau_1}{e}{\tau_2}
    }
  }
  {\tyjudge{\Gamma}{\elam{\tau_1}{x}{e}}{\tyarr{\tau_1}{\tau_2}}}
  \]

  \bigskip

  \pause

  \pause

  \[
  \tyrule
  {\eftyrulename{ap}}
  {
    \only<4->{
      \tyjudge{\Gamma}{e_1}{\tyarr{\tau'}{\tau}}
    \and
      \tyjudge{\Gamma}{e_2}{\tau'}
    }
  }
  {
    \tyjudge{\Gamma}{\eapp{e_1}{e_2}}{\tau}
  }
  \]

\end{frame}

\subsection{Semantics}

\begin{frame}
  \frametitle{Examples}
  \label{fr:ef-types}
  Are these $\lggeEF$ programs well typed?

  {\footnotesize
    \begin{itemize}[<+->]
    \item $\elet{\clam{\enum{}}{x}{\etimes{\var{x}}{\var{x}}}}{sq}
      {
        \eplus{
          \eapp{\var{sq}}{4}
        }
        {
          \eapp{\var{sq}}{10}
        }
      }$
      %
    \item { $\elet{\clam{\enum{}}{x}{
            \clam{\enum{}}{y}{
              \etimes{\var x}{\var y}
            }
          }
        }{f}{
          \eapp
          {\eapp
            {\var{f}}
            {\enum{4}}
          }
          {\enum{4}}
        }
        $}

    \item $\elet{\clam{\enum{}}{x}{
          \eapp{\var f}{\eplus{\var{x}}{\enum{1}}}
        }
      }{f}{
        \eapp{\var{f}}{0}
      }$
    \end{itemize}
  }

\end{frame}

\begin{frame}
  \frametitle{Dynamics}

  First: define what a value is
  \pause

  \bigskip
  \[
  \semrule
  {\efsemrulename{lam}}
  {\,}
  {\valjudge{\elam{\tau}{x}{e}}}
  \]

  \bigskip
  \pause
  Second: define evaluation judgements
  \pause

  \[
  \semrule
  {\efsemrulename{ap}}
  {\jtrans{e_1}{e'_1}}
  {
    \jtrans{\eapp{e_1}{e_2}}{\eapp{e'_1}{e_2}}
  }
  \]

  \bigskip

  \pause

  \bigskip

  We write $\jtransC{e_1}{e_n}$ if $\jtrans{e_1}{e_2}$,
  $\jtrans{e_2}{e_3}$, \ldots, $\jtrans{e_{n-1}}{e_n}$ for some
  terms $e_1$, \ldots, $e_{n-1}$.

\end{frame}

\begin{frame}
  \frametitle{Dynamics}

  \begin{itemize}[<+->]
  \item Call-by-name
    \[
    \semrule
    {\efsemrulename{apn}}
    {\,}
    {\jtrans{\eapp{\elam{\tau}{x}{e_1}}{e_2}}{\subs{e_1}{e_2}{x}}}
    \]
    %
  \item Call-by-value

    \[
    \semrule
    {\efsemrulename{apr}}
    {\valjudge{e_1}
      \and \jtrans{e_2}{e'_2}
    }
    {\jtrans{\eapp{e_1}{e_2}}{\eapp{e_1}{e'_2}}}
    \]

    \[
    \semrule
    {\efsemrulename{apl}}
    {\valjudge{e_2}}
    {\jtrans{\eapp{\elam{\tau}{x}{e_1}}{e_2}}{\subs{e_1}{e_2}{x}}}
    \]
  \end{itemize}

  \bigskip
  %

  What are the differences between call-by-name and call-by-value?
\end{frame}

\begin{frame}
  \frametitle{Examples}
  \label{fr:evaluate-ef}
  Reduce the following expression (if they are typeable!):

  {\footnotesize
    \begin{itemize}[<+->]
    \item $\elet{\clam{\enum{}}{x}{\etimes{\var{x}}{\var{x}}}}{sq}
      {
        \eplus{
          \eapp{\var{sq}}{4}
        }
        {
          \eapp{\var{sq}}{10}
        }
      }$
      %
    \item $\elet{\clam{\enum{}}{x}{
          \clam{\enum{}}{y}{
            \etimes{\var x}{\var y}
          }
        }
      }{f}{
        \eapp
        {\var f}
        {\eapp
          {\enum{4}}
          {\enum{3}}
        }
      }$

    \item $\elet{\clam{\enum{}}{x}{
          \eapp{\var f}{\eplus{\var{x}}{\enum{1}}}
        }
      }{f}{
        \eapp{\var{f}}{0}
      }$
    \end{itemize}
  }

  \bigskip

\end{frame}

\begin{frame}{Other examples}
  \label{fr:notype-ef}

  Type check then evaluate the following terms:
  %
  %
  \begin{itemize}
  \item {\small $ \eapp{
      \eapp{{\elam{\enum{}}{x}{\elam{\enum{}}{y}{\eplus{\var{x}}{\var{y}}}}}}
      {\enum{1}}
    }{\enum{2}}
    $}
    %
  \item $\eapp
    {\elam{\tau}{x}{\eapp
        {\var{x}}
        {\var{x}}}
    }
    {\enum{2}}$
    %
  \item $\eapp
    {\elam{\tau}{x}{\eapp
        {\var{x}}
        {\var{x}}}
    }
    {\elam{\tau'}{x}{\eapp
        {\var{x}}
        {\var{x}}}
    }$
    %
  \end{itemize}

  \bigskip

  The same programs in concrete syntax:
  \begin{itemize}
  \item  $
    \capp{
      \capp{{\clam{\enum{}}{x}{\clam{\enum{}}{y}{{\var{x}+\var{y}}}}}}
      {\enum{1}}
    }{\enum{2}}
    $
  \item $\capp
    {\clam{\tau}{x}{\capp
        {\var{x}}
        {\var{x}}}
    }
    {\enum{2}}$
    %
      \item $\capp
    {\clam{\tau}{x}{\capp
        {\var{x}}
        {\var{x}}}
    }
    {\clam{\tau'}{x}{\capp
        {\var{x}}
        {\var{x}}}
    }$
    %
  \end{itemize}

  %

\end{frame}

\begin{frame}
  \label{fr:eval-strat-ef}
  \frametitle{Evaluation strategies}
  Remember the difference between \emph{call-by-name} vs \emph{call-by-value} evaluations?

  \bigskip

  \begin{itemize}
  \item $\eapp{\elam{\enum{}}{x}{\eplus{\var{x}}{\var{x}}}}{e}$
    % $(\lambda \var{x} . \ \var{x} + \var{x}) \ e$
  \item $\eapp{\elam{\enum{}}{x}{\enum{42}}}{e}$

  \end{itemize}

  \bigskip

  Which evaluation strategy is the best for these terms?

\end{frame}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End:


\chapter{Introduction}

In 1936 Alonzo Church presented the \lam-calculus, a formal system for expressing the entire set of computable problems \cite{Church36}.\footnote{
  The ability of a system to express the entire set of computable problems is now commonly known as `Turing completeness' although here this description would be anachronistic;
  Turing's work on computability was published a year after Church's.
}
Later, Haskell Curry and William Howard both discover a correspondence between the simply-typed \lam-calculus and intuitionistic logic.
However the correspondence runs deeper than this: there is actually a true isomorphism between many systems of formal logic and computational calculi.

The correspondence between systems of formal logic and computer programs drove research into both the logical counterparts of programs and the computational counterparts of logical systems.
As a part of this, Michel Parigot developed the \lmu-calculus, an extension of the \lam-calculus,
through an isomorphism to classical logic \cite{Parigot92}.
More recently, Steffen van Bakel modelled exceptions and exception handling through an extension of the \lam-calculus called the \ltry-calculus \cite{Bakel15}.\footnote{
  Exceptions are a form of error generated by computers to indicate that the flow of control cannot continue as expected and must be aborted.
}

Exceptions are most commonly found in two kinds:
  systems where there is a single type of exception such as in Javascript,
  and systems where exceptions are discriminated by \emph{type} as in Java and Haskell.
Unlike either of these approaches,
the exception handling proposed by the \ltry-calculus introduces exceptions discriminated by \emph{name}.

\subsubsection{Project}
This paper proposes an implementation of named exceptions in Haskell.
First we define a translation from the \lmu-calculus to a calculus for expressing delimited continuations, CDC \cite{JonesDS07}.
\[
\begin{array}{lcr}
  `l`m & \to & CDC
\end{array}
\]
CDC is a calculus which closely models Haskell's syntax and which has been extended with operations for manipulating delimited continuations.
The CDC library for Haskell defined by Jones \emph{et al.} in \cite{JonesDS07} evaluates CDC terms in a single step, returning the final value of the reduction.
However, we are interested in producing the entire step-by-step evaluation of CDC terms which we can transliterate into CDC derivations for verifying translations of \lmu\ into CDC.
This motivates us to write a term-rewriting program for evaluating CDC terms.
The proofs generated by this program are used to investigate the soundness and completeness of the $`l`m \to CDC$ translation.
The translation is then concatenated with van Bakel's original translation of his \ltry-calculus into the \lmu-calculus which yields a translation from \ltry\ to CDC:
\[
   (`l^{try} \to `l`m) \circ (`l`m \to CDC) = `l^{try} \to CDC
\]
We use this final translation to explore implementations of named exceptions directly in Haskell.

\subsubsection{Outline}
Chapter \ref{chapter:background} discusses the related context for this project. Following this, this paper makes the following original contributions:
\begin{itemize}
\item A Haskell interpreter for the calculus of delimited continuations, CDC (in Chapter \ref{chapter:interpreter})
\item A translation of \lmu\ into CDC along with proofs of its soundness and completeness with respect to $`m$-reduction (in Chapter \ref{chapter:translations})
\item A translation of \ltry\ into CDC (also in Chapter \ref{chapter:translations})
\item A proof of concept implementation of \ltry\ in Haskell, based on this translation (in Chapter \ref{chapter:implementation})
\item The specification for a language extension for Haskell with named exceptions, based on \ltry\ (also Chapter \ref{chapter:implementation})
\end{itemize}


\subsubsection{\tt ipbb}
\label{benchmarkipbb}

{\tt ipbb} is a synthetic AKS benchmark that performs
a Boolean-Boolean ({\apl M\qor\qdot\qand\qtran\0M}) matrix product on
arrays of shape {\tt [400, 400]}.

The \sac implementation of these benchmarks utilizes Bernecky's
generalization of the CDC STAR APL matrix
product algorithm.~\cite{RBernecky:apex}

The benchmarks {\tt ipbb}, {\tt ipbbAKD}, {\tt ipape}, {\tt ipapeAKD},
{\tt ipopne}, {\tt ipopneAKD}, {\tt ipbd}, {\tt ipbdAKD}, {\tt ipdd},
{\tt ipddAKD}, {\tt ipplusand}, {\tt ipplusandAKD},
form a clique, as they all perform similar tasks.


%! Author = tstreule

\section{Mechanical Sensors}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Viscoelastic media}
%
\includegraphics[width=.3\columnwidth]{Mechanical_1}\hfill
\includegraphics[width=.3\columnwidth]{Mechanical_2}\hfill
\includegraphics[width=.3\columnwidth]{Mechanical_3}

\textbf{Remark}: Calculate \textit{always} at first in $\unitfrac{rad}{s} \overset{\scriptstyle \times\unitfrac{1}{2\pi}}{\longrightarrow} \unit{Hz}$.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Crystal with thickness $l$}
%
\formbox[\unitfrac{rad}{s}]{Resonance frequency}{\omega_n = n\cdot\omega_0 = n\cdot \frac{\pi}{l} \sqrt{\frac{\mu_Q}{\rho_Q}}}
%\formula{overtones}{q\coloneqq \omega\sqrt{\frac{\rho}{\mu}}, \enskip \lambda = 2\pi / q = 2l / n}
\formula{char. wavelength}{\lambda = 2l/n}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Elastic plate in water}
%
\formbox{Resonance frequency}{\omega_n = n\omega_0 + \Delta\omega_n}
\formula{frequency shift}{\Delta\omega_n = -\sqrt{n} \,\sqrt{\frac{\rho_L\,\eta_L\,\omega_0}{2}} \frac{1}{l\,\rho_Q} \textrm{,\enskip $\eta_L$: viscosity}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Elastic plate in water with adlayer}
%
In fact is the \textit{resonance frequency} dependent on the adlayer height.\\
But if it is ``enough'' small, the Sauerbrey approx. is sufficient.

\formbox{\textbf{Sauerbrey eq.}}{\!\!\Delta f_n = 2\pi\omega_n = -n\frac{\Delta m}{C}\!\!}
\hfill $C {=}\frac{\sqrt{\rho_Q\,\mu_Q}}{2f_0^2} {=} \unit[17.7]{\!\!\frac{\unit[]{ng}}{\unit[]{cm^2Hz}}}$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{QCM-D \textit{vs.} SPR techniques}
%
\begin{tabular}{@{}l @{\qquad}l}
    \includegraphics[width=.35\columnwidth]{Mechanical_vs_QCM} &
    \includegraphics[width=.5\columnwidth]{Mechanical_vs_SPR}
    \\\addlinespace
    \highlight{$\Delta m = -\frac{C}{n} \Delta f_n$} &
    \highlight{$\textstyle \Delta m = d\,\frac{n\ped{protein} - n\ped{buffer}}{\diff n/\diff c}$}
    \\\addlinespace
    $\textrm{LOD}\ped{QCM} = C\cdot \delta f     \simeq \unitfrac[1]{ng}{cm^2}$ &
    $\textrm{LOD}\ped{SPR} = C\cdot \delta\theta \simeq \unitfrac[0.1]{ng}{cm^2}$
\end{tabular}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{QCM: Quartz Crystal Microbalance}
%
\formbox{Resonance cond.}{f = \frac{n\,v}{\lambda} = \frac{n\,v}{2t}}
\formula{Dissipation}{D = \frac{1}{\pi f\tau},}
$\tau$: time until $\frac{U\ped{max}}{\eu}$

\vspace{-9mm}
\begin{minipage}{\linewidth}
    \hfill
    \includegraphics[width=.23\columnwidth]{Mechanical_QCM}
\end{minipage}
\vspace{2mm}

\textbf{Modeling of the QCM-D response} in air / aqueous solution:\par
\begin{minipage}{.25\columnwidth}
\includegraphics[width=.88\columnwidth]{Mechanical_QCM_Modeling}
\end{minipage}%
\begin{minipage}{.75\columnwidth}
$\eta$: viscosity ($=\frac{G''}{\omega}$), $\mu$: elasticity ($=G'$),\\
$\rho$: density, $d$: thickness
%\formula{Resonance condition}{f = \frac{n\,v}{\lambda} = \frac{n\,v}{2t}}
\end{minipage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Strain Gauge}
%
\formula{Resistive strain g.}{\frac{\Delta R}{R} = k\,\frac{\Delta l}{l} = k\,\epsilon
\textrm{,\enskip $\epsilon$: Strain, $k$: Gauge factor}}
\formula{Capacitive strain g.}{C = \epsilon_0\epsilon_r\,\frac{A}{d} \textrm{,\enskip (displacement: $d \to d+\Delta d$)}}


    \filetitle{!dtrends}{Block of deterministic trend equations}{modellang/dtrends}

	\paragraph{Syntax for linearised measurement
variables}\label{syntax-for-linearised-measurement-variables}

\begin{verbatim}
!dtrends
    VariableName += Expression;
    VariableName += Expression;
    ...
\end{verbatim}

\paragraph{Syntax for log-linearised measurement
variables}\label{syntax-for-log-linearised-measurement-variables}

\begin{verbatim}
!dtrends
    log(VariableName) += Expression;
    log(VariableName) += Expression;
    ...
\end{verbatim}

\paragraph{Syntax with equation
labels}\label{syntax-with-equation-labels}

\begin{verbatim}
!dtrends
    'Equation label' VariableName += Expression;
    'Equation label' LOG(VariableName) += Expression;
\end{verbatim}

\paragraph{Description}\label{description}

\paragraph{Example}\label{example}

\begin{verbatim}
!dtrends
    Infl += pi_;
    Rate += rho_ + pi_;
\end{verbatim}


\section{Equality rules}

We describe here the rules for substitution of equality, $sub_l$ and $sub_r$.
{\GF} does not have explicit axioms or rules for reflexivity, commutativity and
transitivity.
Commutativity and transitivity, however, can be derived by $sub_l$ and $sub_r$,
and symmetry can be derived by using other {\GF} commands (for instance by
semantic simplification (see section \ref{sec-eval}), by the tautology and
monadic deciders (see the commands {\tt tauteq} and {\tt monadeq} commands in
section \ref{sec-decide}).

\[
\begin{array}{|c|c||c|c|} \hline
	&&& \\
	sub_l &
	\fraz{A(t_1) \ \ \ \ t_1 = t_2}
	     {A(t_2)}
	&
	sub_r &
	\fraz{A(t_1) \ \ \ \ t_2 = t_1}
	     {A(t_2)}
	\\
	&&& \\ \hline
\end{array}
\]


\section{Numpy} % (fold)
\label{sec:numpy}

\begin{frame}\frametitle{Numpy}
    \framesubtitle{}

    \begin{itemize}
        \item Fundamental package for scientific computing with Python
        \item N-dimensional array object
        \pause
        \item Linear algebra, Fourier transform, random number capabilities
        \item Building block for other packages (e.g. Scipy)
        \item Open source
    \end{itemize}

\end{frame}

\begin{frame}\frametitle{import numpy as np}
    \framesubtitle{The basics}

    Basics:

    \codeblock{code/numpy_basics.py}

    Slicing as usual.

\end{frame}

\begin{frame}\frametitle{More basics}
    \framesubtitle{}

    \codeblock{code/numpy_basics2.py}

\end{frame}

\begin{frame}\frametitle{More basics}
    \framesubtitle{}

    \codeblock{code/numpy_basics3.py}

\end{frame}

\begin{frame}\frametitle{Arrays are mutable}

    \codeblock{code/numpy_mutable.py}

\end{frame}

\begin{frame}\frametitle{Array attributes}
    \framesubtitle{}

    \codeblock{code/numpy_attr.py}

\end{frame}

\begin{frame}[fragile]\frametitle{Basic operations}
    \framesubtitle{}

    Arithmetic operators: \textbf{elementwise} application

    \codeblock{code/numpy_ops.py}

    Also, we can use \verb|+=| and \verb|*=|.

\end{frame}

\begin{frame}\frametitle{Array broadcasting}
    \framesubtitle{}

    When operating on two arrays, numpy compares shapes.
    Two dimensions are compatible when
    \begin{enumerate}
        \item They are of equal size
        \item One of them is 1
    \end{enumerate}

\end{frame}

\begin{frame}\frametitle{Array broadcasting}
    \framesubtitle{An example}

    \begin{figure}
        \centering
        \includegraphics[scale=0.3]{img/broadcasting.png}
    \end{figure}

\end{frame}

\begin{frame}\frametitle{Array broadcasting with scalars}

    This also allows us to add a constant to a matrix or multiply a matrix by a constant

    \codeblock{code/numpy_scalar_ops.py}

\end{frame}

\begin{frame}\frametitle{Vector operations}
    \begin{itemize}
        \item inner product
        \item outer product
        \item dot product (matrix multiplication)
    \end{itemize}

    \codeblock{code/numpy_vector_ops.py}

\end{frame}

\begin{frame}\frametitle{Matrix operations}

    First, define some matrices:

    \codeblock{code/numpy_matrix.py}

\end{frame}

\begin{frame}\frametitle{Matrix operations}

    \codeblock{code/numpy_matrix_ops.py}

\end{frame}

\begin{frame}\frametitle{Operations along axes}
    \framesubtitle{}

    \codeblock{code/numpy_ops2.py}

\end{frame}

\begin{frame}\frametitle{Slicing arrays}
    \framesubtitle{}

    More advanced slicing

    \codeblock{code/numpy_slice.py}

\end{frame}

\begin{frame}\frametitle{Iterating over arrays}
    \framesubtitle{}

    \begin{itemize}
        \item Iterating over multidimensional arrays is done with respect
        to the first axis: \texttt{for row in A}
        \item Looping over all elements:
        \texttt{for element in A.flat}
    \end{itemize}

\end{frame}

\begin{frame}\frametitle{Reshaping}
    \framesubtitle{}

    Reshape using \texttt{reshape}.
    Total size must remain the same.

    \vfill\pause

    Resize using \texttt{resize},
    always works: chopping or appending zeros

    First dimension has `priority', so beware of unexpected results

    \vfill\pause

    Try it!

\end{frame}

\begin{frame}\frametitle{Matrix operations}

\texttt{import numpy.linalg}

\begin{table}
\centering
\begin{tabular}{@{}ll@{}}
    \texttt{eye(3)}& Identity matrix\\
    \texttt{trace(A)}& Trace\\
    \texttt{column\_stack((A,B))}& Stack column wise\\
    \texttt{row\_stack((A,B,A))}& Stack row wise
\end{tabular}
\end{table}

\end{frame}

\begin{frame}[fragile]\frametitle{Linear algebra}
    \framesubtitle{}

\texttt{import numpy.linalg}

\begin{table}
\centering
\begin{tabular}{@{}ll@{}}
    \texttt{qr}& Computes the QR decomposition\\
    \texttt{cholesky}& Computes the Cholesky decomposition\\
    \texttt{inv(A)}& Inverse\\
    \texttt{solve(A,b)}& Solves $Ax = b$ for $A$ full rank\\
    \texttt{lstsq(A,b)}& Solves $\arg\min_x \|Ax-b\|_2$\\
    \texttt{eig(A)}& Eigenvalue decomposition\\
    \texttt{eig(A)}& Eigenvalue decomposition for
    symmetric or hermitian\\
    \texttt{eigvals(A)}& Computes eigenvalues.\\
    \texttt{svd(A, full)}& Singular value decomposition\\
    \texttt{pinv(A)}& Computes pseudo-inverse of A
\end{tabular}
\end{table}
\end{frame}

\begin{frame}\frametitle{Fourier transform}

\texttt{import numpy.fft}

\begin{itemize}
    \item \texttt{fft} 1-dimensional DFT
    \item \texttt{fft2} 2-dimensional DFT
    \item \texttt{fftn} N-dimensional DFT
    \item \texttt{ifft} 1-dimensional inverse DFT (etc.)
    \item \texttt{rfft} Real DFT (1-dim)
    \item \texttt{ifft} Imaginary DFT (1-dim)
\end{itemize}

\end{frame}

\begin{frame}\frametitle{Random sampling}

\texttt{import numpy.random}

\begin{table}
\centering
\begin{tabular}{@{}ll@{}}
    \texttt{rand(d0,d1,...,dn)} & Random values in a given shape\\
    \texttt{randn(d0, d1, ...,dn)} & Random standard normal\\
    \texttt{randint(lo, hi, size)} & Random integers [lo, hi)\\
    \texttt{choice(a, size, repl, p)} & Sample from a\\
    \texttt{shuffle(a)} & Permutation (in-place)\\
    \texttt{permutation(a)} & Permutation (new array)
\end{tabular}
\end{table}

\end{frame}

\begin{frame}\frametitle{Distributions in random}
\texttt{import numpy.random}

    The list of distributions to sample from is quite long, and includes
\begin{itemize}
    \item \texttt{beta}
    \item  \texttt{binomial}
    \item \texttt{chisquare}
    \item \texttt{exponential}
    \item \texttt{dirichlet}
    \item \texttt{gamma}
    \item \texttt{laplace}
    \item \texttt{lognormal}
    \item \texttt{pareto}
    \item \texttt{poisson}
    \item \texttt{power}
\end{itemize}

\end{frame}

% section numpy (end)