\chapter{Mathematical Model of Vehicle Dynamics}

This chapter will detail the mathematical model that was developed to describe the motion of the uDrone.

\section{Reference Frames and State Space}

Conventions for creating this model will follow those laid out by Thor Fossen in the 2011 Handbook of Marine Craft Hydrodynamics and Control. The fixed world frame is defined using the North-East-Down (NED) coordinate system, represented as $\{n\} = (x_n, y_n, z_n)$. in this system, $x_n$ points North, $y_n$ points East, and $z_n$ points down.

The body-fixed frame $\{b\} = (x_b, y_b, z_b)$ is fixed its origin point, $o_b$, to the uDrone. For purposes of this model, $o_b$ is set at the point on the plane of the motors at the back of the uDrone that is along its center-line. $x_b$ runs along the center-line of the vehicle, pointing from the aft (back) of the uDrone to the fore (front). $z_b$ runs from top to bottom and, following the right-hand rule, $y_b$ runs towards the starboard (right). Further, following convention, roll is defined as rotation about $x_b$, pitch as rotation about $y_b$, and yaw as rotation about $z_b$, with counter-clockwise (CCW) being the positive direction.

This choice of body frame origin reduces the complexity of modeling the forces produced by the motors. The drawback is some added complexity caused by the moments of the center of buoyancy and center of gravity relative to the chosen origin, but this is more straight forward than the complexity of calculating motor forces about a different point.

The position of the vehicle, or the body-fixed frame $\{b\}$, with respect to the world frame $\{n\}$ is expressed as $\bm{p} = [N, E, D]^T$. The attitude of the vehicle is expressed as $\bm{\Theta} = [\phi, \theta, \psi]^T$ using Euler angles. Together these create the 6-dimensional position/orientation vector $\bm{\eta} = [\bm{p}, \bm{\Theta]}^T$. The linear and angular velocities are expressed with respect to the vehicles fixed frame $\{b\}$. The linear velocity is $\bm{v} = [u, v, w]^T$ and angular velocity $\bm{\omega} = [p, q, r]^T$. when combine, these form the combine 6-dimensional velocity vector $\bm{\nu}= [\bm{v}, \bm{\omega]}^T$. All together, $\boldsymbol{\eta}$ and $\boldsymbol{\nu}$ represent the 12-dimensional state space describing the state of the uDrone \parencite{thor_kin}.

% \begin{align*}
%      \boldsymbol{p}^{n}_{b}=\left[\begin{array}{c}
%         N \\ E \\ D
%      \end{array}\right]
%      \bm{\Theta}^{n}_{b}=\left[\begin{array}{c}
%         \phi \\ \theta \\ \psi
%      \end{array}\right]
%      \bm{\eta}=\left[\begin{array}{c}
%         \bm{p} \\ \bm{\Theta}
%      \end{array}\right]
% \end{align*}
% \begin{align*}
%      \boldsymbol{v}^{b}_{b}=\left[\begin{array}{c}
%         u \\ v \\ w
%      \end{array}\right]
%      \bm{\omega}^{b}_{b}=\left[\begin{array}{c}
%         p \\ q \\ r
%      \end{array}\right]
%      \bm{\nu}=\left[\begin{array}{c}
%         \bm{v} \\ \bm{\omega}
%      \end{array}\right]
% \end{align*}

\section{Equations of Motions}

The general equation of motion for the uDrone can be derived as a function of the combine linear and angular velocity vector $\boldsymbol{\nu}$ \parencite{thor_mod}. This is shown in equation \ref{eqm}.

\begin{gather}
\underbrace{\boldsymbol{M}_{R B} \dot{\boldsymbol{\nu}}+\boldsymbol{C}_{R B}(\boldsymbol{\nu}) \boldsymbol{\nu}}_{\text {rigid-body forces}}+\underbrace{\boldsymbol{M}_{A} \dot{\boldsymbol{\nu}}+\boldsymbol{C}_{A}\left(\boldsymbol{\nu}\right) \boldsymbol{\nu}+\boldsymbol{D}\left(\boldsymbol{\nu}\right) \boldsymbol{\nu}}_{\text {hydrodynamic forces}}+\underbrace{\boldsymbol{g}(\boldsymbol{\eta})}_{\text{hydrostatic forces}}=\boldsymbol{\tau}
\label{eqm}
\end{gather}
With the terms defined as:
\begin{align*}
    \boldsymbol{\eta}&=\text{combine position and orientation}\\
    \boldsymbol{\nu}&=\text{combine linear and angular velocity}\\
    \dot{\boldsymbol{\nu}}&=\text{combine linear and angular acceleration}\\
    \boldsymbol{M}_{R B}&=\text{rigid-body system inertia matrix}\\
    \boldsymbol{C}_{R B}(\boldsymbol{\nu})&=\text{rigid-body Coriolis matrix}\\
    \boldsymbol{M}_{A}&=\text{added mass system inertia matrix}\\
    \boldsymbol{C}_{A}(\boldsymbol{\nu})&=\text{added mass Coriolis matrix}\\
    \boldsymbol{D}(\boldsymbol{\nu})&=\text{damping matrix}\\
    \boldsymbol{g}(\boldsymbol{\eta})&=\text{gravitational and buoyant forces}\\
    \boldsymbol{\tau}&=\text{control inputs}
\end{align*}
% \begin{align*}
%     \boldsymbol{\eta}&=\text{combine position and orientation}\\
%     \boldsymbol{\nu}&=\text{combine linear and angular velocity}\\
%     \dot{\boldsymbol{\nu}}&=\text{combine linear and angular acceleration}\\
%     \boldsymbol{\tau}&=\text{control inputs}\\
%     \boldsymbol{M}&=\text{system inertia matrix}\\
%     \boldsymbol{C}(\boldsymbol{\nu})&=\text{Coriolis matrix}\\
%     \boldsymbol{D}(\boldsymbol{\nu})&=\text{damping matrix}\\
%     \boldsymbol{g}(\boldsymbol{\eta})&=\text{gravitational and buoyant forces}\\
%     \boldsymbol{\tau}&=\text{control inputs}
% \end{align*}
% \begin{align*}
%     \boldsymbol{M}&=\boldsymbol{M}_{R B}+\boldsymbol{M}_{A}\\
%     \boldsymbol{C}&=\boldsymbol{C}_{R B}+\boldsymbol{C}_{A}
% \end{align*}

\section{Rigid-Body Forces}

The exact values of the system inertia ($\boldsymbol{M}$), Coriolis ($\boldsymbol{C}$), and Drag ($\boldsymbol{D}$) matrices can be determined either through intensive hydrodynamic modeling or experimentation. Due to the complexity of hydrodynamic modeling, experimentation is typically used to determine these values in underwater vehicles similar to the uDrone \parencite{hipp_pen}. It is possible, however, to estimate the rigid body matrix values using information about the vehicle generated from the 3D model. This section details these estimations and explains how they were calculated.

The rigid body system inertia matrix about the center of origin can be calculated using equation \ref{mrb} which is found in \cite{thor_rb}.
\begin{gather}
    \boldsymbol{M}_{R B}^{C O}=\left[\begin{array}{cc}
        m \boldsymbol{I}_{3 \times 3} & -m \boldsymbol{S}\left(\boldsymbol{r}_{g}^{b}\right) \\
        m \boldsymbol{S}\left(\boldsymbol{r}_{g}^{b}\right) & \boldsymbol{I}_{g}-m \boldsymbol{S}^{2}\left(\boldsymbol{r}_{g}^{b}\right)
    \end{array}\right]
    \label{mrb}
\end{gather}
% \begin{align*}
%     \boldsymbol{M}_{R B}^{C O}&=\text{rigid body system inertia matrix about the body fixed-frame origin}\\
%     \boldsymbol{I}_{3 \times 3}&=\text{3 by 3 identity matrix}\\
%     m&=\text{mass}\\
%     \boldsymbol{S}(\cdot)&=\text{cross product operator}\\
%     \boldsymbol{r}_{g}^{b}&=\text{ vector from the body fixed-frame origin to the center of gravity}\\
%     \boldsymbol{I}_{g}&=\text{inertia matrix}
% \end{align*}

In this equation, $m$ is the mass, $\boldsymbol{I}_{3 \times 3}$ is the three-by-three identity matrix, $\boldsymbol{I}_{g}$ is the inertia matrix and $\boldsymbol{r}_{g}^{b}$ is the vector from the body fixed-frame origin to the center of gravity. $\boldsymbol{S}$ is the cross product operator matrix. Before the final vehicle was constructed, m, $\boldsymbol{I}_{g}$, and $\boldsymbol{r}_{g}^{b}$ were taken from the 3D model. Those estimates are shown in equation \ref{m_matrix}.

\begin{equation}
\boldsymbol{M}_{R B}^{C O}=\left[\begin{array}{cccccc}
9.9000 & 0 & 0 & 0 & 0 & 0 \\
0 & 9.9000 & 0 & 0 & 0 & 1.4850 \\
0 & 0 & 9.9000 & 0 & -1.4850 & 0 \\
0 & 0 & 0 & 0.3420 & 0.0010 & -0.0001 \\
0 & 0 & -1.4850 & 0.0010 & 0.5577 & -0.0015 \\
0 & 1.4850 & 0 & -0.0001 & -0.0015 & 0.3167
\end{array}\right]
\label{m_matrix}
\end{equation}

With a completed vehicle these numbers can be verified and varied if needed. For example, with no ballast, the uDrone is positively buoyant. Therefore, to maintain its depth without using power to stay underwater ballast will need to be added. By placing the ballast closer to the center of the vehicle, the moments of inertia will decrease. Conversely, by placing it further from the center the moments can be increased. Additionally, the ballast can be used to change the center of gravity relative to the center of buoyancy. This will create a moment in the vehicle that can help it stay oriented or level in specific ways. This relationship is discussed further in the section \ref{hydrostatics}.

The Coriolis matrix is a function of the angular velocity of the vehicle and can be derived as shown in equation \ref{crb} from \cite{thor_rb}.
\begin{gather}
    \boldsymbol{C}_{RB}^{CO}(\boldsymbol{\nu})=\left[\begin{array}{cc}
        m \boldsymbol{S}\left(\boldsymbol{\omega}^{b}\right) & -m \boldsymbol{S}\left(\boldsymbol{\omega}^{b}\right) \boldsymbol{S}\left(\boldsymbol{r}_{g}^{b}\right) \\
        m \boldsymbol{S}\left(\boldsymbol{r}_{g}^{b}\right) \boldsymbol{S}\left(\boldsymbol{\omega}^{b}\right) & -\boldsymbol{S}\left(\left(\boldsymbol{I}_{g}-m \boldsymbol{S}^{2}\left(\boldsymbol{r}_{g}^{b}\right)\right) \boldsymbol{\omega}^{b}\right)
    \end{array}\right]
    \label{crb}
\end{gather}
% \begin{align*}
%     \boldsymbol{C}_{R B}^{C O}&=\text{rigid body Coriolis matrix about the body fixed-frame origin}\\
%     m&=\text{mass}\\
%     \boldsymbol{S}(\cdot)&=\text{cross product operator}\\
%     \boldsymbol{\omega}^b&=\text{body-fixed frame angular velocity}\\
%     \boldsymbol{r}_{g}^{b}&=\text{ vector from the body fixed-frame origin to the center of gravity}\\
%     \boldsymbol{I}_{g}&=\text{inertia matrix}
% \end{align*}

Where $\boldsymbol{\omega}^{b}$ is the body-fixed frame angular velocity vector. Since this matrix is a function of the vehicle state, it will change with motion. The actual calculations of this matrix are handled by a MatLab program written as a companion to Thor Forson’s book \parencite{mss}. The values based on the system inertia matrix in equation \ref{m_matrix} along with a velocity state vector $\bm{\nu}= [1,0,0,0,0,0]^T$, which represents only forward motion, is shown in equation \ref{c_matrix}.

\begin{equation}
\boldsymbol{C}_{RB}^{CO}(\boldsymbol{\nu})=\left[\begin{array}{cccccc}
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 9.9000 \\
0 & 0 & 0 & 0 & -9.9000 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 9.9000 & 0 & 0 & 0 \\
0 & -9.9000 & 0 & 0 & 0 & 0
\end{array}\right]
\label{c_matrix}
\end{equation}

\section{Hydrostatic Forces} \label{hydrostatics}

The hydrostatic term $\boldsymbol{g}(\boldsymbol{\eta})$ accounts for the forces on the uDrone caused by gravity and buoyancy. The force of gravity, or weight ($W$) is equal to the mass of the uDrone times the acceleration due to gravity. The buoyant force ($B$) is the weight of the water displaced by the uDrone. This is calculated by multiplying the volume of the uDrone, the density of water, and the acceleration due to gravity. If the location of the center of gravity and center of buoyancy (or center of volume) of the uDrone are not in the same spot then there will be a moment on the whole vehicle. Similarly, if the two forces are not equal then there will also be a net linear force on it. This value is a function of the orientation of the vehicle and can be seen in equation \ref{bigG} \parencite{thor_rb}.

\begin{equation}\label{bigG}
\boldsymbol{g}(\boldsymbol{\eta})=\left[\begin{array}{llll}
& (W-B) \sin (\theta) \\
- & (W-B) \cos (\theta) \sin (\phi) \\
- & (W-B) \cos (\theta) \cos (\phi) \\
- & \left(y_{g} W-y_{b} B\right) \cos (\theta) \cos (\phi) & + & \left(z_{g} W-z_{b} B\right) \cos (\theta) \sin (\phi) \\
& \left(z_{g} W-z_{b} B\right) \sin (\theta) & + & \left(x_{g} W-x_{b} B\right) \cos (\theta) \cos (\phi) \\
- & \left(x_{g} W-x_{b} B\right) \cos (\theta) \sin (\phi) & - & \left(y_{g} W-y_{b} B\right) \sin (\theta)
\end{array}\right]
\end{equation}

% \begin{equation}
%   \boldsymbol{g}(\boldsymbol{\eta})=\left[\begin{array}{llll}
%   0\\0\\0\\0\\0\\0
%   \end{array}\right]
% \end{equation}

Ballasting can be used to adjust the weight and center of mass on the uDrone. To simplify this equation the ballast is set so that the weight and buoyancy are equal and the center of mass and buoyancy are the same. This means the $\boldsymbol{g}$ vector will be zeros for all $\boldsymbol{\eta}$. These forces can be seen interacting on the uDrone in figure \ref{cord_frame}. Maintaining overlapped centers of buoyancy and gravity also makes the vehicle more nimble as there are less moments to overcome when rotating. This also has the benefit of making the uDrone more maneuverable. Equal weight and buoyancy reduces energy used as the uDrone does not need to overcome a force making it sink or float as it cruises through the water column.

There might be reasons to adjust the ballasting of the uDrone to impart other properties on it. For example, if the vehicle is slightly positively buoyant than it will float in the event of a power failure, allowing for it to be recovered more easily. Also, if the center of gravity is placed below the center of buoyancy, but still in line with it in the z body direction, then the vehicle will be self righting in roll. This could make control easier as roll, which should be at zero most of the time, can be ignored.

\section{Hydrodynamic Forces} \label{hydrodynamics}

The added mass system inertia matrix and added mass Coriolis matrix can only be determined through experimentation or complex fluid dynamic simulation and are not calculated in the scope of this thesis. The damping matrix, however, can be estimated using drag calculations.

The vehicle is modeled as a flat-faced cylinder moving through water in a direction along its axis. This estimation neglects two factors: 1) drag from the motors, and 2) rotational damping. Both of these forces are small in comparison to the drag of the flat-faced cylinder, so for the purposes of an approximate model, they can be ignored.

The force of drag in a single direction can be calculated using the drag equation:

\begin{gather}
F_{D}=C_{D} A \frac{\rho V^{2}}{2}
\end{gather}
\begin{align*}
    F_D&=\text{drag Force}\\
    C_D&=\text{coefficient of drag}\\
    A&=\text{cross-sectional area normal to velocity}\\
    \rho&=\text{fluid density}\\
    V&=\text{velocity}\\
\end{align*}

Based on the ratio of the diameter to the length of the main body of the uDrone, the Coefficient of drag in the direction of motion is estimated at 0.8. The density of salt water is 1024kg/m$^3$ and the surface area is calculated from the diameter of the eight inch cylinder, which is 0.037m$^2$. Putting this all together, damping force can be calculated as a function of velocity. This is:

\begin{gather}
    \boldsymbol{D}(\boldsymbol{\nu})\boldsymbol{\nu}=\left[\begin{array}{c}
        -15.0u ^2 \\ \sim 0 \\ \sim 0 \\ D_{roll} \\ D_{pitch} \\ D_{yaw}
     \end{array}\right]
\end{gather}

$u$ is the velocity in the x body direction. The last three values which refer to the rotational damping. For the purposes of calculations in the next section these values were assumed to be zero. The second and third terms, however, will always be zero, or nearly zero, as the vehicle cannot independently move in the Y or Z direction.

\section{Control Inputs}\label{control_inputs}

The control inputs are the forces put on the uDrone from the thrusters. The four motor of the uDrone are arranged on a plane, all facing the same direction. The center point between all the thrusters along that plane is the Center of Origin $C_O$ for the vehicle. Thrusters one and three spin in a counterclockwise direction while thrusters two and four spin clockwise for forward thrust. This ensures that the vehicle has no roll moment when moving forward. Figure \ref{cord_frame} shows the uDrone with the $C_O$ and rotation direction of the thrusters.

\begin{figure}[h]
\includegraphics[width=\maxwidth{\textwidth}]{img/cord_frame.png}
\caption{uDrone Coordinate Frame and Motor Directions}
\label{cord_frame}
\end{figure}

Using this convention it is possible to determine the actuation matrix, tau, as a function of thruster inputs.

\begin{gather}
    \boldsymbol{\tau}=\left[\begin{array}{c}
        F_1+F_2+F_3+F_4 \\ 0 \\ 0 \\ M_1-M_2+M_3-M_4 \\ (F_2+F_3-F_1-F_4) \frac{L}{\sqrt{2}} \\ (F_1+F_2-F_3-F_4) \frac{L}{\sqrt{2}}
     \end{array}\right]
     \label{tau}
\end{gather}

In equation \ref{tau} $F_x$ indicates the linear force produced by the $x^{th}$ motor and $M_x$ indicates the angular momentum produced by the $x^{th}$. $L$ is 0.115m, the length from $C_O$ to the center of the motor, which is the same for each motor. Unfortunately, there is no data from Blue Robotics about the moment of the thrusters, so the relationship between control input to the roll moment will need to be determined experimentally. Data is available, however, correlating motor power and thrust force.

\begin{figure}[h]
\includegraphics[width=\maxwidth{\textwidth}]{img/force_amps.png}
\caption{Force Output vs. Current Draw for T200 Thruster at 14 Volts}
\label{force_amp}
\legend{\emph{Source}: \iftoggle{usebiblatex}{\textcite{t200}}{\citet{t200}}}% See: https://upload.wikimedia.org/wikipedia/commons/8/89/Antidorcas_marsupialis%2C_male_%28Etosha%2C_2012%29.jpg
% \legend{\emph{Note}: Here is a note that is especially long to show what happens when it extends to more than one line.}
\end{figure}

Using the figure \ref{force_amp}, along with data about the uDrone battery, it is possible to calculate the maximum velocity, running time at this velocity, and running time at the operational velocity of 1m/s. While the uDrone can carry two 14V, 18Ah batteries, the intent is to use one for thrusters and the other to control all electronics. Therefore, all longevity calculations are done assuming 18Ah are available for thruster actuation.

In order to calculate maximum velocity, the drag equation is set equal to the maximum thruster force. The T200 thrusters produce a maximum thrust of 41.68N each. This is 166.7N of total thrust. Setting this equal to $15u^2$ and solving yields a maximum speed of 3.33m/s. Maintaining this velocity takes 20.29A, for a total of 81.16A. The uDrone could only maintain this speed for approximately 13.3 minute with an 18Ah battery.

Typically, however, the uDrone will be cruising at a speed of 1m/s. At this speed, the drag force is approximately 15N. To maintain this thrust each motor must produce about 3.75N of force. To maintain this force each motor will use approximately 0.5A, for a total of 2A. In order to stay conservative, a 50\% safety factor will be added to this value to account for uncalculated drag forces and actuation that affect orientations, not just forward motion. With this addition, the vehicle will use 3A for actuation during normal operation. With a single 18Ah battery used for thrusters, this will yield a dive time of approximately 6 hours.


\section*{Motivation}

\subsection*{Why are we interested in the Ising model?}
%\subsection{The Ising model: a model found in statistical mechanics}

\begin{frame}
	  	The Ising model is a mathematical model of ferromagnetism in statistical mechanics.

    Probability of a configuration $\sigma$ ({\color{TurkishRose}\textit{Boltzmann distribution}}):
    \begin{align*}
    P_\beta(\sigma) & = e^{-\beta H(\sigma)} / Z(G), \\
    Z(G) & = \sum_{\sigma \colon V \to \{+,-\}} e^{- \beta H(\sigma)}.
    \end{align*}

    \begin{itemize}
    	\item $Z(G)$ is \textit{the partition function of the Ising model}.
    	\item $Z(G)$ encodes information about the physical system.
    \end{itemize}
\end{frame}

\begin{frame}
		     \begin{align*}
		     P_\beta(\sigma) & = e^{-\beta H(\sigma)} / Z(G), \\
		     Z(G) & = \sum_{\sigma \colon V \to \{+,-\}} e^{- \beta H(\sigma)}.
		     \end{align*}

	\begin{enumerate}
		\item {\color{TurkishRose} \textbf{Problem:}} What is the complexity of evaluating $Z(G)$? \\
		%{\color{TurkishRose}\textbf{Answer:}}
		$\# \mathfs{P}$-hard in some cases.

		\item For some of those cases, $Z(G)$ admits a \textit{fully polynomial-time randomised approximation scheme} \\
		(Jerrum and Sinclair, 1993,  G\"odel prize in 1996).

		\item {\color{TurkishRose} \textbf{Problem:}} What is the complexity of approximating $Z(G)$?

		\item {\color{TurkishRose} \textbf{Application:}}  Strongly simulating \textit{instantaneous quantum polynomial-time circuits} is equivalent to approximating $|Z(G)|$ for some parameters.
	\end{enumerate}
\end{frame}


\section{Error Calculation}
\label{sec:Error_Calculation}
This section contains the error calculation of the measured values. The error calculation is done for the fitted values width $w$, diameter $d$ and grid constant $g$ (see sections \ref{subsec:Slit} to \ref{subsec:Cross-Grid}).

\subsection{Uncertainties}
\label{subsec:Uncertainties}
All conducted measurements in this experiment have uncertainties. Although it was possible to read the position on the y-axis to half a millimeter, the uncertainty is still one millimeter. This is due to the difficulty to find the exact center of the minima or maxima. The systematic uncertainties are shown in table \ref{tab:equipment} ($s_x = 1$ mm and $s_y = 1$ mm).

\subsection{Uncertainty of the Angle $\varphi$}
\label{subsec:Uncertainty_Angle}
The uncertainty $s_\varphi$ of the angle $\varphi$ is calculated with the following equation \ref{eq:uncertainty_angle}:

\begin{equation}
s_{\varphi}=\sqrt{\left(\frac{\partial \varphi}{\partial x}\Biggr|_{\varphi}\cdot s_{x}\right)^2 + \left(\frac{\partial \varphi}{\partial y}\Biggr|_{\varphi}\cdot s_{y}\right)^2}
\label{eq:uncertainty_angle}
\end{equation}

with:

\[
\frac{\partial \varphi}{\partial x}\Biggr|_{\varphi}=-\frac{y}{x^2+y^2} \qquad , \qquad \frac{\partial \varphi}{\partial y}\Biggr|_{\varphi}=\frac{x}{x^2+y^2}
\]

where:
\begin{conditions}
	s_{\varphi} & uncertainty of $\varphi$ \\
	s_x & uncertainty of x \\
	s_y & uncertainty of y \\
	x & distance between the aperture and the projection surface (see figure \ref{fig:experimental_arrangement}) \\
	y & position of the maxima or the minima
\end{conditions}

\subsection{Uncertainty of the Width $w$}
\label{subsec:Uncertainty_Width}
To derive the total uncertainty of the width $w$ the following equations are used. The statistical uncertainty $s_{w,\ \text{stat}}$ is obtained from the fits (from QtiPlot).

\begin{equation}
s_{w,\ \text{tot}}=\sqrt{s_{w,\ \text{syst}}^2+s_{w,\ \text{stat}}^2}
\label{eq:total_uncertainty_w}
\end{equation}

with:
\begin{equation}
s_{w,\ \text{syst}}=\sqrt{\left(\frac{\partial w}{\partial \varphi}\Biggr|_{w}\cdot s_{\varphi}\right)^2}
\label{eq:syst_uncertainty_w}
\end{equation}

where:
\begin{conditions}
	s_{w,\ \text{tot}} & total uncertainty of $w$ \\
	s_{w,\ \text{syst}} & systematic uncertainty of $w$ \\
	s_{w,\ \text{stat}} & statistical uncertainty of $w$ \\
	s_{\varphi} & uncertainty of $\varphi$
\end{conditions}

\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\subsubsection{Calculated Uncertainties of the Width $w$ (Slit)}
\label{subsubsec:Uncertainty_Width_Slit}
\addtocontents{toc}{\protect\setcounter{tocdepth}{3}}
The systematic uncertainty was calculated by using equation \ref{eq:slit_maxima} and equation \ref{eq:syst_uncertainty_w}. The statistical uncertainty was obtained from table \ref{tab:Slit}. The total uncertainty was calculated by using equation \ref{eq:total_uncertainty_w}. All calculations were done in MATLAB (see appendix \ref{sec:MATLAB_Error_Calculation}).

\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.3}
	\begin{tabular}{r||c|c|c}
		& \textbf{Systematic} ($\mu$m) & \textbf{Statistical} ($\mu$m) & \textbf{Total} ($\mu$m) \\
		\hline\hline
		\textbf{Slit 40 $\mu$m} & -0.92 & 0.10 & 0.93 \\
		\textbf{Slit 100 $\mu$m} & -6.77 & 0.14 & 6.77 \\
	\end{tabular}
	\caption{Calculated Uncertainties for the Width $w$ of the Slit}
	\label{tab:Calculated_Uncertainties_Width_Slit}
\end{table}

To calculate the uncertainty of the 40 $\mu$m slit and the 100 $\mu$m slit the 1st order ($m = 1$) was used. It is generally best to use a low order number (greater uncertainty).

\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\subsubsection{Calculated Uncertainties of the Width $w$ (Anti-Slit)}
\label{subsubsec:Uncertainty_Width_Anti-Slit}
\addtocontents{toc}{\protect\setcounter{tocdepth}{3}}
The systematic uncertainty was calculated by using equation \ref{eq:slit_maxima} and equation \ref{eq:syst_uncertainty_w}. The statistical uncertainty was obtained from table \ref{tab:Anti-Slit}. The total uncertainty was calculated by using equation \ref{eq:total_uncertainty_w}. All calculations were done in MATLAB (see appendix \ref{sec:MATLAB_Error_Calculation}).

\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.3}
	\begin{tabular}{r||c|c|c}
		& \textbf{Systematic} ($\mu$m) & \textbf{Statistical} ($\mu$m) & \textbf{Total} ($\mu$m) \\
		\hline\hline
		\textbf{Anti-Slit 230 $\mu$m} & -23.33 & 0.34 & 23.34 \\
		\textbf{Anti-Slit 124 $\mu$m} & -6.80 & 0.08 & 6.80 \\
	\end{tabular}
	\caption{Calculated Uncertainties for the Width $w$ of the Anti-Slit}
	\label{tab:Calculated_Uncertainties_Width_Anti-Slit}
\end{table}

To calculate the uncertainty of the 230 $\mu$m anti-slit the 6th order was used. To calculate the uncertainty of the 124 $\mu$m anti-slit the 1st order was used.It is generally best to use a low order number (greater uncertainty).

\newpage

\subsection{Uncertainty of the Diameter $d$}
\label{subsec:Uncertainty_Diameter}
To derive the total uncertainty of the diameter $d$ the following equations are used. The statistical uncertainty $s_{d,\ \text{stat}}$ is obtained from the fits (from QtiPlot).

\begin{equation}
s_{d,\ \text{tot}}=\sqrt{s_{d,\ \text{syst}}^2+s_{d,\ \text{stat}}^2}
\label{eq:total_uncertainty_d}
\end{equation}

with:
\begin{equation}
s_{d,\ \text{syst}}=\sqrt{\left(\frac{\partial d}{\partial \varphi}\Biggr|_{d}\cdot s_{\varphi}\right)^2}
\label{eq:syst_uncertainty_d}
\end{equation}

where:
\begin{conditions}
	s_{d,\ \text{tot}} & total uncertainty of $d$ \\
	s_{d,\ \text{syst}} & systematic uncertainty of $d$ \\
	s_{d,\ \text{stat}} & statistical uncertainty of $d$ \\
	s_{\varphi} & uncertainty of $\varphi$
\end{conditions}

\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\subsubsection{Calculated Uncertainties of the Diameter $d$ (Circular Aperture)}
\label{subsubsec:Uncertainty_Diameter_Circular-Aperture}
\addtocontents{toc}{\protect\setcounter{tocdepth}{3}}

The systematic uncertainty was calculated by using equation \ref{eq:circular_aperture} and equation \ref{eq:syst_uncertainty_d}. The statistical uncertainty was obtained from table \ref{tab:Circular_Apertures}. The total uncertainty was calculated by using equation \ref{eq:total_uncertainty_d}. All calculations were done in MATLAB (see appendix \ref{sec:MATLAB_Error_Calculation}).

\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.3}
	\begin{tabular}{r||c|c|c}
		& \textbf{Systematic} ($\mu$m) & \textbf{Statistical} ($\mu$m) & \textbf{Total} ($\mu$m) \\
		\hline\hline
		\textbf{Circular Aperture 150 $\mu$m} & -10.21 & 0.83 & 10.24 \\
		\textbf{Circular Aperture 100 $\mu$m} & -4.57 & 0.55 & 4.60 \\
	\end{tabular}
	\caption{Calculated Uncertainties for the Diameter $d$}
	\label{tab:Calculated_Uncertainties_Diameter}
\end{table}

To calculate the uncertainty of the 150 $\mu$m circular aperture and the 100 $\mu$m circular aperture the 2nd Bessel coefficient ($c = 2.233$) was used (see table \ref{eq:coeffs}). It is generally best to use a low "order" number (greater uncertainty).

\newpage

\subsection{Uncertainty of the Grid Constant $g$}
\label{subsec:Uncertainty_Grid_Constant}
To derive the total uncertainty of the grid constant $g$ the following equations are used. The statistical uncertainty $s_{g,\ \text{stat}}$ is obtained from the fits (from QtiPlot).

\begin{equation}
s_{g,\ \text{tot}}=\sqrt{s_{g,\ \text{syst}}^2+s_{g,\ \text{stat}}^2}
\label{eq:total_uncertainty_g}
\end{equation}

with:
\begin{equation}
s_{g,\ \text{syst}}=\sqrt{\left(\frac{\partial g}{\partial \varphi}\Biggr|_{g}\cdot s_{\varphi}\right)^2}
\label{eq:syst_uncertainty_g}
\end{equation}

where:
\begin{conditions}
	s_{g,\ \text{tot}} & total uncertainty of $g$ \\
	s_{g,\ \text{syst}} & systematic uncertainty of $g$ \\
	s_{g,\ \text{stat}} & statistical uncertainty of $g$ \\
	s_{\varphi} & uncertainty of $\varphi$
\end{conditions}

\addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
\subsubsection{Calculated Uncertainties of the Grid Constant $g$ (Cross-Grid)}
\label{subsubsec:Uncertainty_Grid_Constant_Cross-Grid}
\addtocontents{toc}{\protect\setcounter{tocdepth}{3}}

The systematic uncertainty was calculated by using equation \ref{eq:cross-grid} and equation \ref{eq:syst_uncertainty_g}. The statistical uncertainty was obtained from table \ref{tab:Cross-Grid}. The total uncertainty was calculated by using equation \ref{eq:total_uncertainty_g}. All calculations were done in MATLAB (see appendix \ref{sec:MATLAB_Error_Calculation}).

\begin{table}[H]
	\centering
	\renewcommand{\arraystretch}{1.3}
	\begin{tabular}{r||c|c|c}
		 & \textbf{Systematic} ($\mu$m) & \textbf{Statistical} ($\mu$m) & \textbf{Total} ($\mu$m) \\
		\hline\hline
		\textbf{Cross-Grid 28 $\mu$m} & -0.36 & 0.44 & 0.57 \\
		\textbf{Cross-Grid 50 $\mu$m} & -0.30 & 0.06 & 0.30 \\
	\end{tabular}
	\caption{Calculated Uncertainties for the Grid Constant $g$}
	\label{tab:Calculated_Uncertainties_Grid_Constant}
\end{table}

To calculate the uncertainty of the 28 $\mu$m cross-grid and the 50 $\mu$m cross-grid the 1st order ($m = 1$) was used. It is generally best to use a low order number (greater uncertainty).


% Copyright 2018-2021 Melvin Eloy Irizarry-Gelpí
\setcounter{chapter}{2}
\chapter{Circuits in Series and Parallel}
%
In this experiment you will learn about circuits connected in series or in parallel.
%
\section{Preliminary}
%
A \textbf{resistor} is any component in an electric circuit with \textbf{electrical resistance}. The SI unit for resistance is the ohm:
\begin{equation}
	1 \ \text{ohm} = 1 \ \text{V/A}
\end{equation}
Ohm's law is a statement that relates the voltage $V$ across a resistor to the amount of current $I$ leaving (or equivalently, entering) a resistor:
\begin{equation}
	V = R I
\end{equation}
Here, $R$ is the amount of electrical resistance. Solving for $R$ gives
\begin{equation} \label{eq.03.ROhmLaw}
	R = \frac{V}{I}
\end{equation}
For \textbf{ohmic resistors}, the ratio of voltage and current is fixed (i.e. constant) and \textbf{always} gives the same value. This is \textbf{not true} for \textbf{non-ohmic resistors}.

An electric circuit can contain many components that are connected with wires. The electric properties of the circuit will depend on \textbf{how} these components are connected. You are going to look at two ways of connecting two components in a circuit to a battery: \textbf{series} and \textbf{parallel}.
%
\subsection{Circuits in Series}
%
A collection of two resistors in \textbf{series} can be replaced by an \textbf{equivalent resistor} with a resistance given by the sum of the individual resistances:
\begin{equation} \label{eq.03.RSeries}
	R_{\text{eq}} = R_{1} + R_{2}
\end{equation}
When two resistors are connected in \textbf{series} to a battery, the \textbf{current} $I_{0}$ leaving the battery is the \textbf{same} as the \textbf{current} $I_{1}$ leaving resistor 1, and also the same as the \textbf{current} $I_{2}$ leaving resistor 2:
\begin{equation} \label{eq.03.ISeries}
	I_{0} = I_{1} = I_{2}
\end{equation}
When two resistors are connected in \textbf{series} to a battery, the \textbf{voltage} $V_{0}$ across the battery is \textbf{split} between the \textbf{voltage} $V_{1}$ across resistor 1, and the \textbf{voltage} $V_{2}$ across resistor 2:
\begin{equation} \label{eq.03.VSeries}
	V_{0} = \left| V_{1} + V_{2} \right|
\end{equation}
The absolute value is needed because the voltage across each resistor is \textbf{negative} since it correspond to an \textbf{electric potential drop}.
%
\subsection{Circuits in Parallel}
%
A collection of two resistors in \textbf{parallel} can be replaced by an \textbf{equivalent resistor} with a resistance that satisfies the relation
\begin{equation}
	\frac{1}{R_{\text{eq}}} = \frac{1}{R_{1}} + \frac{1}{R_{2}}
\end{equation}
Solving for the equivalent resistance gives
\begin{equation} \label{eq.03.RParallel}
	R_{\text{eq}} = \frac{R_{1} R_{2}}{R_{1} + R_{2}}
\end{equation}
When two resistors are connected in \textbf{parallel} to a battery, the \textbf{current} $I_{0}$ leaving the battery is split between the \textbf{current} $I_{1}$ leaving resistor 1, and the \textbf{current} $I_{2}$ leaving resistor 2:
\begin{equation} \label{eq.03.IParallel}
	I_{0} = I_{1} + I_{2}
\end{equation}
When two resistors are connected in \textbf{parallel} to a battery, the \textbf{voltage} $V_{0}$ across the battery has the same magnitude as the \textbf{voltage} $V_{1}$ across resistor 1, and also the same magnitude as the \textbf{voltage} $V_{2}$ across resistor 2:
\begin{equation} \label{eq.03.VParallel}
	V_{0} = \left| V_{1} \right| = \left| V_{2} \right|
\end{equation}
Again, remember that the voltage across a resistor (measured in the direction along the current) is negative because it correspond to a drop in electric potential.
%
\subsection{Power}
%
The power $P$ input or output of a component in an electric circuit can be found by multiplying the voltage $V$ across that component, and the amount of current $I$ leaving that component:
\begin{equation}
	P = VI
\end{equation}
The SI unit for power is the \textbf{watt} (W). One watt is equivalent to one joule of energy consumed or generated per second:
\begin{equation}
	1 \ \text{W} = 1 \ \text{J/s}
\end{equation}
Since power equals voltage multiplied by current, you also have
\begin{equation}
	1 \ \text{W} = 1 \ \text{V {\textperiodcentered} A}
\end{equation}
%
\section{Experiment}
%
There are four experiments. The first two experiments involve using \textbf{two ohmic} resistors. The other two experiments use \textbf{two non-ohmic} resistors (light bulbs).
%
\subsection{Part 1: Resistors in Series}
%
In this part, you connect two \textbf{resistors} in \textbf{series} to a battery.
%
\subsection{Part 2: Resistors in Parallel}
%
In this part, you connect two \textbf{resistors} in \textbf{parallel} to a battery.
%
\subsection{Part 3: Light Bulbs in Series}
%
In this part, you connect two \textbf{light bulbs} in \textbf{series} to a battery.
%
\subsection{Part 4: Light Bulbs in Parallel}
%
In this part, you connect two \textbf{light bulbs} in \textbf{parallel} to a battery.
%
\section{Analysis}
%
Each run is a measurement of either \textbf{voltage} (electric potential difference between two points) or \textbf{current}. If the voltage and current sensors were zeroed correctly, then the measurement over time should correspond to the measurement of the desired quantity, and no offset or baseline needs to be taken into account. One way to determine a single value is to take the \textbf{time-average}.

Note that each \textbf{voltage measurement has three decimal figures}, and each \textbf{current measurement has four decimal figures}. You should round your time-averaged values appropriately.

In each part there are three components: one battery and two resistors (or two light bulbs). There are \textbf{six quantities} that describe the system:
\begin{itemize}
	\item Time-averaged voltage across the battery: $V_{0}$
	\item Time-averaged voltage across resistor/bulb 1: $V_{1}$
	\item Time-averaged voltage across resistor/bulb 2: $V_{2}$
	\item Time-averaged current leaving the battery: $I_{0}$
	\item Time-averaged current leaving resistor/bulb 1: $I_{1}$
	\item Time-averaged current leaving resistor/bulb 2: $I_{2}$
\end{itemize}
These six quantities satisfy certain mathematical relations. Note that $V_{1}$ and $V_{2}$ are measured to be negative.
%
\subsection{Part 1: Two Resistors in Series}
%
For the two \textbf{resistors in series}, you find the time average for all six quantities above and fill a table similar to Table \ref{table.03.resistors.series}.

You should check that relations Equation (\ref{eq.03.ISeries}) and Equation (\ref{eq.03.VSeries}) hold true. The percent difference between the labeled resistance and the prediction Equation (\ref{eq.03.ROhmLaw}) from Ohm's law should be very small. The resistance of the battery should be very close to the \textbf{series equivalent} resistance in Equation (\ref{eq.03.RSeries}).
%
\subsection{Part 2: Two Resistors in Parallel}
%
For the two \textbf{resistors in parallel}, you find the time average for all six quantities above and fill a table similar to Table \ref{table.03.resistors.parallel}.

You should check that relations Equation (\ref{eq.03.IParallel}) and Equation (\ref{eq.03.VParallel}) hold true. The percent difference between the labeled resistance and the prediction Equation (\ref{eq.03.ROhmLaw}) from Ohm's law should be very small. The resistance of the battery should be very close to the \textbf{parallel equivalent} resistance in Equation (\ref{eq.03.RParallel}).
%
\subsection{Part 3: Two Light Bulbs in Series}
%
For two \textbf{light bulbs in series}, you can find the time average for all six quantities mentioned above, and fill a table similar to Table \ref{table.03.bulbs.series}. Note that the fourth column consist of the ratio of voltage and current for each component. This is a quantity with units of resistance (ohms) but it does not correspond to the actual resistance of the light bulbs. As you will find, the light bulbs are not ohmic, and thus the ratio of the voltage across the light bulb and the current leaving the light bulb is not constant. However, you should find that the relations Equation (\ref{eq.03.ISeries}) and Equation (\ref{eq.03.VSeries}) again hold.
%
\subsection{Part 4: Two Light Bulbs in Parallel}
%
For two \textbf{light bulbs in parallel}, you can find the time average for all six quantities mentioned above, and table similar to Table \ref{table.03.bulbs.parallel}. Note that the fourth column consist of the ratio of voltage and current for each component. You can verify that the light bulbs are not ohmic by showing that the values in the fourth column in Tables \ref{table.03.bulbs.series} and \ref{table.03.bulbs.parallel} are very different. However, you should find that the relations Equation (\ref{eq.03.IParallel}) and Equation (\ref{eq.03.VParallel}) again hold.
%
\section{My Data}
%
For parts 1 and 2, I used \textbf{three} resistors, instead of two. The resistances are given by
\begin{align}
	R_{1} = 10 \text{ ohm} && R_{2} = 51 \text{ ohm} && R_{3} = 68 \text{ ohm}
\end{align}
The equivalent resistance in \textbf{series} with three resistors is given by
\begin{equation}
	R_{\text{eq}} = R_{1} + R_{2} + R_{3}
\end{equation}
In parallel, the equivalent resistant satisfies the following relation:
\begin{equation}
	\frac{1}{R_{\text{eq}}} = \frac{1}{R_{1}} + \frac{1}{R_{2}} + \frac{1}{R_{3}}
\end{equation}
Solving for the equivalent resistance in \textbf{parallel} gives
\begin{equation}
	R_{\text{eq}} = \frac{R_{1} R_{2} R_{3}}{R_{1} R_{2} + R_{1} R_{3} + R_{2} R_{3}}
\end{equation}
As you can see from my spreadsheet, the results are in good agreement with expectations.
%
\subsection{Part 1: Three Resistors in Series}
%
Table \ref{table.03.3resistors.series} has the results for three resistors in series. You can check that the values for the current in the third column are all very close. Indeed,
\begin{equation}
	I_{0} \approx I_{1} \approx I_{2} \approx I_{3}
\end{equation}
This is the three-resistor analog of Equation (\ref{eq.03.ISeries}). Also, you can check that
\begin{equation}
	| V_{1} + V_{2} + V_{3} | = 3.075 \text{ V}
\end{equation}
which is very close to the value of $V_{0}$ (the voltage across the battery). This is the three-resistor analog of Equation (\ref{eq.03.VSeries}).

The last column in Table \ref{table.03.3resistors.series} contains the power generated/consumed by the corresponding component. As you can see, the rate of energy generation for the battery is very close to the sum of the rate of consumption for each resistor. Note that, in \textbf{series}, the resistor with the \textbf{largest} resistance consumes the most energy.
%
\subsection{Part 2: Three Resistors in Parallel}
%
Table \ref{table.03.3resistors.parallel} has the results for three resistors in parallel. You can check that, ignoring the signs, the values for the voltage in the second column are all very close. Indeed,
\begin{equation}
	V_{0} \approx |V_{1}| \approx |V_{2}| \approx |V_{3}|
\end{equation}
This is the three-resistor analog of (\ref{eq.03.VParallel}). Also, you can check that
\begin{equation}
	I_{1} + I_{2} + I_{3}  = 0.3532 \text{ A}
\end{equation}
which is very close to the value of $I_{0}$ (the current leaving the battery). This is the three-resistor analog of Equation (\ref{eq.03.IParallel}).

The last column in Table \ref{table.03.3resistors.parallel} contains the power generated/consumed by the corresponding component. As you can see, the rate of energy generation for the battery is very close to the sum of the rate of consumption for each resistor. Note that, in \textbf{parallel}, the resistor with the \textbf{smallest} resistance consumes the most energy.

One last thing about resistors: proof that they \textbf{are ohmic} (at least for the amount of voltage and current that we used) is that the values in the fourth column in Tables \ref{table.03.3resistors.series} and \ref{table.03.3resistors.parallel} are consistent (except for the first value, because it corresponds to the equivalent resistance). That is, it does not matter if they are connected in series or parallel, the amount of current going through the resistor is proportional to the amount of voltage across the resistor.
%
\subsection{Part 3: Two Light Bulbs in Series}
%
The six runs in the text file \texttt{bulbs-serial.txt} are for two light bulbs connected in series.
\begin{itemize}
	\item Run 1: measurement of voltage across battery ($V_{0}$).
	\item Run 2: measurement of voltage across long light bulb ($V_{L}$).
	\item Run 3: measurement of voltage across round light bulb ($V_{R}$).
	\item Run 4: measurement of current leaving battery ($I_{0}$).
	\item Run 5: measurement of current leaving long light bulb ($I_{L}$).
	\item Run 6: measurement of current leaving round light bulb ($I_{R}$).
\end{itemize}
The \textbf{long} light bulb is connected \textbf{first}, and the \textbf{round} light bulb is connected \textbf{second}.
%
\subsection{Part 4: Two Light Bulbs in Parallel}
%
The six runs in the text file \texttt{bulbs-parallel.txt} are for two light bulbs connected in parallel.
\begin{itemize}
	\item Run 1: measurement of voltage across battery ($V_{0}$).
	\item Run 2: measurement of voltage across long light bulb ($V_{L}$).
	\item Run 3: measurement of voltage across round light bulb ($V_{R}$).
	\item Run 4: measurement of current leaving battery ($I_{0}$).
	\item Run 5: measurement of current leaving long light bulb ($I_{L}$).
	\item Run 6: measurement of current leaving round light bulb ($I_{R}$).
\end{itemize}
%
\section{Your Data}
%
If your data for resistors in series and/or parallel is not good, let me know via email and I will make data available to you.
%
% \newpage
% \section{Your Lab Report}
% %
% In your lab report you should include:
% \begin{enumerate}
% 	\item One table like Table \ref{table.03.resistors.series} for two resistors in series.
% 	\item One table like Table \ref{table.03.resistors.parallel} for two resistors in parallel.
% 	\item One table like Table \ref{table.03.bulbs.series} for two light bulbs in series.
% 	\item One table like Table \ref{table.03.bulbs.parallel} for two light bulbs in parallel.
% \end{enumerate}
% You should also:
% \begin{enumerate}
% 	\item Verify that equations (\ref{eq.03.ISeries}) and (\ref{eq.03.VSeries}) hold for two resistors, and also for two light bulbs, connected in series.
% 	\item Verify that the voltage across the battery divided by the current leaving the battery is close to (\ref{eq.03.RSeries}) for two resistors in series.
% 	\item Verify that equations (\ref{eq.03.IParallel}) and (\ref{eq.03.VParallel}) hold for two resistors, and also for two light bulbs, connected in parallel.
% 	\item Verify that the voltage across the battery divided by the current leaving the battery is close to (\ref{eq.03.RParallel}) for two resistors in parallel.
% 	\item Confirm that the long light bulb is non-ohmic by comparing the ratio of the voltage and the current $V_{1} / I_{1}$ in series and in parallel.
% 	\item Confirm that the round light bulb is non-ohmic by comparing the ratio of the voltage and the current $V_{2} / I_{2}$ in series and in parallel.
% 	\item Find which resistor consumes more power when two resistors are connected in series.
% 	\item Find which resistor consumes more power when two resistors are connected in parallel.
% 	\item Find which light bulb consumes more power when two light bulbs are connected in series.
% 	\item Find which light bulb consumes more power when two light bulbs are connected in parallel.
% \end{enumerate}
%
\newpage
\section{Tables}
%
\begin{table}[ht]
	\begin{center}
		\begin{tabular}{l|r|r|r}
            \textbf{Quantity} & \textbf{Battery} & \textbf{Resistor 1} & \textbf{Resistor 2} \\
            \hline
            Voltage (V) & $V_{0}$ & $V_{1}$ & $V_{2}$ \\
            Current (A) & $I_{0}$ & $I_{1}$ & $I_{2}$ \\
            \hline
            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{1} / I_{1}$ & $V_{2} / I_{2}$ \\
            Expected Resistance (ohm) & $R_{1} + R_{2}$ & $R_{1}$ & $R_{2}$ \\
            Percent Difference (\%) & & & \\
            \hline
            Power (W) & $V_{0} I_{0}$ & $V_{1} I_{1}$ & $V_{2} I_{2}$ \\
            \hline
        \end{tabular}
	\end{center}
	\caption{Time-averages and resistance for two resistors in series.}
	\label{table.03.resistors.series}
\end{table}
%
\begin{table}[ht]
	\begin{center}
		\begin{tabular}{l|r|r|r}
            \textbf{Quantity} & \textbf{Battery} & \textbf{Resistor 1} & \textbf{Resistor 2} \\
            \hline
            Voltage (V) & $V_{0}$ & $V_{1}$ & $V_{2}$ \\
            Current (A) & $I_{0}$ & $I_{1}$ & $I_{2}$ \\
            \hline
            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{1} / I_{1}$ & $V_{2} / I_{2}$ \\
            Expected Resistance (ohm) & $R_{1} R_{2} / (R_{1} + R_{2})$ & $R_{1}$ & $R_{2}$ \\
            Percent Difference (\%) & & & \\
            \hline
            Power (W) & $V_{0} I_{0}$ & $V_{1} I_{1}$ & $V_{2} I_{2}$ \\
            \hline
        \end{tabular}
	\end{center}
	\caption{Time-averages and resistance for two resistors in parallel.}
	\label{table.03.resistors.parallel}
\end{table}
%
\begin{table}[ht]
	\begin{center}
		\begin{tabular}{l|r|r|r}
            \textbf{Quantity} & \textbf{Battery} & \textbf{Long bulb} & \textbf{Round bulb} \\
            \hline
            Voltage (V) & $V_{0}$ & $V_{L}$ & $V_{R}$ \\
            Current (A) & $I_{0}$ & $I_{L}$ & $I_{R}$ \\
            \hline
            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{L} / I_{L}$ & $V_{R} / I_{R}$ \\
            Power (W) & $V_{0} I_{0}$ & $V_{L} I_{L}$ & $V_{R} I_{R}$ \\
            \hline
        \end{tabular}
	\end{center}
	\caption{Time-averages and power for two light bulbs in series.}
	\label{table.03.bulbs.series}
\end{table}
%
\begin{table}[ht]
	\begin{center}
		\begin{tabular}{l|r|r|r}
            \textbf{Quantity} & \textbf{Battery} & \textbf{Long bulb} & \textbf{Round bulb} \\
            \hline
            Voltage (V) & $V_{0}$ & $V_{L}$ & $V_{R}$ \\
            Current (A) & $I_{0}$ & $I_{L}$ & $I_{R}$ \\
            \hline
            Observed Resistance (ohm) & $V_{0} / I_{0}$ & $V_{L} / I_{L}$ & $V_{R} / I_{R}$ \\
            Power (W) & $V_{0} I_{0}$ & $V_{L} I_{L}$ & $V_{R} I_{R}$ \\
            \hline
        \end{tabular}
	\end{center}
	\caption{Time-averages and power for two light bulbs in parallel.}
	\label{table.03.bulbs.parallel}
\end{table}
%
\begin{table}[ht]
	\begin{center}
		\begin{tabular}{l|r|r|r|r}
			\textbf{Quantity} & \textbf{Battery} & \textbf{Resistor 1} & \textbf{Resistor 2} & \textbf{Resistor 3} \\
			\hline
			Voltage (V) & 4.430 & \textminus 0.338 & \textminus 1.757 & \textminus 2.345 \\
			Current (A) & 0.0346 & 0.0346 & 0.0347 & 0.0347 \\
			\hline
			Observed Resistance (ohm) & 128.05 & 9.76 & 50.70 & 67.68 \\
			Expected Resistance (ohm) & 129 & 10 & 51 & 68 \\
			Percent Difference (\%) & \textminus 0.73 & \textminus 2.36 & \textminus 0.58 & \textminus 0.46 \\
			\hline
			Power (W) & 0.15 & \textminus 0.01 & \textminus 0.06 & \textminus 0.08 \\
			\hline
		\end{tabular}
	\end{center}
	\caption{Time-averages and resistance for three resistors in series.}
	\label{table.03.3resistors.series}
\end{table}
%
\begin{table}[ht]
	\begin{center}
		\begin{tabular}{l|r|r|r|r}
			\textbf{Quantity} & \textbf{Battery} & \textbf{Resistor 1} & \textbf{Resistor 2} & \textbf{Resistor 3} \\
			\hline
			Voltage (V) & 3.731 & \textminus 3.707 & \textminus 3.736 & \textminus 3.734 \\
			Current (A) & 0.4904 & 0.3722 & 0.0739 & 0.0554 \\
			\hline
			Observed Resistance (ohm) & 7.61 & 9.96 & 50.55 & 67.37 \\
			Expected Resistance (ohm) & 7.45 & 10 & 51 & 68 \\
			Percent Difference (\%) & 2.20 & \textminus 0.39 & \textminus 0.88 & \textminus 0.92 \\
			\hline
			Power (W) & 1.83 & \textminus 1.38 & \textminus 0.28 & \textminus 0.21 \\
			\hline
		\end{tabular}
	\end{center}
	\caption{Time-averages and resistance for three resistors in parallel.}
	\label{table.03.3resistors.parallel}
\end{table}
%
\FloatBarrier
\newpage
\section{Figures}
%
\begin{figure}[ht]
	\centering
	\includegraphics[scale=0.74]{image/03-serial-parallel/resistor-V.pdf}
	\caption{Voltage across ohmic resistor}
	\label{figure.03.resistor.v}
\end{figure}
%
\begin{figure}[ht]
	\centering
	\includegraphics[scale=0.74]{image/03-serial-parallel/resistor-I.pdf}
	\caption{Current through ohmic resistor}
	\label{figure.03.resistor.i}
\end{figure}
%
\begin{figure}[ht]
	\centering
	\includegraphics[scale=0.74]{image/03-serial-parallel/bulb-V.pdf}
	\caption{Voltage across non-ohmic light bulb}
	\label{figure.03.bulb.v}
\end{figure}
%
\begin{figure}[ht]
	\centering
	\includegraphics[scale=0.74]{image/03-serial-parallel/bulb-I.pdf}
	\caption{Current through non-ohmic light bulb}
	\label{figure.03.bulb.i}
\end{figure}


\subsection{Theoretical Results}

\hogwild's original article \cite{2011NRRW} manages to prove that the
asynchronous noise generated by \hogwild, under certain sparsity assumptions of
the $f_i$'s, converged at the same rate as seen in the stochastic gradient
method. However, a newer article from 2015 by De Sa et al. \cite{2015SZOR}
presented a new framework in the context of martingale theory, which drops said
sparsity assumptions and generalizes to certain non-convex formualations. Given
that I just learned about martingale theory essentially two weeks ago in Basic
Probability, and that much of my synthetic tests are on dense datasets, I feel
compelled to present this argument instead.

The following is a cleaned up summary of the arguments presented in the article,
except I focus on just demonstrating how martingale theory can be used to
generalize convergence arguments for a sequential stochastic gradient method to
the asynchronous case, and cut out the generalization required for the
non-convex situation.

\subsubsection{Initial Machinery}

First, recall the definition of a martingale:
\begin{definition} \label{def:martingale}
  \cite{2004JP} A sequence of random variables $(X_n)_{n \geq 0}$ is called
  a martingale, or an $(\mathcal{F}_n)$-martingale, if
  \begin{enumerate}[(i)]
    \item $\E{|X_n|} < \infty, \forall n$.
    \item $X_n$ is $\mathcal{F}_n$ measurable, $\forall n$.
    \item $\E{X_n \mid \mathcal{F}_m} = X_m$ a.s., $\forall m \leq n$.
  \end{enumerate}
  furthermore a supermartingale (submartingale) is one satisfying (i), (ii)
  exactly, and (iii) with $\leq\ (\geq)$ instead.
\end{definition}
Using this, the idea is to model our convergence with a non-negative
supermartingale $W_t(x_t, \dots, x_0)$ which is a function of the previous
stochastic gradient iterates. These $W_t$, when used in the theory later, will
be associated with specific stochastic algorithms, as an example below we'll see
it applied to serial stochastic gradient. However, given such a supermartingale,
and given a bounded stopping time $B$ (in literature known as a horizon), if our
stochastic gradient iterates are written as $x_{t+1} = x_t - \eta \nabla
f_t(x_t)$, where $\eta$ is the learning rate, and $f_t$ denotes the random
function chosen at time step $t$, then we see that condition (iii) in the above
definition implies that:
\[
  W_{t+1}(x_t - \eta \nabla f_t(x_t), x_t, \dots, x_0)
  \leq
  W_t(x_t, \dots, x_0), \forall t \leq B
\]
which certainly makes sense if our $-\nabla f_t(x_t)$ is a sufficient search
direction. Furthermore, letting our success region be denoted as $S
= B_\e(x^*)$, where $x^*$ is the minimizer of our optimization problem, if we
impose that if $x_t \not\in S, \forall t \leq T$ then:
\[
  W_T(x_T, \dots, x_0) \geq T
\]
then we call $W_t$ a {\it rate supermartingale}. To simplify notation, let $F_t$
be the event where $\nexists t \leq T$ such that $x_t \in S$.

A good example of the power of this machinery is proving a convergence bound on
the serial version of stochastic gradient: using (iii) of definition
\ref{def:martingale}, one can see that considering $F_T$:
\[
  \E{W_0(x_0)}
  \underbrace{\geq}
  \E{W_T}
  =
  \Prob{F_t}
  \underbrace{\Prob{F_T}\E{W_T | F_T}}_{W_T \geq T} +
  \underbrace{\Prob{F_T^c}\E{W_T | F_T^c}}_{W_T \geq 0}
  \geq
  \Prob{F_T}T
\]
where the first inequality is by Doob's optional sampling theorem. Thus for
a simple serial stochastic gradient method: $\Prob{F_t} = \E{W_0} / T$.

Now that we can characterize serial stochastic gradient in this model, we need
a method to analyze asynchronous noise. Recall that since we've guaranteed in
the description of \hogwild\ that writes to the iteration variable $x_t$ are
done atomically, the only race condition possible is when updates to entries of
$x_t$ are interleaved with either the other thread's updates or its reads on
$x_t$.

Indeed, when going to update the $i$th component of $x_{t+1}$, the variable used
to compute the gradient may have long since changed, making our iteration look
more like $x_{t+1} = x_t - \nabla f_t(v_t)$ where $v_t$'s entries were the
entries of some previous iterate $x$. Let $\tau_{i,t}$ denote the lag for the
update of the $i$th component of $x_{t+1}$, i.e. $(v_t)_i = ( x_{t-\tau_{i,t}}
)_i$. Then we recognize that this lag for each component $i$ (supposing the
computer hasn't crashed) must be bounded; let $\tau'$ be the the maximum over
$i$ of such bounds and let $\tau = \E{\tau'}$. This is known in literature as
the {\it worst-case expected delay}.

Finally, we need one last definition, mainly one of convinience, to proceed
onward. This describes the main conditions upon a rate supermartingale necessary
to prove that the asynchronous noise error is irrelevant to the convergence
rate.
\begin{definition}
  An algorithm with associated rate supermartingale $W$ is $(H, R, \xi)$-bounded
  if the following conditions hold.
  \begin{enumerate}[(1)]
    \item $W$ must be Lipschitz continuous in the current iterate with parameter
      $H$, i.e.
      \[
        \norm{W_t(u, x_{t-1}, \dots, x_0) - W_t(v, x_{t-1}, \dots, x_0)}
        \leq
        H\norm{u-v}, \forall t, u, v, x_t, \dots, x_0.
      \]
    \item $\nabla f$ must be Lipschitz continuous in expectation with parameter
      $R$, i.e.
      \[
        \E{||\nabla f(x) - \nabla f(y)||} \leq R\norm{u-v}
      \]
    \item The expected magnitude of the update must be bounded by $\xi$, i.e.
      \[
        \E{||\nabla f(x)||} \leq \xi
      \]
  \end{enumerate}
  Note that these look very familiar to the conditions in the stochastic
  gradient method convergence theorem (theorem \ref{thm:sgd}).
\end{definition}

\subsubsection{Convergence of \hogwild}

Finally, now that all of the machinery has been defined, we can get to the main
result:
\begin{theorem} \label{thm:convergence}
  Suppose we have an asynchronous stochastic algorithm with associated rate
  supermartingale $W$ which is $(H,R,\xi)$ bounded with horizon $B$.
  Furthermore, assume that $HR\xi \tau < 1$; then $\forall T \leq B$:
  \[
    \Prob{F_T} \leq \frac{\E{W(0, x_0)}}{(1-HR\xi\tau)T}
  \]
\end{theorem}
Before we prove it, we briefly discuss how to use this theorem in practice.
Suppose we have a loss function $f$ which we want to use \hogwild\ on to
minimize. Then first we need to obtain a rate supermartingale proving the
problem%
\footnote{
  In the article, De Sa et al. describes this as being no more difficult than
  proving serial convergence, but the proof (in the convex case) doesn't seem to
  have any similarity between it and serial convergence, so I can't validate
  this claim.
}, determine $H, R, \xi$ such that $W$ is $(H,R,\xi)$-bounded, and then apply
this theorem to get a proper rate of convergence. This is a very powerful
theorem, as we'll be able to state later, given strongly convex $f$ and with the
other required bounds, we can blanket prove that \hogwild\ works on them.
Furthermore, for nicer non-convex problems, such as the low-rank least-squared
matrix completion problem presented in the paper, it's easy to derive a proper
rate supermartingale as well.

Now, with respect to the proof, we only outline it because it's mainly just
a repeated application of the above bounds we have in order to lower bound away
noise terms, and then it follows the path outlined in the serial stochastic
gradient method proof.
\begin{proof}
  \begin{enumerate}[(i)]
    \item With $W$ defined exactly as in the serial case, it's not a rate
      supermartingale. Instead, from it we construct rate supermartingale $V_t$,
      where $\forall t, x$ where $x_u$ not converged $\forall u < t$:
      \[
        V_t(x_t, \dots, x_0) = W_t(x_t, \dots, x_0)
        - \underbrace{HR\xi \tau t}_{(1)}
        + \underbrace{
          HR \sum_{k=1}^\infty \norm{x_{t-k+1}-x_{t-k}} \sum_{m=k}^\infty
          \Prob{\tau' \geq m}
        }_{(2)}
      \]
      where (1) allows for longer iteration counts (as HOGWILD needs to allow
      for given noise corruption), and (2) measures distance between recent
      iterates. Otherwise if $x_u$ is converged, then we let $V_t(x_t, \dots,
      x_0) = V_u(x_u, \dots, x_0)$. Basically, we've defined $V$ a stopped
      process.
    \item Show $V_t$ is a rate supermartingale for \hogwild
    \item Using a similar process to the serial stochastic gradient proof, show
      that $\E{V_T} \leq \E{V_0} = \E{W_0}$, then using the law of total
      expectation on this with $F_T$, and recalling that $\E{W_T | F_T} \geq T$,
      we recieve the desired result.
  \end{enumerate}
\end{proof}
Given this, the general theorem for the convex case is:
\begin{theorem} \label{thm:convexconv}
  Consider trying to minimize $f$, which is:
  \begin{itemize}
    \item Strongly convex with parameter $c$.
    \item $\nabla f_k$ Continuously differentiable in $||\cdot||_1$ with
      Lipschitz constant $L$.
    \item Upper bounded second moment of the gradient by $M^2$
    \item Success criteria $\norm{x-x^*}^2 \leq \e$, for some $\e > 0$.
  \end{itemize}
  Then we can construct rate supermartingale $W_t$ such that it's $(H,R,\xi)$
  bounded with $H = 2\sqrt{\e}(2\eta c\e - \eta^2 M^2)^{-1}, R = \eta L,
  \xi = \eta M$. Then choosing step size $\eta$ (for some $\nu \in (0,1)$):
  \[
    \eta = \frac{c\e \nu}{M^2 + 2LM\tau\sqrt{\e}}
  \]
  then we recieve:
  \[
    \Prob{F_T} \leq \frac{M^2 + 2LM\tau\sqrt{\e}}{c^2\e\nu T} \log
    \left(
      e \norm{x_0 -x^*}^2 \e^{-1}
    \right)
  \]
\end{theorem}