% -----------------------------*- LaTeX -*------------------------------
\documentclass[12pt]{report}
\usepackage{scribe_hgen486}
\usepackage{amsmath}
\begin{document}

\scribe{Frank Wen}		% required
\lecturenumber{9}			% required, must be a number
\lecturedate{February 2}		% required, omit year
\lecturer{John Novembre}

\maketitle

% please leave this comment
\framebox[.95\textwidth]{\parbox{.93\textwidth}{ {{\bf Note:}} These
lecture notes are still rough, and have only have been mildly
proofread.  }}
\vspace*{.1in}

% feel free to delete content below this line
% ----------------------------------------------------------------------

\section{Continuous time processes (the exponential distribution)}
The exponential distribution often appears as the distribution of waiting times until an event (i.e. arrival times).

\begin{align*}
f(x) = \lambda e^{-\lambda x}
\end{align*}

Let $T$ be a random variable representing the waiting time until an event happens. Then for $T\sim exp(\lambda)$ with expected value $E(T) = \frac{1}{\lambda}$. The cumulative distribution function is given by

\begin{align*}
F(X) = P(T\le X) &= 1-e^{-\lambda x}\\
P(T > X) &= e^{-\lambda x}
\end{align*}

An important property of the exponential distribution is that it is \textit{memoryless}. Suppose that $T$ is the waiting time until an event occurs. Then, for any given waiting times $t$ and $s$,

\begin{align*}
P(T > t+s | T>t ) &= P(T>s)
\end{align*}

This is to say that if we have already waited $t$ minutes for an event to occur, then the remaining time $s$ for the event to occur is the same as if we hadn't waited the first $t$ minutes to begin with. To show this, we use our definition of conditional probability:
\begin{align*}
P(T > t+s | T>t ) &= \frac{P(T > t+s , T>t )}{P(T>t)}
\end{align*}
Since we have already waited $t$ minutes, $P(T > t+s , T>t ) = P(T > t+s)$. So,
\begin{align*}
P(T > t+s | T>t ) &= \frac{P(T > t+s )}{P(T>t)}\\
&= \frac{e^{-\lambda(t+s)}}{ e^{-\lambda t} }\\
&= e^{-\lambda s} = P(T>s)
\end{align*}
\section{Discrete time processes (the geometric distribution)}

The geometric distribution can be thought of as the discrete analog of the exponential distribution. It is the the probability distribution of $X$ number of Bernoulli trials with success probability $p$ before one success is obtained.

\begin{equation*}
Geom(p) = P(X= k) = (1-p)^{k-1}p
\end{equation*}

Because the trials are independent, the geometric distribution is also memoryless.

\section{Poisson processes}
\subsection{Counting process and the poisson distribution}
A poisson process can be defined as a counting process, where we are interested in the number of events (arrivals) that have occurred up until some time $N(t)$. Four properties of this counting process are the following\\
1) $N(0) = 0$\\
2) $N(t), t\ge0$ has independent increments, or what happens in one time interval is independent of what happens in any other interval\\
3) $P(N(t_0+t) - N(t_0) \ge2) = o(t) $ as $t\rightarrow0$\\
As the time between events gets smaller, the probability of observing two or more events in that time step goes to zero. In other words, events do not happen simultaneously.\\
4) $P(N(t_0+t) - N(t_0) =1 ) = \lambda t + o(t) $ as $t\rightarrow0$ \\
i.e. the number of events in an interval of length $t$ is Poisson distributed with rate $\lambda t$. We write this as
\begin{equation*}
P(N(t) = k) = \frac{(\lambda t)^k e^{-\lambda t} }{k!}
\end{equation*}

Here, $f(x) = o((g(x))$ means that $|f(x)| \le k|g(x)| $ for all $k$. Intuitively this means that $g(x)$ grows faster than $f(x)$

\subsection{Relationship to the binomial distribution}
The poisson distribution can be derived as the limit of a binomial distribution as the number of trials $n$ goes ti infinity, and the probability of success $p$ goes to zero, such that $np = \lambda$. To show this, we take an interval $(s, s+t]$ and divide it into $n$ intervals of size $t/n$. The number of events in the $i$th interval is given by $N_i$. Since events do not happen simultaneously,
\begin{align*}
P(N_i\ge2) = o(t/n),  t\rightarrow0
\end{align*}
This is the equivalent of saying that $N_i \sim Bernoulli(p)$, where $p = \lambda(t/n) + o(t/n)$.\\\\
The total number of events in the interval is then Binomially distributed
\begin{align*}
 N(t+s) - N(s) \sim Binom(n,p) = Binom(n, \lambda t/n)
\end{align*}
 So, as $n$ approaches infinity, $np$ approaches $\lambda t$, and $N(t+s) - N(s) ~ Pois(\lambda t)$.

\subsection{Inter-arrival times}
Waiting times between events (inter-arrival times) in a poisson process are exponentially distributed. To show this, we consider the waiting times between the first and second arrival $T_1$ and $T_2$ respectively.
\begin{align*}
P(T_1 > t) &= P(N(t) = 0)\\
&= \frac{(\lambda t)^0 e^{-\lambda t}}{0!} = e^{-\lambda t}
\end{align*}
So the waiting time until the first arrival is exponentially distributed. For the second arrival event, given the first arrival occurred at time $s$, the waiting time is
\begin{align*}
P(T_2 > t) &= \int_s P(T_2 > t | T_1 = s) P(T_1 = s)\\
&= \int_s P(0 \text{ events in }(s, s+t] | T_1 = s) P(T_1 = s)
\end{align*}
By independence,
\begin{align*}
&=\int_s  P(0 \text{ events in } (s, s+t] ) P(T_1 = s) \\
&= e^{-\lambda t}\int_s P(T_1 = s) \\
&= e^{-\lambda t}
\end{align*}
By the same logic, the inter-arrival time (waiting time in between events) for any $i$th interval is also exponentially distributed $T_i \sim exp(\lambda)$. Then, the waiting time until the $n$th arrival is the sum of all $i$ events $S_n = \sum_{i=1}^n T_i$. Since the inter-arrival times are exponentially distributed, the $n$th arrival time is gamma distributed $S_n \sim Gamma(\lambda, n)$

If we know the number of events in some given interval $(0,t]$, then the distribution of inter-arrival times conditioned on the number of events is uniformly distributed on $(0,t]$. We show this for the simple case with one event.
\begin{align*}
P(T_1 > s | N(t) = 1) &= \frac{P(T_1 > s , N(t) = 1)}{P(N(t) = 1)}\\
&=P(0 \text{ events in } (0,s], 1 \text{ event in } (s, t] )\\
&= \frac{e^{-\lambda s} \lambda (t-s) e^{-\lambda(t-s)} }{\lambda t e^{-t}}\\
&= \frac{t-s}{t}
\end{align*}
To get to the uniform distribution,
\begin{align*}
P(T_1 \le s | N(t) = 1) &= 1- P(T_1 > s |N(t) =1)\\
&=\frac{s}{t}
\end{align*}

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

\subsection{Splitting and superposition}
In order to develop point processes suitable for certain models, one can employ mathematical operations that remove points from Poisson process (splitting i.e. thinning), or combining points from multiple Poisson processes (superposition).

\subsubsection{Superposition}
If we combine the points from two Poisson processes with rates $r_1$ and $r_2$, the result is a Poisson process with rate $r_1 + r_2$. More formally, suppose we have two Poisson processes of rate $\lambda_1$ and $\lambda_2)$, given by $\{N_1(t) ; t>0\}$ and $\{N_2(t) ; t>0\}$. The two are independent if for all $t_1, ..., t_n$, the random variables $N_1(t_1),...,N_1(t_n)$ are independent of $N_2(t_1),...,N_1(t_n)$. Suppose $N(t) = N_1(t) + N_2(t)$ for all $t>0$. Then $\{N_t; t>0\} $then a Poisson process with rate $\lambda_1+\lambda_2$ .\

\subsubsection{Splitting}
Now suppose we have a Poisson process $\{N_t; t>0\}$ with rate $\lambda$. Suppose each arrival is switched to $\{N_1(t) ; t>0\}$ with probability $p$ and switched to $\{N_2(t) ; t>0\}$ with probability $(1-p)$. Then $\{N_1(t) ; t>0\}$ is a Poisson process with rate $\lambda p$ and $\{N_2(t) ; t>0\}$ is a Poisson process with rate $\lambda (1-p)$

\subsection{Compound Poisson processes}
Compound Poisson processes assign a random value or weight to each point in a Poisson process.

\subsection{Non-homogenous Poisson processes}
So far, we have considered Poisson processes where the rate parameter $\lambda$ is constant for all time $t > 0$. A nonhomogenous Poisson process is one where the `rate,' referred to as an intensity function $\lambda(t)$ can vary over time. $\{N_t; t>0\}$ is a nonhomogenous or inhomogenous Poisson process if\\
1. $N(0) = 0$\\
2. $\{N(t), t\ge 0 \}$ has independent increments\\
3. $P(N(t+h) - N(t) \ge 2) = o(h)$\\
4.$ P(N(t+h) - n(t) = 1) = \lambda(t)h + o(h)$\\
Note that a nonhomogenous Poisson process with $\lambda(t) = \lambda$ for all $t>0$ is a homogenous Poisson process.\\
Also note that for the nonhomogenous Poisson process, the interarrival times are no longer exponentially distributed, nor are they independent.
\subsection{Compound or mixed `Poisson' processes}

\end{document}


\documentclass[12pt]{scrartcl}

\input{preamble}

\makeatletter
\title{Hack 11.0}\let\Title\@title
\subtitle{Computer Science I -- Java\\
Encapsulation\\
{\small
\vskip1cm
Department of Computer Science \& Engineering \\
University of Nebraska--Lincoln}
\vskip-3cm}
%\author{Dr.\ Chris Bourke}
\date{~}
\makeatother

\begin{document}

\maketitle

\hrule

\input{instructions.tex}

\section*{Problem Statement}

There are thousands of commercial, military, and local airports in the US and
around the world.  The International Civil Aviation Organization maintains a
database of current and inactive airports around the world.  The database
uniquely identifies each airport by an alphanumeric GPS code.  Further, each
record contains the following pieces of data on each airport:
\begin{itemize}
  \item The name of the airport
  \item Its latitude in degrees in the range $[-90, 90]$ with negative values corresponding to the southern hemisphere
  \item Its longitude in degrees in the range $[-180, 180]$ with negative values corresponding to the western hemisphere
  \item The type of airport
  \item Its elevation in (whole) feet above sea level
  \item Its municipality and its country
\end{itemize}

Design a Java class to encapsulate these attributes to model an
airport record from the ICAO database.  Also design several methods
to support your class including a constructor, getters, a \mintinline{java}{toString()}
method, etc.  You will also implement several utility methods that
use your class to compute the air
distance(s) between airport locations using their latitude and longitude.
Recall that the air distance $d$ between two latitude/longitude points can be
estimated using the Spherical Law of Cosines.

 $$d = \arccos{(\sin(\varphi_1) \cdot \sin(\varphi_2) + \cos(\varphi_1) \cos(\varphi_2) \cos(\Delta) )} \cdot R$$
where
\begin{itemize}
  \item $\varphi_1$ is the latitude of location $A$, $\varphi_2$ is the latitude of location $B$
  \item $\Delta$ is the difference between location $B$'s longitude and location $A$'s longitude
  \item $R$ is the (average) radius of the earth, 6,371 kilometers
\end{itemize}
This formula assumes that latitude and longitude are in radians
$r$, $-\pi \leq r \leq \pi$.  To convert from degrees $d$ ($-180 \leq d \leq 180$)
to radians $r$, you can use the simple formula:
  $$r = \frac{d}{180} \pi$$

More details have been provided in a starter file, \mintinline{text}{Airport.java}.
You will need to design your class and implement all of the specified
methods.

\section*{Instructions}

\begin{itemize}

  \item In addition, you must create a main test driver program that
  demonstrates at least 3 cases per non-trivial function.  Name this file
  \mintinline{text}{AirportTester.java} and hand it in.

  \item You are encouraged to collaborate any number of students
  before, during, and after your scheduled hack session.

  \item You may (in fact are encouraged) to define any additional
  ``helper'' methods that may help you.

  \item Include the name(s) of everyone who worked together on
  this activity in your source file's header.

  \item Turn in all of your files via webhandin, making sure that
  it runs and executes correctly in the webgrader.  Each individual
  student will need to hand in their own copy and will receive
  their own individual grade.
\end{itemize}

\end{document}


%!TEX root = maths.tex
\usetikzlibrary{patterns,intersections,arrows,backgrounds}

\newcommand{\degre}{\ensuremath{^\circ}}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows}

\newcommand{\realPlot}[2]{
	\draw[domain=#1,scale=1,samples=500 ] plot (\x:{#2}); %Curve with parameter
}

\newenvironment{fullPlot}[4]
{\begin{center}
		\resizebox{0.5\textwidth}{!}{%
			\begin{tikzpicture}
			\begin{axis}[
			x=1cm,y=1cm,
			axis lines=middle,
			ymajorgrids=true,
			xmajorgrids=true,
			xmin=#1,
			xmax=#2,
			ymin=#3,
			ymax=#4,
			xtick={-20,-19,...,20},
			ytick={-20,-19,...,20},]
			\coordinate (origin) at (0,0);
			\end{axis}
			\begin{scope}[shift={(origin)}]
			\clip (#1,#3) rectangle (#2,#4);
				%Dashed lines loop (increments of 15 degrees)
			\foreach \i in {0,15,...,75,105,120,...,180}{
				\draw[red,dashed, thick, samples=500] plot(\x, {tan(\i) * \x});}
				\draw[red, dashed, thick, samples=500] plot(0,\x);		 %Line x=0 due to tan() math err
		}

		{
			%Green crosses loop (incremenets of 15 degress with upper bound parameter)
%			\foreach \x in {0,15,...,75,105,120,...,{#6}}{
%				\pic[line width=1pt,green] at ({\x}:{#5}) {mycross};}

			%	\pic[line width=1pt,green] at (0,5) {mycross};
			%	\pic[line width=1pt,green] at (0,-5) {mycross};
			\end{scope}
			\end{tikzpicture}
		}
	\end{center}

}

\graphicspath{pictures/Polar_Curves}
\begin{document}
	\chapter{Polar Curves}
	\section{Introduction}
	The position of a point on a plane can be described in sever ways. With respect to some origin $O$
	we can locate a point $P$ on a plane by noting a horizontal distance followed by a vertical distance.\\

	\definecolor{uququq}{rgb}{0.25,0.25,0.25}
	\definecolor{xdxdff}{rgb}{0.49,0.49,1}
	\definecolor{qqqqff}{rgb}{0,0,1}
	\definecolor{xdxdff}{rgb}{0.49,0.49,1}
	\definecolor{qqqqff}{rgb}{0,0,1}
	\begin{center}
		\definecolor{xdxdff}{rgb}{0.49,0.49,1}
		\definecolor{qqqqff}{rgb}{0,0,1}
		\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
		\draw[->,color=black] (-1,0) -- (5,0);
		\foreach \x in {-1,1,2,3,4}
		\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
		\draw[->,color=black] (0,-1) -- (0,4);
		\foreach \y in {-1,1,2,3}
		\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
		\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
		\clip(-1,-1) rectangle (5,4);
		\draw [dash pattern=on 1pt off 1pt] (0,3)-- (4,3);
		\draw [dash pattern=on 1pt off 1pt] (2.08,3) -- (2,2.9);
		\draw [dash pattern=on 1pt off 1pt] (2.08,3) -- (2,3.1);
		\draw [dash pattern=on 1pt off 1pt] (4,0)-- (4,3);
		\draw [dash pattern=on 1pt off 1pt] (4,1.58) -- (4.1,1.5);
		\draw [dash pattern=on 1pt off 1pt] (4,1.58) -- (3.9,1.5);
		\begin{scriptsize}
		\fill [color=red] (4,3) circle (1.5pt);
		\draw[color=black] (4.31,3.19) node {$P$ ($x$, $y$)};
		\fill [color=qqqqff] (4,0) circle (1.5pt);
		\draw[color=black] (4.2,0.2) node {$X$};
		\fill [color=qqqqff] (0,3) circle (1.5pt);
		\draw[color=black] (0.2,3.19) node {$Y$};
		\end{scriptsize}
		\end{tikzpicture}
	\end{center}

	However the point $P$ can be located on a plane with respect to the origin $O$, a horizontal line and the distance of $P$ from $O$.\\

	\definecolor{ttttff}{rgb}{0.2,0.2,1}
	\definecolor{qqqqff}{rgb}{0,0,1}
	\definecolor{cqcqcq}{rgb}{0.75,0.75,0.75}
	\definecolor{ttttff}{rgb}{0.2,0.2,1}
	\definecolor{qqqqff}{rgb}{0,0,1}
	\begin{center}

		\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
		\draw[->,color=black] (-1,0) -- (6,0);
		\foreach \x in {-1,1,2,3,4,5}
		\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
		\draw[->,color=black] (0,-1) -- (0,6);
		\foreach \y in {-1,1,2,3,4,5}
		\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
		\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
		\clip(-1,-1) rectangle (6,6);
		\draw [shift={(0,0)},color=ttttff,fill=ttttff,fill opacity=0.1] (0,0) -- (0:0.71) arc (0:45:0.71) -- cycle;
		\draw (0,0)-- (3,3);
		\begin{scriptsize}
		\fill [color=qqqqff] (0,0) circle (1.5pt);
		\draw[color=black] (-0.4,-0.3) node {Pole};
		\fill [color=red] (3,3) circle (1.5pt);
		\draw[color=black] (3.52,3.21) node {$P$ ($r$, $\theta$)};
		\draw[color=black] (1.71,1.44) node {$r$};
		\draw[color=black] (0.46,0.2) node {$\theta$};
		\end{scriptsize}
		\end{tikzpicture}

	\end{center}

	This is the polar coordinate system where we refer to the origin as the pole and the horizontal line as the initial line. The anti clockwise angle is usually measured in the principal range $-\pi < \theta \leq \pi$.
	\newpage
	\section{Relationship between Polar and Cartesian Coordinates}

	Consider the following diagram showing the point P on the plane, both in Cartesian and Polar coordinates

	The above relationship can be used to convert from one form to another.
	\begin{example}
		Find the polar coordinates of the curve given by $y=x^2+y^2=2x$
	\end{example}

	\begin{alignat*}{2}
	& \qquad \quad x^2+y^2  &   & = 2x  \\
	& \implies 2r\cos\theta &   & = r^2 \\
	& \implies 2\cos\theta  &   & = r
	\end{alignat*}

	\hrulefill
	\begin{example}
		Find the Cartesian equation corresponding to the curves \textbf{a)} $r=4(1+\cos\theta)$ and \textbf{b)} $3 = r\sin 2\theta$.
	\end{example}
	\begin{equation*}
	\begin{split}
	r &= 4(1+\cos\theta)
	\end{split}
	\qquad \qquad \qquad
	\begin{split}
	3 &= r\sin2\theta\\
	3 &= 2r\sin\theta\cos\theta\\
	3  &= 2x\sin\frac yr
	\end{split}
	\end{equation*}
	$$i^2 + 1^2 = 0$$

	\newpage
	\section{Sketching Polar Curves}
	\begin{example}
		Sketch the polar curve of $2+2\cos\theta$.
	\end{example}
	Observing the following sketch, it is shown that a line of symmetry is present in the $x$-axis for the \emph{cosine} function family.
	\begin{center}
		\resizebox{300pt}{!}{%
			\begin{tabular}{c|c|c|c|c|c|c|c|c|c}

				$\displaystyle\theta$ & $0$ & $\frac\pi6$ & $\frac\pi4$ & $\frac\pi3$ & $\frac\pi2$ & $\frac{2\pi}3$ & $\frac{3\pi}4$ & $\frac{5\pi}6$ & $\pi$ \\ \hline
				$r$                   & 4   & 3.7         & 3.4         & 3           & 2           & 1              & 0.6            & 0.3            & 0
			\end{tabular}
		}
	\end{center}
	\begin{center}
		\begin{tikzpicture}[scale=1.7]
		\draw[thick,->,>=latex] (-3,0)--(5,0) node[above] {$x$};
		\draw[thick,->,>=latex] (0,-3)--(0,4) node[left] {$y$};
		\draw[domain=0:540,scale=1,samples=1000] plot (\x:{2+(2*cos(\x))});
		\clip (-3,-3) rectangle (6,4);

		% Draw dotted lines and crosses
		\foreach \i in {0, {pi/6},{pi/4}, {pi/3}, {2* pi / 3}, {3 * pi / 4}, {5 *pi / 6}, {pi}}{
			\draw[red, dashed, samples=500] plot(\x, {tan( deg(\i)) * \x});
			\pic[line width=1pt,green] at ({deg(\i)}:{2+(2*cos(deg(\i)))}) {mycross};}
		\end{tikzpicture}
	\end{center}
	\newpage
	\begin{example}
		Sketch the graph with polar equation $r=3-2\cos\theta$.
	\end{example}
	Similarly to the above example, a line of symmetry is present in the $x$-axis.
	\begin{center}
		\resizebox{300pt}{!}{%
			\begin{tabular}{c|c|c|c|c|c|c|c|c|c}
				$\displaystyle\theta$ & $0$ & $\frac\pi6$ & $\frac\pi4$ & $\frac\pi3$ & $\frac\pi2$ & $\frac{2\pi}3$ & $\frac{3\pi}4$ & $\frac{5\pi}6$ & $\pi$ \\ \hline
				$r$                   & 1   & 1.3         & 1.6         & 2           & 3           & 4              & 4.4            & 4.7            & 5
			\end{tabular}
		}
	\end{center}

	\begin{center}
		\begin{tikzpicture}
		\draw[thick,->,>=latex] (-6,0)--(4,0) node[above] {$x$};
		\draw[thick,->,>=latex] (0,-4)--(0,4) node[left] {$y$};
		\draw[domain=0:540,scale=1,samples=500] plot (\x:{3-(2*cos(\x))});
		\clip (-5,-5) rectangle (6,4);

		%	Draw dotted lines and crosses
		\foreach \i in {0, {pi/6},{pi/4}, {pi/3}, {2* pi / 3}, {3 * pi / 4}, {5 *pi / 6}, {pi}}{
			\draw[red, dashed, thick, samples=500] plot(\x, {tan( deg(\i)) * \x});
			\pic[line width=1pt,green] at ({deg(\i)}:{3-(2*cos(deg(\i)))}) {mycross};}
		\end{tikzpicture}
	\end{center}
	\newpage
	\begin{example}
		Sketch the graph with polar equation $r=5+2\sin\theta$.
	\end{example}

	It is noted that since the graph is part of the \emph{sine} function family,the line of symmetry is now present in the $y$-axis.

	\begin{center}
		\resizebox{300pt}{!}{%
			\begin{tabular}{c|c|c|c|c|c|c|c|c|c}
				$\theta$ & $\frac{-\pi}2$ & $\frac{-\pi}3$ & $\frac{-\pi}4$ & $\frac{-\pi}6$ & 0   & $\frac\pi6$ & $\frac\pi4$ & $\frac\pi3$ & $\frac\pi2$ \\ \hline
				$r$      & 3              & $3.3$          & $3.6$          & $4$            & $5$ & $6$         & $6.4$       & $6.7$       & $7$
			\end{tabular}
		}
	\end{center}

	\begin{center}
		\begin{tikzpicture}
		\draw[thick,->,>=latex] (-8,0)--(6,0) node[above] {$x$};
		\draw[thick,->,>=latex] (0,-4)--(0,9) node[left] {$y$};
		\draw[domain=0:540,scale=1,samples=500] plot (\x:{5+(2*(sin(\x)))});

		\clip (-9,-4) rectangle (8,8);

		%	Draw dotted lines and crosses
		\foreach \i in {{-pi/6},{-pi/4}, {-pi/3}, 0, {pi/6},{pi/4}, {pi/3}}{
			\draw[red, dashed, thick, samples=500] plot(\x, {tan( deg(\i)) * \x});
			\pic[line width=1pt,green] at ({deg(\i)}:{5+(2*(sin(deg(\i))))}) {mycross};}
		\end{tikzpicture}
	\end{center}

	\newpage
	\begin{example}
		Sketch the polar curve $r=3+7\sin\theta$ and the circle $r=5$. Find the polar coordinates of their points of intersection.
	\end{example}

	\begin{center}
		\begin{tikzpicture}
		\draw[thick,->,>=latex] (-7,0)--(7,0) node[above] {$x$};
		\draw[thick,->,>=latex] (0,-6)--(0,11) node[left] {$y$};
		\draw[domain=0:540,scale=1,samples=1000] plot (\x:{3+(7*sin(\x))}); %Curve
		\draw[domain=0:540,scale=1,samples=500] plot (\x:5);				%Circle
		\clip (-7,-2) rectangle (6,10);

		%Draw dotted lines and crosses
		\foreach \i in {{-pi/6},{-pi/4}, {-pi/3}, 0, {pi/6},{pi/4}, {pi/3}}{
			\draw[red, dashed, thick, domain=-7:7, samples=500] plot(\x, {tan( deg(\i)) * \x});
			\pic[line width=1pt,green] at ({deg(\i)}:{3+(7*sin(deg(\i)))}) {mycross};}

		\draw[red, dashed, thick, domain=-7:12, samples=500] plot(0,\x);
		%Tangential Asymptotes
		\pic[line width=1pt,green] at ({deg(pi/2)}:10) {mycross};
		\pic[line width=1pt,green] at ({deg(-pi/2)}:-4) {mycross};

		\end{tikzpicture}
	\end{center}

	\newpage
	\begin{example}
		Sketch the polar curve $r=8\sin^2\theta$ and the line $r=\csc\theta$. Find the polar coordinates of their points of intersection.
	\end{example}
	\begin{center}
		\begin{tikzpicture}
		\begin{axis}[
		x=1cm,y=1cm,
		axis lines=middle,
		ymajorgrids=true,
		xmajorgrids=true,
		xmin=-4,
		xmax=4,
		ymin=-9,
		ymax=9,
		xtick={-4,-3,...,4},
		ytick={-9,-8,...,9},]
		\draw[domain=0:540,scale=1,samples=1000] plot (\x:{8*(sin(\x)^2)}) node[above] {$r=8\sin^2\theta$}; %Curve
		\draw[domain=-5:5,scale=1,samples=1000] plot (\x, 1) node[above] {$r=\csc\theta$}; %Curve
		%	\clip (-7,-2) rectangle (6,10);
		\end{axis}
		\end{tikzpicture}
	\end{center}

	\section{Area partly bounded by a polar curve}
	Consider the following diagram showing the graph of $r=f(\theta)$.

	\begin{center}
		\resizebox{300pt}{!}{%
			\definecolor{ccffww}{rgb}{0.8,1,0.4}
			\definecolor{qqttcc}{rgb}{0,0.2,0.8}
			\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
			\definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1}
			\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
			\begin{axis}[
			x=1cm,y=1cm,
			axis lines=middle,
			ymajorgrids=true,
			xmajorgrids=true,
			xmin=-4.087350135407929,
			xmax=12.075704876608706,
			ymin=-1.9400069331551724,
			ymax=8.089791136292845,
			xtick={-4,-3,...,12},
			ytick={-1,0,...,8},]
			\clip(-4.087350135407929,-1.9400069331551724) rectangle (12.075704876608706,8.089791136292845);

			\fill[line width=0.8pt,color=ccffww,fill=ccffww,fill opacity=0.55] (1.6469997622170334,5.285200045490499) -- (1.8018963690587861,5.303857839349265) -- (2.057802642713001,5.344452622890168) -- (2.2425420008780867,5.375610046949744) -- (2.4085986469696503,5.401170598203379) -- (2.6317350137162325,5.427157717856224) -- (2.826543364850297,5.438046959825773) -- (2.9930508460166525,5.436092904437624) -- (3.1583701235903847,5.422111858769122) -- (3.394065928081652,5.378740328890088) -- (3.5780745473050493,5.323957494370168) -- (3.7684491850962933,5.246759511526517) -- (3.909043353636018,5.175946821869229) -- (4.096867913840399,5.062840104074621) -- (4.339673854011711,4.885528774754539) -- (4.70860996427174,4.552297629385634) -- (5.130951567039364,4.088855310480258) -- (5.420878217861827,3.7324711921147538) -- (5.752127039672099,3.3035617372125) -- (5.8996282307282275,3.1102010591021587) -- (0,0) -- cycle;
			\draw [line width=2pt,dash pattern=on 1pt off 1pt,domain=-4.087350135407929:12.075704876608706] plot(\x,{(-0--4.099788120747726*\x)/1.2775959286106953});
			\draw [line width=2pt,dash pattern=on 1pt off 1pt,domain=-4.087350135407929:12.075704876608706] plot(\x,{(-0--4.87618*\x)/9.24945});
			\draw[line width=2pt,color=xdxdff,smooth,samples=100,domain=-4.087350135407929:12.075704876608706] plot(\x,{0.014635180803888441*(\x)^(4)-0.23126329831793696*(\x)^(3)+1.0699408938350827*(\x)^(2)-1.8059409257011467*(\x)+6.282771603030379});
			\draw (2.6126764256158723,7.846889871240623) node[anchor=north west] {$\theta = \alpha$};
			\draw (7.440339068528793,5.195217727753861) node[anchor=north west] {$\theta = \beta$};
			\draw [line width=2.4pt,color=qqttcc,fill=qqttcc,fill opacity=0.1] (0,0) -- (27.797567846322046:0.9614841741650471) arc (27.797567846322046:72.69166717480417:0.9614841741650471) -- cycle;
			\draw [color=xdxdff](-2.5287336846561685,8.960187336063308) node[anchor=north west] {$ r=f({\theta})$};
			\begin{scriptsize}
			\draw [fill=uuuuuu] (1.6469997622170334,5.285200045490499) circle (2pt);
			%				\draw[color=uuuuuu] (1.74734066886733,5.524146524178746) node {$G$};
			\draw [fill=uuuuuu] (0,0) circle (2pt);
			\draw [fill=uuuuuu] (5.8996282307282275,3.1102010591021587) circle (2pt);
			\draw[color=uuuuuu] (6.038596351456593,3.3937000119498784) node {$D_1$};
			\draw[color=qqttcc] (1.0743017469517973,0.5143079324766583) node {$\omega$};
			\end{scriptsize}
			\end{axis}
			\end{tikzpicture}
		}
	\end{center}
	It can be shown that the area bounded by the curve $r=f(\theta)$, from $\theta = \alpha$ to $\theta = \beta$ is given by \[A = \frac12\int_\alpha^\beta r^2\,d\theta\]
	\hrulefill
	\newpage
	\begin{example}
		Sketch the curve with polar equation $r=2(1-\cos\theta)\sqrt{\sin\theta}$ for $0 \leq \theta\leq \pi$ and find the area it encloses.
	\end{example}
	\begin{center}
		\begin{tabular}{c|c|c|c|c|c|c|c|c|c|c|c|c|c}
			$\theta$ & 0   & $\frac{\pi}{12}$ & $\frac{\pi}6$ & $\frac{\pi}4$ & $\frac{\pi}3$ & $\frac{5\pi}{12}$ & $\frac\pi2$ & $\frac{7\pi}{12}$ & $\frac{2\pi}3$ & $\frac{3\pi}4$ & $\frac{5\pi}6$ & $\frac{11\pi}{12}$ & $\pi$ \\ \hline
			$r$      & $0$ & $0.03$           & $0.2$         & $0.5$         & $0.9$         & $1.5$             & $2$         & $2.5$             & $11$           & $2.9$          & $2.6$          & $2$                & $0$
		\end{tabular}
	\end{center}

	\begin{fullPlot}{-3}{2}{-2}{3}
	\realPlot{0:180}{2*(1-cos(\x))*(sqrt(sin(\x)))}
	\end{fullPlot}
%	\fullPlot{-3}{2}{-2}{3}{2*(1-cos(\x))*(sqrt(sin(\x)))}{180}
	\begin{align*}
	A & =\frac12\int_0^\pi \left(2(1-\cos\theta)\sqrt{\sin\theta}\right)^2\,d\theta             \\
	& = \frac12\int_0^\pi 4(1-\cos\theta)^2\sin(\theta)\,d\theta                                \\
	& = 2\int_0^\pi \sin(\theta)(1-2\cos(\theta)+\cos^2\theta)\,d\theta\\
	&= 2\int_0^\pi \sin\theta - 2\sin\theta\cos\theta+\sin\theta\cos^2\theta\,d\theta\\
	&= 2\left(\left.-\cos\theta + \cos^2\theta - \frac{\cos^3\theta}{3}\right|_0^\pi\right)
	\end{align*}
	\newpage
	\begin{example}
		Sketch the curve with polar equation $r=3-4\cos\theta$ and find the area enclosed by the inner loop.
	\end{example}

	\fullPlot{-5}{5}{-5}{5}{2+2*(cos(\x))}{180}
	\newpage
	\begin{example}
		Sketch the curve  $r=5\sin3\theta$ and the circle $r=5$. Find the area of the region which lies inside the circle but outside the curve.
	\end{example}
	\begin{center}
		\begin{tikzpicture}
		\begin{axis}[
		x=1cm,y=1cm,
		axis lines=middle,
		ymajorgrids=true,
		xmajorgrids=true,
		xmin=-6,
		xmax=6,
		ymin=-6,
		scale=1,
		ymax=6,
		xtick={-6,-5,...,6},
		ytick={-6,-5,...,6},]
		\coordinate (origin) at (0,0);
		\end{axis}
		\begin{scope}[shift={(origin)}]
		\clip (-6,-6) rectangle (6,6);
		\draw[domain=0:360,scale=1,samples=500 ] plot (\x:{5*sin(3*\x)}); %Curve
		\draw[domain=0:360,scale=1,samples=500 ] plot (\x:5); %Curve
		\foreach \i in {0,15,...,75,105,120,...,180}{
			\draw[red, dashed, thick, domain=-5:5, samples=500] plot(\x, {tan(\i) * \x});
			\pic[line width=1pt,green] at ({\i}:{5*sin(3*\i)}) {mycross};
		}
		\draw[red, dashed, thick, domain=-5:5, samples=500] plot(0, \x);
		\pic[line width=1pt,green] at (0,5) {mycross};
		\pic[line width=1pt,green] at (0,-5) {mycross};
		\end{scope}
		\end{tikzpicture}
	\end{center}

	\begin{multicols}{2}
		\noindent
		\begin{align*}
		A & = \frac12 \int_0^\frac\pi3 (5\sin(3\theta))^2\,d\theta                        \\
		& = \frac{25}{2} \int_0^\frac\pi3 \sin^2(3\theta)\,d\theta                      \\
		& = \frac{25}{2} \int_0^\frac\pi3 \frac{1-\cos(6\theta)}{2}                     \\
		& = \frac{25}{4} \left.\quad\theta - \frac{\cos(6\theta)}{6}\right|_0^\frac\pi3 \\
		& = \frac{25}{24} \left.\quad 6\theta - \cos6\theta\right|_\alpha^\beta
		\end{align*}

		\begin{align*}
		A & = \pi r^2 \\
		& = 25\pi   \\~\\~\\~\\~\\
		\end{align*}
	\end{multicols}

	\newpage
	\begin{example}
		Sketch the curve $r=3(1+\sqrt{2}\cos\theta)$ and the line $r=3\sqrt{2}\sec\theta$. Find the polar coordinates of their points of intersection. Find the area of the region which lies inside the circle but outside of the cardioid.
	\end{example}

	\begin{center}
		\begin{tikzpicture}
		\begin{axis}[
		x=1cm,y=1cm,
		axis lines=middle,
		ymajorgrids=true,
		xmajorgrids=true,
		xmin=-2,
		xmax=8,
		ymin=-6,
		scale=1,
		ymax=6,
		xtick={-2,-1,...,8},
		ytick={-6,-5,...,6},]
		\coordinate (origin) at (0,0);
		\end{axis}
		\begin{scope}[shift={(origin)}]
		\clip (-2,-6) rectangle (8,6);
		\draw[domain=0:360,scale=1,samples=500 ] plot (\x:{3*(1+(sqrt(2)*cos(\x))}); %Curve
		\draw[range=0:180,scale=1,samples=500 ] plot (\x:{3*sqrt(2)*sec(\x)}); %Curve
		\foreach \i in {0,15,...,75,105,120,...,180}{
			\draw[red, dashed, thick, domain=-5:8, samples=500] plot(\x, {tan(\i) * \x});
			\pic[line width=1pt,green] at ({\i}:{3*(1+(sqrt(2)*cos(\i))}) {mycross};
		}
		%	\draw[red, dashed, thick, domain=-5:5, samples=500] plot(0, \x);
		%	\pic[line width=1pt,green] at (0,5) {mycross};
		%	\pic[line width=1pt,green] at (0,-5) {mycross};
		\end{scope}
		\end{tikzpicture}
	\end{center}
	\newpage

	\begin{example}
		Sketch the curve $r=5+\sin\theta$ and the line $r\sin\theta = 8$.
	\end{example}

	\begin{center}
		\begin{tikzpicture}
		\begin{axis}[
		x=1cm,y=1cm,
		axis lines=middle,
		ymajorgrids=true,
		xmajorgrids=true,
		xmin=-7,
		xmax=7,
		ymin=-3,
		scale=1,
		ymax=9,
		xtick={-7,-6,...,7},
		ytick={-3,-2,...,9},]
		\coordinate (origin) at (0,0);
		\end{axis}
		\begin{scope}[
		shift={(origin)}]
		\clip (-7,-3) rectangle (7,9);
		\draw[domain=0:360,scale=1,samples=500 ] plot (\x:{5+(3*sin(\x))}); %Curve
		\draw[domain=-7:7,scale=1,samples=500 ] plot (\x,8); %LIne y=8
		\foreach \i in {0,15,...,75,105,120,...,180}{
			\draw[red, domain=-7:7,dashed, thick, samples=500] plot(\x, {tan(\i) * \x});
			\pic[line width=1pt,green] at ({\i}:{5+(3*sin(\i))}) {mycross};
		}
		%	\draw[red, dashed, thick, domain=-5:5, samples=500] plot(0, \x);
		%	\pic[line width=1pt,green] at (0,5) {mycross};
		%	\pic[line width=1pt,green] at (0,-5) {mycross};
		\end{scope}
		\end{tikzpicture}
	\end{center}

\end{document}


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

\begin{document}

% ============================================================================================
\section*{Checking the 2nd and 3rd order terms of Calzetta etal.}

The following calculations show that my results for the RNC connection agree with those of Calzetta etal. to third order terms.

Note that I take $\nabla_{ab}$ to be $\nabla_a\left(\nabla_b\right)$.

Note also that $(LCB)\>R_{abcd} = - (Calzetta)\> R_{abcd}$. Consequently, I replace $R_{abcd}$ with
$-R_{abcd}$ in the Calzetta expressions (done as a Cadabra substitution rule).

This is relatively straightforward. We just apply a few carefully chosen applications of the first and second Bianchi identities.

Note that in this example, 2nd and 3rd order refer to the powers of $x$ in the expression. This differs from
the usage elsewhere in these examples (3rd and 4th order with respect to $R$ and its derivatives).

\clearpage

\begin{cadabra}
   {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,u,v,w#}::Indices("latin",position=independent).
   {\mu,\nu,\rho,\sigma,\tau,\lambda,\xi#}::Indices("greek",position=independent).

   \nabla{#}::Derivative.

   g_{a b}::Metric.
   g^{a b}::InverseMetric.
   g^{a b}::Weight(label=gnum,value=1).

   \delta{#}::KroneckerDelta.

   R_{a b c d}::RiemannTensor.
   R_{a b c d}::Depends(\nabla{#}).

   x^{a}::Weight(label=xnum,value=1).

   def add_tags (obj,tag):

      n = 0
      ans = Ex('0')

      for i in obj.top().terms():
         foo = obj[i]
         bah = Ex(tag+'_{'+str(n)+'}')
         ans := @(ans) + @(bah) @(foo).
         n = n + 1

      return ans

   def clear_tags (obj,tag):

      ans := @(obj).
      foo  = Ex(tag+'_{a?} -> 1')
      substitute (ans,foo)

      return ans

   def get_xterm (obj,n):

       foo := @(obj).
       bah  = Ex("xnum = " + str(n))
       distribute  (foo)
       keep_weight (foo, bah)

       return foo

   def get_gterm (obj,n):

       foo := @(obj).
       bah  = Ex("gnum = " + str(n))
       distribute  (foo)
       keep_weight (foo, bah)

       return foo

   # note: keeping numbering as is (out of order) to ensure R appears before \nabla R etc.
   def product_sort (obj):
       substitute (obj,$ g^{a b}                   -> A001^{a b}                $)
       substitute (obj,$ x^{a}                     -> A002^{a}                  $)
       substitute (obj,$ z^{a}                     -> A003^{a}                  $)
       substitute (obj,$ \nabla_{e f}{R_{a b c d}} -> A006_{a b c d e f}        $)
       substitute (obj,$ \nabla_{e}{R_{a b c d}}   -> A005_{a b c d e}          $)
       substitute (obj,$ R_{a b c d}               -> A004_{a b c d}            $)
       sort_sum       (obj)
       sort_product   (obj)
       rename_dummies (obj)
       substitute (obj,$ A001^{a b}                -> g^{a b}                   $)
       substitute (obj,$ A002^{a}                  -> x^{a}                     $)
       substitute (obj,$ A003^{a}                  -> z^{a}                     $)
       substitute (obj,$ A004_{a b c d}            -> R_{a b c d}               $)
       substitute (obj,$ A005_{a b c d e}          -> \nabla_{e}{R_{a b c d}}   $)
       substitute (obj,$ A006_{a b c d e f}        -> \nabla_{e f}{R_{a b c d}} $)

       return obj

   def reformat (obj,scaleA,scaleB):

      foo  = Ex(str(scaleA))
      moo  = Ex(str(scaleB))
      bah := @(foo) @(obj) / @(moo).

      distribute     (bah)
      bah = product_sort (bah)
      rename_dummies (bah)
      canonicalise   (bah)
      factor_out     (bah,$g^{c? d?}$)
      factor_out     (bah,$x^{a?},z^{b?}$)
      ans := @(moo) @(bah) / @(foo).

      return ans

   # ==========================================================================
   # LCB

   import cdblib
   Gamma  = cdblib.get ('Gamma','../connection.json')             # cdb(ex-12.100,Gamma)

   # note that the next two lines require careful inspection of the free indices on Gamma
   # expecting Gamma = \Gamma^{d}_{ab}
   Gamma := z^{a} z^{b} @(Gamma).

   # lower index ^{d} to _{v}

   Gamma := g_{v d} @(Gamma).

   distribute (Gamma)
   substitute (Gamma, $g_{a d} g^{d b} -> \delta_{a}^{b}$)
   eliminate_kronecker (Gamma)                                    # cdb(ex-12.101,Gamma)

   # change free index _{v} to _{a}

   foo := tmp_{v} -> @(Gamma).                                    # cdb(ex-12.191,foo)
   bah := tmp_{a}.                                                # cdb(ex-12.192,bah)
   substitute (bah, foo)                                          # cdb(ex-12.193,bah)

   Gamma := @(bah).                                               # cdb(ex-12.102,Gamma)

   Gamma = product_sort (Gamma)                                   # cdb(ex-12.103,Gamma)

   gam1  = get_xterm (Gamma,1)                                    # cdb(ex-12.200,gam1)
   gam2  = get_xterm (Gamma,2)                                    # cdb(ex-12.201,gam2)
   gam3  = get_xterm (Gamma,3)                                    # cdb(ex-12.202,gam3)

   gam30 = get_gterm (gam3,0)                                     # cdb(ex-12.203,gam30)
   gam31 = get_gterm (gam3,1)                                     # cdb(ex-12.204,gam31)

   gam1  = reformat (gam1, 3,1)                                   # cdb(ex-12.300,gam1)
   gam2  = reformat (gam2,12,1)                                   # cdb(ex-12.301,gam2)

   gam30 = reformat (gam30,40,1)                                  # cdb(ex-12.302,gam30)
   gam31 = reformat (gam31,45,2)                                  # cdb(ex-12.303,gam31)

   gam3 := @(gam30) + @(gam31).                                   # cdb(ex-12.304,gam3)

   Gamma := @(gam1) + @(gam2) + @(gam3).                          # cdb(ex-12.305,Gamma)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.100}}
   \Dmath*{\cdb*{ex-12.191}}
   \Dmath*{\cdb*{ex-12.192}}
   \Dmath*{\cdb*{ex-12.193}}
   \Dmath*{\cdb*{ex-12.101}}
   \Dmath*{\cdb*{ex-12.102}}
   \Dmath*{\cdb*{ex-12.103}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.200}}
   \Dmath*{\cdb*{ex-12.201}}
   \Dmath*{\cdb*{ex-12.202}}
   \Dmath*{\cdb*{ex-12.203}}
   \Dmath*{\cdb*{ex-12.204}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.300}}
   \Dmath*{\cdb*{ex-12.301}}
   \Dmath*{\cdb*{ex-12.302}}
   \Dmath*{\cdb*{ex-12.303}}
   \Dmath*{\cdb*{ex-12.304}}
   \Dmath*{\cdb*{ex-12.305}}
\end{dgroup*}

\clearpage

\begin{cadabra}
   # ==========================================================================
   # Calzetta
   # note: \nabla_{a b} defined as \nabla_{a}\nabla_{b}

   GammaBar := z^{\nu} z^{\rho} (
                 (2/3) R^{\mu}_{\nu\rho\sigma} x^{\sigma}
               + (1/12) (5 \nabla_{\lambda}{R^{\mu}_{\nu\rho\sigma}}
                         + \nabla_{\rho}{R^{\mu}_{\sigma\nu\lambda}}) x^{\sigma} x^{\lambda}
               + (1/6) (  (9/10) \nabla_{\tau\lambda}{R^{\mu}_{\rho\nu\sigma}}
                        + (3/20) (  \nabla_{\tau\rho}{R^{\mu}_{\sigma\nu\lambda}}
                                  + \nabla_{\rho\tau}{R^{\mu}_{\sigma\nu\lambda}} )
                        + (1/60) (  21 R^{\mu}_{\lambda\xi\rho} R^{\xi}_{\sigma\nu\tau}
                                  + 48 R^{\mu}_{\xi\rho\lambda} R^{\xi}_{\sigma\nu\tau}
                                  - 37 R^{\mu}_{\sigma\xi\lambda} R^{\xi}_{\nu\rho\tau} ) ) x^{\sigma} x^{\lambda} x^{\tau} ).
                                                                  # cdb(ex-12.400,GammaBar)

   # convert from Greek to Latin indices

   distribute (GammaBar)
   rename_dummies (GammaBar,"greek","latin")                      # cdb(ex-12.401,GammaBar)

   # lower the \mu index

   GammaBar := \delta_{a \mu} @(GammaBar).                        # cdb(ex-12.402,GammaBar)
   distribute (GammaBar)                                          # cdb(ex-12.403,GammaBar)
   eliminate_kronecker (GammaBar)                                 # cdb(ex-12.404,GammaBar)

   # sort products

   GammaBar = product_sort (GammaBar)                             # cdb(ex-12.405,GammaBar)

   # Replace R with - R (Calzetta uses the non-MTW convention for Riemann)

   substitute (GammaBar, $R_{a b c d} -> - R_{a b c d}$)          # cdb(ex-12.406,GammaBar)
   substitute (GammaBar, $R^{a}_{b c d} -> - R^{a}_{b c d}$)      # cdb(ex-12.407,GammaBar)

   substitute (GammaBar, $R^{a}_{b c d} -> g^{a e} R_{e b c d}$)  # cdb(ex-12.408,GammaBar)

   cal1 = get_xterm (GammaBar,1)                                  # cdb(ex-12.500,cal1)
   cal2 = get_xterm (GammaBar,2)                                  # cdb(ex-12.501,cal2)
   cal3 = get_xterm (GammaBar,3)                                  # cdb(ex-12.502,cal3)

   cal1 = reformat (cal1,3,1)                                     # cdb(ex-12.600,cal1)
   cal2 = reformat (cal2,12,1)                                    # cdb(ex-12.601,cal2)
   # cal3 = reformat (cal3,360,1)                                   # cdb(ex-12.602,cal3)

   cal30 = get_gterm (cal3,0)                                     # cdb(ex-12.602,cal30)
   cal31 = get_gterm (cal3,1)                                     # cdb(ex-12.603,cal31)

   cal1  = reformat (cal1, 3,1)                                   # cdb(ex-12.604,cal1)
   cal2  = reformat (cal2,12,1)                                   # cdb(ex-12.605,cal2)

   cal30 = reformat (cal30,40,1)                                  # cdb(ex-12.606,cal30)
   cal31 = reformat (cal31,360,1)                                 # cdb(ex-12.607,cal31)

   cal3 := @(cal30) + @(cal31).                                   # cdb(ex-12.608,cal3)

   GammaBar := @(cal1) + @(cal2) + @(cal3).                       # cdb(ex-12.409,GammaBar)

\end{cadabra}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.400}}
   \Dmath*{\cdb*{ex-12.401}}
   \Dmath*{\cdb*{ex-12.402}}
   \Dmath*{\cdb*{ex-12.403}}
   \Dmath*{\cdb*{ex-12.404}}
   \Dmath*{\cdb*{ex-12.405}}
   \Dmath*{\cdb*{ex-12.406}}
   \Dmath*{\cdb*{ex-12.407}}
   \Dmath*{\cdb*{ex-12.408}}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.500}}
   \Dmath*{\cdb*{ex-12.501}}
   \Dmath*{\cdb*{ex-12.502}}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.600}}
   \Dmath*{\cdb*{ex-12.601}}
   \Dmath*{\cdb*{ex-12.602}}
   \Dmath*{\cdb*{ex-12.603}}
   \Dmath*{\cdb*{ex-12.604}}
   \Dmath*{\cdb*{ex-12.605}}
   \Dmath*{\cdb*{ex-12.606}}
   \Dmath*{\cdb*{ex-12.607}}
   \Dmath*{\cdb*{ex-12.608}}
\end{dgroup*}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.409}}
\end{dgroup*}

\clearpage

\def\GammaBar{{\bar{\Gamma}}}

% -----------------------------------------------------------------------------
\subsection*{The fun begins $\Gamma - \GammaBar$}

It's now time to compute the difference $\Gamma-\GammaBar$. Here it is.

\begin{cadabra}
   def reformat_diff (obj):

       distribute (obj)

       obj1  = get_xterm (obj,1)
       obj2  = get_xterm (obj,2)
       obj3  = get_xterm (obj,3)

       obj30 = get_gterm (obj3,0)
       obj31 = get_gterm (obj3,1)

       obj1  = reformat (obj1, 3,1)
       obj2  = reformat (obj2,12,1)

       obj30 = reformat (obj30,40,1)
       obj31 = reformat (obj31,360,1)

       obj3 := @(obj30) + @(obj31).

       ans := @(obj1) + @(obj2) + @(obj3).

       return ans

   # We could use reformat_diff here but instead we'll do it one step at a time so that
   # we can see exactly what's going on. Later on we will use reformat_diff to do the job.

   diff := @(Gamma) - @(GammaBar).                                # cdb(ex-12.diff.100,diff)
   distribute (diff)

   diff1  = get_xterm (diff,1)                                    # cdb(ex-12.diff.200,diff1)
   diff2  = get_xterm (diff,2)                                    # cdb(ex-12.diff.201,diff2)
   diff3  = get_xterm (diff,3)                                    # cdb(ex-12.diff.202,diff3)

   diff30 = get_gterm (diff3,0)                                   # cdb(ex-12.diff.203,diff30)
   diff31 = get_gterm (diff3,1)                                   # cdb(ex-12.diff.204,diff31)

   diff1  = reformat (diff1, 3,1)                                 # cdb(ex-12.diff.300,diff1)
   diff2  = reformat (diff2,12,1)                                 # cdb(ex-12.diff.301,diff2)

   diff30 = reformat (diff30,40,1)                                # cdb(ex-12.diff.302,diff30)
   diff31 = reformat (diff31,360,1)                               # cdb(ex-12.diff.303,diff31)

   diff3 := @(diff30) + @(diff31).                                # cdb(ex-12.diff.304,diff3)

   diff := @(diff1) + @(diff2) + @(diff3).                        # cdb(ex-12.diff.305,diff)

\end{cadabra}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.diff.100}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.diff.200}}
   \Dmath*{\cdb*{ex-12.diff.201}}
   \Dmath*{\cdb*{ex-12.diff.202}}
   \Dmath*{\cdb*{ex-12.diff.203}}
   \Dmath*{\cdb*{ex-12.diff.204}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.diff.300}}
   \Dmath*{\cdb*{ex-12.diff.301}}
   \Dmath*{\cdb*{ex-12.diff.302}}
   \Dmath*{\cdb*{ex-12.diff.303}}
   \Dmath*{\cdb*{ex-12.diff.304}}
   \Dmath*{\cdb*{ex-12.diff.305}}
\end{dgroup*}

\clearpage

% -----------------------------------------------------------------------------
\subsection*{Second order terms}

\begin{cadabra}
   diff2  = get_xterm (diff,2)
   diff2 := 12 @(diff2).                                                        # cdb (ex-12.701,diff2)
   distribute (diff2)                                                           # cdb (ex-12.702,diff2)

   diff2 = add_tags (diff2,'\\mu')                                              # cdb (ex-12.711,diff2)

   # swap indices on middle term, then apply 2nd Bianchi identity

   zoom       (diff2, $\mu_{1} Q??$)                                            # cdb (ex-12.712,diff2)
   substitute (diff2, $\nabla_{b}{R_{a d c e}} -> - \nabla_{b}{R_{d a c e}}$)   # cdb (ex-12.713,diff2)
   unzoom     (diff2)

   substitute (diff2, $\mu_{1} -> \mu_{0}, \mu_{2} -> \mu_{0}$)                 # cdb (ex-12.714,diff2)
   substitute (diff2, $\mu_{0} -> 0$)                                           # cdb (ex-12.715,diff2)

   diff2 = clear_tags (diff2,'\\mu')                                            # cdb (ex-12.716,diff2)

   diff2 := @(diff2) / 12 .

   diff := @(diff1) + @(diff2) + @(diff3).

   diff  = reformat_diff (diff)                                                 # cdb(ex-12.diff.306,diff)
\end{cadabra}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.701}}
   \Dmath*{\cdb*{ex-12.702}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.711}}
   \Dmath*{\cdb*{ex-12.712}}
   \Dmath*{\cdb*{ex-12.713}}
   \Dmath*{\cdb*{ex-12.714}}
   \Dmath*{\cdb*{ex-12.715}}
   \Dmath*{\cdb*{ex-12.716}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.diff.306}}
\end{dgroup*}

\clearpage

% -----------------------------------------------------------------------------
\subsection*{Third order terms, commute $\nabla\nabla R$ terms}

\begin{cadabra}
   diff3  = get_xterm (diff,3)
   diff3 := 360 @(diff3).                              # cdb (ex-12.801,diff3)
   distribute (diff3)                                  # cdb (ex-12.802,diff3)

   # commutation rule for covariant derivs on Rabcd, see exrecise 3.6
   # note: \nabla_{a b} defined as \nabla_{a}\nabla_{b}
   CommuteNablaRiemann := \nabla_{f e}(R_{a b c d}) -> \nabla_{e f}(R_{a b c d})
                                                     + g^{u v} R_{u a e f} R_{v b c d}
                                                     + g^{u v} R_{u b e f} R_{a v c d}
                                                     + g^{u v} R_{u c e f} R_{a b v d}
                                                     + g^{u v} R_{u d e f} R_{a b c v}.

   diff3 = add_tags (diff3,'\\mu')                     # cdb (ex-12.901,diff3)

   # commute derivs on Rabcd so that each double deriv is of the form \nabla_{b*}

   substitute (diff3, $\mu_{3} -> \mu_{1}$)            # cdb (ex-12.902,diff3)

   zoom       (diff3, $\mu_{1} Q??$)                   # cdb (ex-12.903,diff3)
   substitute (diff3, CommuteNablaRiemann)             # cdb (ex-12.904,diff3)
   unzoom     (diff3)

   diff3 = clear_tags (diff3,'\\mu')
   diff3 := @(diff3) / 360 .

   distribute   (diff3)
   canonicalise (diff3)                                # cdb (ex-12.905,diff3)

   diff := @(diff1) + @(diff2) + @(diff3).

   diff  = reformat_diff (diff)                        # cdb(ex-12.diff.307,diff)
\end{cadabra}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.801}}
   \Dmath*{\cdb*{ex-12.802}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.901}}
   \Dmath*{\cdb*{ex-12.902}}
   \Dmath*{\cdb*{ex-12.903}}
   \Dmath*{\cdb*{ex-12.904}}
   \Dmath*{\cdb*{ex-12.905}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.diff.307}}
\end{dgroup*}

\clearpage

% -----------------------------------------------------------------------------
\subsection*{Third order terms, use 2nd Bianchi identity on $\nabla\nabla R$ terms}

\begin{cadabra}
   diff3  = get_xterm (diff,3)
   diff3 := 360 @(diff3).                                                           # cdb (ex-12.910,diff3)
   distribute (diff3)                                                               # cdb (ex-12.911,diff3)

   diff3 = add_tags (diff3,'\\mu')                                                  # cdb (ex-12.912,diff3)

   # swap indices on middle second deriv term, then apply 2nd Bianchi identity

   zoom       (diff3, $\mu_{1} Q??$)                                                # cdb (ex-12.913,diff3)
   substitute (diff3, $\nabla_{b c}{R_{a e d f}} -> - \nabla_{b c}{R_{e a d f}}$)   # cdb (ex-12.914,diff3)
   unzoom     (diff3)

   substitute (diff3, $\mu_{1} -> \mu_{0}, \mu_{2} -> \mu_{0}$)                     # cdb (ex-12.915,diff3)
   substitute (diff3, $\mu_{0} -> 0$)                                               # cdb (ex-12.916,diff3)

   diff3 = clear_tags (diff3,'\\mu')
   diff3 := @(diff3) / 360 .

   distribute   (diff3)
   canonicalise (diff3)                                                             # cdb (ex-12.917,diff3)

   diff := @(diff1) + @(diff2) + @(diff3).

   diff  = reformat_diff (diff)                                                     # cdb(ex-12.diff.308,diff)
\end{cadabra}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.910}}
   \Dmath*{\cdb*{ex-12.911}}
   \Dmath*{\cdb*{ex-12.912}}
   \Dmath*{\cdb*{ex-12.913}}
   \Dmath*{\cdb*{ex-12.914}}
   \Dmath*{\cdb*{ex-12.915}}
   \Dmath*{\cdb*{ex-12.916}}
   \Dmath*{\cdb*{ex-12.917}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.diff.308}}
\end{dgroup*}

\clearpage

% -----------------------------------------------------------------------------
\subsection*{Third order terms, use 1st Bianchi identity on $R R$ terms}

\begin{cadabra}
   diff3  = get_xterm (diff,3)
   diff3 := 360 @(diff3).
   distribute (diff3)

   diff3 = add_tags (diff3,'\\mu')                                              # cdb (ex-12.921,diff3)

   # swap indices on middle term, then apply 1st Bianchi identity

   zoom       (diff3, $\mu_{1} Q??$)                                            # cdb (ex-12.922,diff3)
   substitute (diff3, $R_{a d b g} R_{c e f h} -> - R_{a d g b} R_{c e f h}$)   # cdb (ex-12.923,diff3)
   unzoom     (diff3)

   substitute (diff3, $\mu_{1} -> \mu_{0}, \mu_{2} -> \mu_{0}$)                 # cdb (ex-12.924,diff3)
   substitute (diff3, $\mu_{0} -> 0$)                                           # cdb (ex-12.925,diff3)

   diff3 = clear_tags (diff3,'\\mu')                                            # cdb (ex-12.926,diff3)

   diff := @(diff1) + @(diff2) + @(diff3).

   diff  = reformat_diff (diff)                                                 # cdb(ex-12.diff.309,diff)
\end{cadabra}

\clearpage

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.921}}
   \Dmath*{\cdb*{ex-12.922}}
   \Dmath*{\cdb*{ex-12.923}}
   \Dmath*{\cdb*{ex-12.924}}
   \Dmath*{\cdb*{ex-12.925}}
   \Dmath*{\cdb*{ex-12.926}}
\end{dgroup*}

\begin{dgroup*}
   \Dmath*{\cdb*{ex-12.diff.309}}
\end{dgroup*}

\end{document}


\section{Periodogram-based Methods Applied to Real–World Data}

\begin{enumerate}[label=\alph*), leftmargin=*]
%% a)
\item
%

The sunspot time series and its Chebyshev-windowed periodogram method are provided at figure \ref{fig:1_4_a}.
The raw time series (blue) spectral estimates are compared to two preprocessed series:
\begin{enumerate}
    \item a centered and detrended series (red, \texttt{mean \& detrend})
    \item a logarithmic centered series (yellow, \texttt{log \& mean})
\end{enumerate}

\begin{figure}[h]
    \centering
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/spectrum-estimation/periodogram-based-methods-applied-to-real-world-data/assets/a/sunspots-raw}
    \end{subfigure}
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/spectrum-estimation/periodogram-based-methods-applied-to-real-world-data/assets/a/sunspots-Chebyshev}
    \end{subfigure}
    \caption{Sunspots: Chebyshev-windowed periodogram method, to raw and preprocessed series.}
    \label{fig:1_4_a}
\end{figure}

Subtraction of the \texttt{mean}, results in attenuation of the DC component ($f = 0$), while \texttt{detrend} removed low-frequency components.
Consequently, the spectral estimate of the centered and detrended series is almost identical to the raw sunspots time series for frequencies $f \gtrapprox 0.02$ (in $rad/sample$),
while the lower frequency components are eliminated.

To avoid logarithms of zero, the logarithmic series is obtained by first adding a small constant to the raw sunspots time series (MATLAB $\mathtt{eps} = 2.2204e-16$) and then
taking natural \texttt{log} and removing the \texttt{mean}. Similarly, the DC component is also removed and the peaks at the same frequencies are observed, but now they are more noticeable
(only peaks of interest are above $0dB$).

%% b)
\item
%

The Standard and Bartlett method periodograms of the EEG signal are provided at figure \ref{fig:1_4_b_1}. The latter is easier to interpret since its peaks are accentuated.
The peaks distinguished from the periodograms are at frequencies $f = 13,\ 26,\ 39,\ 50\ Hz$ as well as a wider peak at $8-10\ Hz$.

\begin{figure}[h]
    \centering
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/spectrum-estimation/periodogram-based-methods-applied-to-real-world-data/assets/b/eeg-periodogram-standard}
    \end{subfigure}
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/spectrum-estimation/periodogram-based-methods-applied-to-real-world-data/assets/b/eeg-periodogram-averaged-bartlett}
    \end{subfigure}
    \caption{EEG: standard and Bartlett method periodogram.}
    \label{fig:1_4_b_1}
\end{figure}

As suggested by the instructions, the components in $8-10\ Hz$ are due to the tiredness of the subject during the recording, adequately captured by the Bartlett method periodograms,
regardless the window length $\Delta t$.

The peak at $f_{0}^{SSEVP} = 13\ Hz$ corresponds to the fundamental frequency of the SSEVP, whose harmonics can be noticed at frequencies $f_{1}^{SSEVP} = 26\ Hz$ and
$f_{2}^{SSEVP} = 39\ Hz$. Its third harmonic $f_{3}^{SSEVP} = 52\ Hz$ is hardly visible at the standard periodogram and the Bartlett method periodogram with $\Delta t = 10\ s$, highly affected by
the strong $f^{PLI} = 50\ Hz$ component due to the power-line interference.

\begin{figure}[h]
    \centering
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/spectrum-estimation/periodogram-based-methods-applied-to-real-world-data/assets/b/eeg-periodogram-averaged-bartlett-dt_10}
    \end{subfigure}
    ~
    \begin{subfigure}{0.49\textwidth}
        \centering
        \includegraphics[height=1.5in]{report/spectrum-estimation/periodogram-based-methods-applied-to-real-world-data/assets/b/eeg-periodogram-averaged-bartlett-dt_1}
    \end{subfigure}
    \caption{EEG: Bartlett method periodogram averaging window $\Delta t$.}
    \label{fig:1_4_b_2}
\end{figure}

Figure \ref{fig:1_4_b_2} depicts the comparison between the Standard and Bartlett method periodograms for averagign window lengths $\Delta t = 10\ s$ and $\Delta t = 1\ s$.
For $\Delta t = 10\ s$, the periodogram has reduced variance compared to the standard periodogram, but inevitably reduced resolution. Nonetheless, the peaks of interest
(harmonics of SSEVP, power-line interference frequency and $8-10\ Hz$ band) are observable. On the other hand, for $\Delta t = 1\ s$ despite the even more reduced variance
(by a factor of 10) the resolution is insufficient to capture the $3^{rd}$ harmonic of SSEVP, but the rest of the peaks are visible.

Overall, the trade-off between variance and precision is illustrated, from the standard periodogram with best precision and maximum variance to the Bartlett method periodgram
with $\Delta t = 1\ s$ with worst precision and least variance.

%
\end{enumerate}


\documentclass{article}
\input{../homework-problems}

\toggletrue{solutions}
%\togglefalse{solutions}
\toggletrue{answers}
\newtheorem{problem}{Problem}

\newcommand{\hide}[1]{}
\renewcommand{\fcProblemRef}{\theproblem.\theenumi}
\renewcommand{\fcSubProblemRef}{\theenumi.\theenumii}

\begin{document}

\begin{center}
\Large
Master Problem Sheet \\
Version \today
\\ Calculus III \\ \normalsize Instructor: Todor Milev

\end{center}

This master problem sheet contains all freecalc problems on the topics studied in Calculus III. For a list of contributors/authors of the freecalc project (and in particular, the present problem collection) see file contributors.tex.

\fcLicenseContent

\tableofcontents

\section{Distances and coordinates}
\begin{problem}
\input{../../modules/coordinate-systems/homework/distance-between-points}
\end{problem}

\begin{problem}
\input{../../modules/coordinate-systems/homework/recognizing-spheres}
\end{problem}

\section{Vectors}
\subsection{Vector basics}
\begin{problem}
\input{../../modules/vectors/homework/basic-operations-in-coordinates-1}
\end{problem}
\subsection{Dot product}
\begin{problem}
\input{../../modules/vectors/homework/dot-product}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/vectors-orthogonal}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/vectors-angles}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/angle-between-vertices-and-origin-regular-tetrahedron}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/vector-projection}
\end{problem}

\subsection{Cross product}

\begin{problem}
\input{../../modules/vectors/homework/triangle-in-space-area}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/find-orthogonal-vector}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/find-tetrahedron-volume}
\end{problem}

\input{../../modules/vectors/homework/find-tetrahedron-volume-solutions}

\begin{problem}
\input{../../modules/vectors/homework/points-coplanar}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/jacobi-identity}
\end{problem}

\section{Lines, planes, points and relationships between them}
\subsection{Lines}
\subsubsection{Line from point and direction}
\begin{problem}
\input{../../modules/vectors/homework/line-from-point-and-direction}
\end{problem}

\subsubsection{Line from two points}
\begin{problem}
\input{../../modules/vectors/homework/line-from-two-points}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/line-from-two-points-lines-from-cube-vertices}
\end{problem}
\input{../../modules/vectors/homework/line-from-two-points-lines-from-cube-vertices-solution}

\subsection{Planes}
\subsubsection{Plane from point and normal}
\begin{problem}
\input{../../modules/vectors/homework/plane-from-point-and-normal}
\end{problem}
\input{../../modules/vectors/homework/plane-from-point-and-normal-solution}

\subsubsection{Plane from point and two directions}
\begin{problem}
\input{../../modules/vectors/homework/plane-from-point-and-two-directions}
\end{problem}

\subsubsection{Plane from three points}
\begin{problem}
\input{../../modules/vectors/homework/plane-from-three-points}
\end{problem}

\subsection{Distances between points, lines, planes}
\subsubsection{Distance between line and point}
\begin{problem}
\input{../../modules/vectors/homework/distance-line-point}
\end{problem}
\subsubsection{Distance between plane and point}
\begin{problem}
\input{../../modules/vectors/homework/distance-plane-point}
\end{problem}

\subsubsection{Distance between lines}
\begin{problem}
\input{../../modules/vectors/homework/distance-between-edges-regular-tetrahedron}
\end{problem}
\begin{problem}
\input{../../modules/vectors/homework/distance-between-lines}
\end{problem}
\input{../../modules/vectors/homework/distance-between-lines-solutions}

\subsection{Angles (in space)}
\subsubsection{Angles between lines}
\begin{problem}
\input{../../modules/vectors/homework/angle-between-edges-regular-tetrahedron}
\end{problem}

\subsubsection{Angle between plane and line}
\begin{problem}
\input{../../modules/vectors/homework/angle-betwen-plane-and-line}
\end{problem}

\begin{problem}
\input{../../modules/vectors/homework/angle-betwen-tetrahedron-edge-and-base}
\end{problem}

\subsubsection{Angles between planes}
\begin{problem}
\input{../../modules/vectors/homework/angle-between-faces-tetrahedron}
\end{problem}

\section{Polar, Cylindrical and Spherical coordinates}
\subsection{Polar coordinates}
\begin{problem}
\input{../../modules/polar-coordinates/homework/equation-of-line-in-polar}
\end{problem}

\input{../../modules/polar-coordinates/homework/equation-of-line-in-polar-solutions}

\begin{problem}
\input{../../modules/polar-coordinates/homework/equation-of-circle-in-polar}
\end{problem}
\subsection{Cylindrical coordinates - basics}

\begin{problem}
\input{../../modules/cylindrical-coordinates/homework/equation-of-plane-in-cylindrical}
\end{problem}

\begin{problem}
\input{../../modules/cylindrical-coordinates/homework/equation-of-sphere-in-cylindrical}
\end{problem}
\subsection{Spherical coordinates - basics}

\begin{problem}
\input{../../modules/spherical-coordinates/homework/equation-of-plane-in-spherical}
\end{problem}

\begin{problem}
\input{../../modules/spherical-coordinates/homework/equation-of-sphere-in-spherical}
\end{problem}

\section{Quadratic surfaces}

\begin{problem}
\input{../../modules/quadratic-surfaces/homework/name-quadratic-surfaces-and-give-examples}
\end{problem}

\begin{problem}
\input{../../modules/quadratic-surfaces/homework/find-surface-type-from-equation}
\end{problem}
\input{../../modules/quadratic-surfaces/homework/find-surface-type-from-equation-solutions}

\section{Curves in space}
\subsection{Curvature}
\begin{problem}
\input{../../modules/parametric-curves/homework/curvature-computation-1}
\end{problem}
\input{../../modules/parametric-curves/homework/curvature-computation-1-solutions}

\subsection{Curve length}
\begin{problem}
\input{../../modules/parametric-curves/homework/space-curve-length-1}
\end{problem}
\input{../../modules/parametric-curves/homework/space-curve-length-1-solutions}
\begin{problem}
\input{../../modules/parametric-curves/homework/space-curve-write-length-integral-1}
\end{problem}

\section{Multivariable limits}

\begin{problem}
\input{../../modules/continuity-multivariable/homework/limits-multivariable-1}
\end{problem}

\input{../../modules/continuity-multivariable/homework/limits-multivariable-1-solutions}
\section{Tangent planes}

\begin{problem}
\input{../../modules/partial-derivatives/homework/compute-tangent-plane-graph-function-1}
\end{problem}

\begin{problem}
\input{../../modules/partial-derivatives/homework/compute-tangent-plane-surface-implicit-equation-1}
\end{problem}
\input{../../modules/partial-derivatives/homework/compute-tangent-plane-surface-implicit-equation-1-solutions}

\section{Partial derivatives}

\begin{problem}
\input{../../modules/partial-derivatives/homework/compute-partial-derivative-1}
\end{problem}

\input{../../modules/partial-derivatives/homework/compute-partial-derivative-1-solutions}

\subsection{Variable changes in differential operators}

\begin{problem}
\input{../../modules/partial-derivatives/homework/variable-change-differential-operators-1}
\end{problem}
\input{../../modules/partial-derivatives/homework/variable-change-differential-operators-1-solutions}
\section{Multivariable optimization (min/max)}

\begin{problem}
\input{../../modules/optimization-multivariable/homework/find-min-max-1}
\end{problem}
\input{../../modules/optimization-multivariable/homework/find-min-max-1-solutions}
\subsection{Lagrange multipliers}

\begin{problem}
\input{../../modules/optimization-multivariable/homework/min-max-with-lagrange-multipliers-1}
\end{problem}
\input{../../modules/optimization-multivariable/homework/min-max-with-lagrange-multipliers-1-solutions}

\section{Double integrals}

\begin{problem}
\input{../../modules/integration-multivariable/homework/double-integrals-1}
\end{problem}

\begin{problem}
\input{../../modules/integration-multivariable/homework/double-integrals-2}
\end{problem}
\input{../../modules/integration-multivariable/homework/double-integrals-2-solutions}
\subsection{Double integrals solved via changing integration order}

\begin{problem}
\input{../../modules/integration-multivariable/homework/double-integrals-change-variable-order-1}
\end{problem}
\input{../../modules/integration-multivariable/homework/double-integrals-change-variable-order-1-solutions}
\section{Triple Integrals}
\begin{problem}
\input{../../modules/integration-multivariable/homework/triple-integrals-over-curvilinear-trapezoids-1}
\end{problem}
\input{../../modules/integration-multivariable/homework/triple-integrals-over-curvilinear-trapezoids-1-solutions}

\section{Variable Changes in Multivariable Integrals}
\begin{problem}
\textbf{Problem \ref{problemVolumeRaisedHorn} is of higher difficulty than the problem you will get on the exam.}

\input{../../modules/integration-multivariable-variable-change/homework/volumes-1}
\end{problem}
\input{../../modules/integration-multivariable-variable-change/homework/volumes-1-solutions}

\subsection{Integrals in Polar, Cylindrical and Spherical coordinates}
\subsubsection{Polar coordinates}
\begin{problem}
\input{../../modules/integration-multivariable-variable-change/homework/integrals-polar-1}
\end{problem}
\subsubsection{Cylindrical coordinates}
\begin{problem}
\input{../../modules/integration-multivariable-variable-change/homework/integrals-cylindrical-1}
\end{problem}
\subsubsection{Spherical coordinates}
\begin{problem}
\input{../../modules/integration-multivariable-variable-change/homework/integrals-spherical-centroids-centers-of-mass-1}
\end{problem}
\section{2D Field Potential}
\begin{problem}
\input{../../modules/integration-line-integrals/homework/find-2D-scalar-potential}
\end{problem}
\section{Green's Theorem}
\subsection{Line Integrals via Greens Theorem}
\begin{problem}
\input{../../modules/integration-line-integrals/homework/line-integrals-via-greens-theorem}
\end{problem}
\section{Surface Integrals}
\subsection{Surface area}
\begin{problem}
\input{../../modules/integration-surface-integrals/homework/surface-area-1}
\end{problem}
\subsection{Flux}
\begin{problem}
\input{../../modules/integration-surface-integrals/homework/find-flux-1}
\end{problem}
\subsection{Divergence Theorem}
\begin{problem}
\input{../../modules/integration-surface-integrals/homework/divergence-theorem-1}
\end{problem}

\end{document}


% jam 2004-08-28

\subsection{Functions of faces}
\label{sec:faces}

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

\subsubsection{Corner angles}
\label{sec:corner_angles}

\begin{figure}[!htp]
\centering
\begin{verbatim}

          V2/p2
            o
           /U\
          / g2\
     E20 /     \ E12
        / F012  \
       /)g0   g1(\
V0/p0 o-----------o V1/p1
           E01

\end{verbatim}
\caption{Face labeling.
\label{fig:face_labeling}}
\end{figure}

Suppose face $\F_{012}$ has vertices $\V_0, \V_1, \V_2$,
at points $\p_0, \p_1, \p_2$,
and edges $\E_{01}, \E_{12}, \E_{20}$,
as labeled in figure \ref{fig:face_labeling}.

The {\em corner angle} $\gamma_i$ in face $\F_{012}$ of vertex $\V_i$ is
the angle between the two edges in $\F_{012}$ that meet at $\V_i$:
\begin{eqnarray}
\gamma_i
& = & \gamma(\F_{012},\V_i)
\\
& = & \gamma(\p_i,\p_{(i+1) \% 3},\p_{(i+2) \% 3})
\nonumber
\\
& = & \theta(\p_{(i+1) \% 3} - \p_i,\p_{(i+2) \% 3} - \p_i)
\nonumber
\\
& = &
\cos^{-1}
\left[
\frac{ \left( \p_{(i+1) \% 3} - \p_i \right)
  \bullet
  \left( \p_{(i+2) \% 3} - \p_i \right) }
{ \| \p_{(i+1) \% 3} - \p_i \|
  \| \p_{(i+2) \% 3} - \p_i \| }
\right]
\nonumber
\end{eqnarray}

Corner angles vary between $0$ and $\pi$, with both extremes
corresponding to singular, zero-area faces.
The sum of corner angles for a given face is always $\pi$.

Using equation \ref{eq:angle_gradient},
it's easy to see that the partial gradients are:
\begin{eqnarray}
\Gc{\p_0}{\gamma(\p_0,\p_1,\p_2)}{\q}
& = &
\frac{
\left[ (\q_1 -\q_0) \perp (\q_2 - \q_0) \right]
+
\left[ (\q_2 -\q_0) \perp (\q_1 - \q_0) \right]
}
{ \sqrt{\|\q_1 - \q_0\|^2\|\q_2 - \q_0\|^2 -
\left( (\q_1 - \q_0) \bullet (\q_2 - \q_0) \right)^2 }}
\\
\Gc{\p_1}{\gamma(\p_0,\p_1,\p_2)}{\q}
& = &
\frac{-(\q_1 -\q_0) \perp (\q_2 - \q_0)}
{ \sqrt{\|\q_1 - \q_0\|^2\|\q_2 - \q_0\|^2 -
\left( (\q_1 - \q_0) \bullet (\q_2 - \q_0) \right)^2 }}

\nonumber
\\
\Gc{\p_2}{\gamma(\p_0,\p_1,\p_2)}{\q}
& = &
\frac{-(\q_2 -\q_0) \perp (\q_1 - \q_0)}
{ \sqrt{\|\q_1 - \q_0\|^2\|\q_2 - \q_0\|^2 -
\left( (\q_1 - \q_0) \bullet (\q_2 - \q_0) \right)^2 }}
\nonumber
\end{eqnarray}

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

\subsubsection{Functions of face normals}
\label{sec:normals}

A number of important functions of triangular meshes,
such as surface area,
are based on face normal vectors.

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

\paragraph{Area-weighted face normal}
\label{sec:areanormal}

Suppose we have a face whose 3 vertices are at $\p = (\p_0, \p_1, \p_2)$,
where $\p_i \in \Reals^3; i=0,1,2.$
(Note that the order of the $\p_i$ determines the orientation of the face.
With a face as labeled in figure \ref{fig:face_labeling},
the normal points out of the page.)

The {\it area-weighted normal} vector is
\nopagebreak
\begin{eqnarray}
\a (\p) & = & (\p_0 \times \p_1) \ + \ (\p_1 \times \p_2) \ + \ (\p_2 \times \p_0) \\
        & = & (\p_1 - \p_0) \ \times \ (\p_2 - \p_0) \nonumber \\
        & = & (\p_2 - \p_1) \ \times \ (\p_0 - \p_1) \nonumber \\
        & = & (\p_0 - \p_2) \ \times \ (\p_1 - \p_2) \nonumber
\end{eqnarray}

The 'partial' derivatives of the area-weighted normal are:
\begin{eqnarray}
\Dd{\p_0}{\a}{\q}{r_0} \
& = \ (\r0 \times \q_1) \ + \ (\q_2 \times \r_0) & = (\q_2 - \q_1) \times \r_0 \\
\Dd{\p_1}{\a}{\q}{r_1} \
& = \ (\r1 \times \q_2) \ + \ (\q_0 \times \r_1) & = (\q_0 - \q_2) \times \r_1 \nonumber \\
\Dd{\p_2}{\a}{\q}{r_2} \
& = \ (\r2 \times \q_0) \ + \ (\q_1 \times \r_2) & = (\q_1 - \q_0) \times \r_2 \nonumber
\end{eqnarray}

Note that $\Df{\p}{\a}$ is {\it skew-symmetric}, that is,
$\Df{\p}{\a}^{\dagger} = -\Df{\p}{\a}.$

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

\paragraph{Face area}
\label{sec:facearea}

The area of a face is half the length of the area-weighted normal:
\begin{eqnarray}
A(\p)
& = & \frac{1}{2} \| \ \a(\p) \ \|  \\
& = & \frac{1}{2} \| \ (\p_0 \times \p_1) \ + \ (\p_1 \times \p_2) \ + \ (\p_2 \times \p_0) \ \|.
\nonumber
\end{eqnarray}

It follows from equation \ref{eq:norm_derivative}
that the first 'partial' derivative of the face area is:
\begin{eqnarray}
\label{eq:area_partial_derivative}
\Dd{\p_0}{A}{\q}{\r_0}
& = &
\frac{\a(\q)^\dagger}{2\|\a(\q)\|}
{\Dd{\p_0}{\a}{\q}{\r_0}}  \\
& = &
\frac{\a(\q)}{2\|\a(\q)\|}
\bullet
\left[(\r_0 \times \q_1) + (\q_2 \times \r_0)\right] \nonumber \\
& = &
\frac{\a(\q)}{2\|\a(\q)\|}
\bullet
\left[(\q_2 - \q_1) \ \times \  \r_0)\right] \nonumber \\
& = &
\frac{\a(\q) \times (\q_2 - \q_1)}{2\|\a(\q)\|}
\bullet
\r_0 \nonumber
\end{eqnarray}

The last identity follows from equation \ref{eq:dot_cross}.

The 'partial' gradients of the face area are then:
\begin{eqnarray}
\Gc{\p_0}{A}{\q} & = & \frac{\a(\q) \times (\q_2 - \q_1)}{2\|\a(\q)\|} \\
\Gc{\p_1}{A}{\q} & = & \frac{\a(\q) \times (\q_0 - \q_2)}{2\|\a(\q)\|} \nonumber \\
\Gc{\p_2}{A}{\q} & = & \frac{\a(\q) \times (\q_1 - \q_0)}{2\|\a(\q)\|} \nonumber
\end{eqnarray}

More simply, using the face unit normal \( \n(\p)  =  \frac{\a(\p)}{\| \a(\p) \|} \):
\begin{eqnarray}
\label{eq:area_gradient}
\Gc{\p_0}{A}{\q} & = & \frac{\n(\q)}{2} \times (\q_2 - \q_1) \\
\Gc{\p_1}{A}{\q} & = & \frac{\n(\q)}{2} \times (\q_0 - \q_2) \nonumber \\
\Gc{\p_2}{A}{\q} & = & \frac{\n(\q)}{2} \times (\q_1 - \q_0) \nonumber
\end{eqnarray}

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

\paragraph{Face unit normal vector}
\label{sec:facenormal}

The unit vector normal to a face whose vertices are at
$\p = (\p_0,\p_1,\p_2)$ is just the area weighted normal (see \autoref{sec:areanormal})
adjusted to length 1:
\begin{equation}
\n(\p)  =  \frac{\a(\p)}{\| \a(\p) \|}
\end{equation}

Following equation \ref{eq:normalized_function_derivative}, the derivative is:

\begin{eqnarray}
\label{eq:unit_normal_derivative}
\Dc{\n}{\p}{\q}
&  =
& \frac{ \left( {\| \a(\p) \|^2 \I_{\Reals^3}  -  \a(\p) \otimes \a(\p) }
{\| \a(\p) \|^3} \right) }
\; \Dc{\a}{\p}{\q}
 \\
& & \nonumber\\
&  =
& \frac{ \left( {\| \a(\p) \|^2 \I_{\Reals^3}  -  \a(\p) \otimes \a(\p) }
{\| \a(\p) \|^3} \right)} \ast
\nonumber \\
&    &
\left[ \left( \q_0 \times \p_1 \right) + \left( \p_2 \times \q_0 \right)
+
\left( \q_1 \times \p_2 \right) + \left( \p_0 \times \q_1 \right)
+
\left( \q_2 \times \p_0 \right) + \left( \p_1 \times \q_2 \right) \right]
\nonumber \\
& & \nonumber\\
&  =
& \frac{ \left( {\| \a(\p) \|^2 \I_{\Reals^3}  -  \a(\p) \otimes \a(\p) }{\| \a(\p) \|^3} \right)} \ast
\nonumber \\
&    &
\left[ \left( (\p_2 - \p_1) \times \q_0 \right)
+
\left( (\p_0 - \p_2) \times \q_1 \right)
+
\left( (\p_1 - \p_0) \times \q_2 \right) \right]
\nonumber \\
& & \nonumber\\
&  =
& { \left( {\I_{\Reals^3}  -  \n(\p) \otimes \n(\p) } \over {\| \a(\p) \|} \right)} \ast \; \Dc{\a}{\p}{\q}
\nonumber
\end{eqnarray}

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

\subsubsection{Aspect Ratio}
\label{sec:aspect_ratio}

Minimizing a measure of face aspect ratio can help maintain
a well-conditioned mesh.
Maximizing it may help in discovering collapse-able edges.

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

\paragraph{Squared edge lengths over area}
\label{sec:Squared-edge-lengths-over-area}

One measure of the deviation of a face from equilaterality is:
\begin{equation}
{\mathrm L2A}(\p_0,\p_1,\p_2)
=
\frac{ \| \p_0 - \p_1 \|^2 + \| \p_1 - \p_2 \|^2 + \| \p_2 - \p_0 \|^2 }
{A(\p)}
\end{equation}

Using \ref{eq:area_gradient}, it follows that the
partial gradients of L2A are:
\begin{eqnarray}
\label{eq:L2A_gradient}
\Gc{\p_0}{L2A}{\q}
& =
&
\left(
\frac{2\left[ \left( \p_0 - \p_1 \right) + \left( \p_0 - \p_2 \right) \right]}
{A(\q)}
\right)
\\
& - &
\left(
\frac{ \| \p_0 - \p_1 \|^2 + \| \p_1 - \p_2 \|^2 + \| \p_2 - \p_0 \|^2 }
{2 A^2(\q)}
\left[ \n(\q) \times (\q_2 - \q_1)
\right]
\right)
\nonumber \\
\Gc{\p_1}{L2A}{\q}
& =
&
\left(
\frac{2\left[ \left( \p_1 - \p_2 \right) + \left( \p_1 - \p_0 \right) \right]}
{A(\q)}
\right)
\nonumber
\\
& - &
\left(
\frac{ \| \p_0 - \p_1 \|^2 + \| \p_1 - \p_2 \|^2 + \| \p_2 - \p_0 \|^2 }
{2 A^2(\q)}
\left[ \n(\q) \times (\q_0 - \q_2) \right]
\right)
\nonumber
\\
\Gc{\p_2}{L2A}{\q}
& =
&
\left(
\frac{2\left[ \left( \p_2 - \p_0 \right) + \left( \p_2 - \p_1 \right) \right]}
{A(\q)}
\right)
\nonumber
\\
& - &
\left(
\frac{ \| \p_0 - \p_1 \|^2 + \| \p_1 - \p_2 \|^2 + \| \p_2 - \p_0 \|^2 }
{2 A^2(\q)}
\left[ \n(\q) \times (\q_1 - \q_0) \right]
\right)
\nonumber
\end{eqnarray}


\section{Introduction}

Some of the important questions in cellular biology have to do with how the sizes of different parts of the cell, the organelles, are regulated.
Here we concentrate on modeling the growth of the Eukaryotic flagellum, an organelle that protrudes from the cell and is usually used for propulsion.
The choice of studying a flagellum has the advantage of restricting the problem to growth in only one dimension.
~\cite{bressloff}

\begin{figure}[!ht]
\centering
\parbox[t][2.3in][t]{4in}{
\hspace{1in}IFT Particles\\
\includegraphics[width=3in]{IFT_diagram.png}
\raisebox{1.75in}[1pt][1pt]{\hspace{2.2in}Kinesin-II}\\
\raisebox{1.39in}[1pt][1pt]{\hspace{3.04in}Microtubules}\\
\raisebox{1.5in}[1pt][1pt]{($-$)\hspace{2.2in}($+$)}\\
\raisebox{1.05in}[1pt][1pt]{\hspace{-0.15in}Dynein-1b}\\
\raisebox{0.83in}[1pt][1pt]{\hspace{2.95in}Flagellar membrane}
}
\caption{The interflagellar transport machinery.~\cite{rosenbaum2}
During intraflagellar transport,
linear arrays of IFT particles (yellow) are anterograde,
towards the ($+$) ends of the flagellar microtubules (blue)
by kinesin-II (pink), and retrograde (towards the ($-$) ends)
by cytoplasmic dynein 1b (green).
The IFT particles carry precursors that are necessary for the assembly of
the flagellar axoneme.}
\end{figure}

Eukaryotic flagella grow using the mechanism of intraflagellar transport. This process describes the movement of particles (transporters) carrying building blocks (precursor proteins) along the microtubule and depositing them at the flagellum tip.
The transporters use different motors for anterograde (towards tip) movement and retrograde (towards cell body) movement.
~\cite{rosenbaum}

In order to express the length of the flagellum mathematically we define the relevant variables as follows:
$L$ represents the flagellar length, $a$ represents the effective size of a precursor protein transported by a transporter, $v_+$ represents a transporter's anterograde speed, $v_-$ represents a transporter's retrograde speed, and $M$ represents the number of transporters in the flagellum.
We also suppose that a flagellum degrades at a constant speed of $V$.
Using these parameters it is possible to arrive at an ordinary differential equation (ODE) for the flagellum length, at the microscopic level, however, a stochastic model may be more representative of the behavior of the motors and transporters.
Our goal is to represent flagellar growth as a stochastic process, and compare and contrast the stochastic model with the deterministic model.
We are also interested in analyzing the behavior that cannot be predicted by the deterministic model, such as the variation of the flagellum length.
The deterministic ODE for the flagellum length is:

\begin{equation*}
\frac{dL}{dt} = \frac{a \bar{v} M}{2L} - V
\end{equation*}

Where $\bar{v}$ is the harmonic mean of $v_+$ and $v_-$.
The assembly rate, which is the positive right-hand-side term, is arrived at by noting that a transporter adds a segment of length $a$ to the flagellum every time it completes one round trip, to the tip of the flagellum and back.
The time it takes to complete this trip is the time taken to reach the tip from the base, $L/v_+$, added to the time it takes to reach the base from the tip, $L/v_-$, adding up to $2L/\bar{v}$.
The disassembly rate is given by $V$ and is length-independent.

The values we use for the parameters above in our simulations are taken from the paper by Paul C. Bressloff, \emph{Stochastic model of intraflagellar transport }~\cite{bressloff}: $v_+$, $v_-$, and $V$ are taken to be $2.0 \mu$m$/$s, $3.5 \mu$m$/$s, $0.01 \mu$m$/$s respectively, $M$ is taken to be 10, and $a$ is taken to be $10$nm.


\documentclass{beamer}
\usepackage[utf8]{inputenc}
% \usetheme{Warsaw}  %% Themenwahl

\input{../../shared_slides.tex}

\title{Minimum enclosing ball problem}
\date{\today}

\begin{document}
\maketitle
\frame{\tableofcontents}

\section{Intro}

\begin{frame}
  \frametitle{Intro} %%Folientitel
  \begin{definition} %%Definition
    Given a set of vectors $A = \{a_1, \dots, a_m\}\in \R^d$ we want to find the smallest ball containing all points of $A$.
    % A \subseteq B_{c,\rho} := \{x \in R^d : \Vert x - c \Vert \le \rho \}
    I.e.
    \begin{align}
      \min_{c,\rho}\,  \rho \\
      s.t. \Vert a_i -c  \Vert \le \rho \quad \forall i=1, \dots, m
    \end{align}
  \end{definition}
  Used in clustering, Data classification, facility location, computer graphics.
\end{frame}

\begin{frame}
  \frametitle{Rewriting the problem}
  Square constraints for smoothness
    \begin{align}
      \min_{c,\rho} \, \rho \\
      s.t. \Vert a_i \Vert^2 - 2 a_i^T c + c^T c  \le \rho \quad \forall i=1, \dots, m
    \end{align}

    Build Lagrangian Dual:
    \begin{equation}
      L(c, \rho, u) = \rho + \sum_{i=1}^m u_i *  (\Vert a_i -c  \Vert^2- \rho^2)
    \end{equation}
    and the dual function:
    \begin{equation}
      \Phi(u) = \inf_{c, \rho} L(c, \rho, u) = \sum_{i=1}^m \Vert a_i \Vert^2u_i - \sum_{i=1}^{m} u_i a_i^T c
    \end{equation}
    if $\sum_{i=1}^{m} u_i = 1$ with $u_i \ge 0$. Yields the unit simplex.

    sparsity (dual is typically sparse because the dual solution is combination of only a few points)
\end{frame}

\begin{frame}
  \frametitle{Solving via Frank-Wolfe}

\end{frame}
\end{document}


% Copyright 2018 Melvin Eloy Irizarry-Gelpí
\chapter{Impulse and Momentum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Preliminary}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Linear momentum (or just \textbf{momentum}) is a physical quantity that incorporates velocity and mass:
\begin{equation}
    p = m v
\end{equation}
Due to the second law of motion, a net \textbf{force} causes an acceleration (a change in the velocity of an object). This in turn leads to a change in the momentum of an object. The precise relationship between momentum and forces includes a quantity called \textbf{impulse}.

Formally, impulse is defined as the area under the curve in a \textbf{force versus time} graph. In principle, we need calculus to find the area under a curve. In practice we use a simple approximation: we approximate the curve as a \textbf{flat line}. The area under a flat line has the same shape as a rectangle. The area of a rectangle is the length multiplied by the width. Which flat line to use? Since force is in the vertical axis, a flat horizontal line corresponds to a fixed value of force along time. An appropriate choice for the fixed value is the \textbf{time-averaged force} $\bar{F}$. This would correspond to the width of the rectangle. The length of the rectangle is the amount of time $\Delta t$ that the force acts. The ``area'' is thus given by
\begin{equation}
    \text{``area'' } = \bar{F} \times \Delta t = \text{ impulse}
\end{equation}
Impulse has units of force multiplying time. If force is in newtons (N) and time in seconds (s), then impulse has units of N s. However, the newton is equivalent to
\begin{equation}
    1 \text{ N} = 1 \text{ kg m/s}^{2}
\end{equation}
Thus, the N s is equivalent to
\begin{equation}
    1 \text{ N s} = 1 \text{ kg m/s}
\end{equation}
If you look carefully, these are the same units of momentum. This does not mean that impulse is the same as momentum. Indeed, impulse can also be defined as the \textbf{change in momentum}:
\begin{equation}
    \text{impulse } = p_{2} - p_{1}
\end{equation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Experiment}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In order to verify the relationship between momentum, force, and impulse, we need to use a mechanical system where momentum and force change with time. A cart, moving along a track and colliding with a force sensor is perfect for this. Different attachment on the force sensor allow us to study different kinds of collisions. We also use a photogate to measure the speed of the cart before and after the collision. In this way, we collect data on force, and momentum, and the impulse can be determined in two different ways.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Analysis}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
We are going to determine the amount of impulse in two different ways.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Impulse from Change in Momentum}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The photogate measures the velocity of the object before the collision ($v_{1}$) and after the collision ($v_{2}$). Strictly speaking, \textbf{one of the velocities value should be negative} because there is \textbf{a change in the direction} of motion. We are going to multiply the value for $v_{2}$ by $-1$ in order to \textbf{make it negative}.

With the values of velocity, and the mass of the object, you can find the momentum of the object before the collision,
\begin{equation}
    p_{1} = m v_{1}
\end{equation}
and the momentum after the collision,
\begin{equation}
    p_{2} = m v_{2}
\end{equation}
The change in momentum is
\begin{equation}
    \Delta p = p_{2} - p_{1}
\end{equation}
This is the first estimate of the amount of impulse during the collision.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Impulse from Force Acting Over Time}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The force sensor measures the amount of force on the sensor during the collision. First you need to determine when the collision is taking place. This involves making a force versus time graph and finding the time $t_{1}$ when the collision begins and the time $t_{2}$ when it ends. With these times you can compute the amount of time that the collision lasts:
\begin{equation}
    \Delta t = t_{2} - t_{1}
\end{equation}
Then you delete all the force values before and after the collision in the force column. Finally, you can compute the average force during this time period. This gives you the value of $\bar{F}$. With $\bar{F}$ and $\Delta t$ you can compute the impulse:
\begin{equation}
    \text{impulse } = \bar{F} \times \Delta t
\end{equation}
This is the second estimate of the amount of impulse during the collision.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{My Data}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
There are two experiments: elastic and inelastic collisions. The difference between these experiment is that in the inelastic case, the amount of force during the collision is larger, and the velocity (and momentum) after the inelastic collision is zero. Besides that, the analysis is almost identical.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Elastic Collision}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In my elastic collision data you will find 12 runs (3 for each amount of extra mass). I analyzed runs 1, 4, 7, and 10 (corresponding to no extra mass, 100 g, 200 g, and 300 g). Here are some of the steps I followed to find my results, which are in table \ref{table.08.results.elastic}.

The two values for the velocity are scattered along the velocity column. With the velocity values you can compute the momentum values, and thus the change in momentum.

The force versus time graph has to be restricted to the region where the collision is happening. This region consist of the deep well in the middle of the graph. There seems to be small oscillations after the deep well, but these are due to the fact that after the cart leaves the spring, the spring vibrates due to its elasticity. These oscillations are not part of the collision.

In order to quantify the agreement between the two values of impulse found, you can compute a modified version of the percent difference. If $I_{1}$ corresponds to the value of impulse determined from the change in momentum, and $I_{2}$ corresponds to the value of impulse determined from the average force and the length of the time interval, then the percent difference is given by
\begin{equation}
    \text{percent difference } = 200 \times \left\vert \frac{I_{1} - I_{2}}{I_{1} + I_{2}} \right\vert
\end{equation}
(The long vertical lines mean taking the absolute value and thus ignoring the sign of the fraction inside). In my case, the percent difference was always below 2\%.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}
    \centering
    \begin{tabular}{|r|r|r|r|r|}\hline
        Extra mass & $\Delta p$ & Average $F$ & $\Delta t$ & Impulse \\ \hline
        0 kg & -0.339 kg m/s & -0.804 N & 0.430 s & -0.346 kg m/s \\
        0.1 kg & -0.357 kg m/s & -0.764 N & 0.476 s & -0.364 kg m/s \\
        0.2 kg & -0.528 kg m/s & -1.079 N & 0.496 s & -0.535 kg m/s \\
        0.3 kg & -0.570 kg m/s & -1.096 N & 0.528 s & -0.579 kg m/s \\
        \hline
    \end{tabular}
    \caption{Summary of results for the elastic collision}
    \label{table.08.results.elastic}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Inelastic Collision}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In the inelastic collisions, both the cart and the force sensor had a sticky clay attachment that enabled the cart to stick to the force sensor during the collision. Everyone has the same data, so I will not spoil the surprise. But the percent differences for the inelastic collision came out to be very small (see table \ref{table.08.results.inelastic}).

The velocity column for each inelastic collision has a single velocity measurement. This value corresponds to $v_{1}$. The velocity after the inelastic collision is zero.

There is a very important difference between the inelastic collisions and the elastic collisions: In the force versus time graph, after the initial deep well (which is deeper in the inelastic case than in the elastic case), there are peaks and wells that are significant in magnitude and cannot be regarded as noise. For example, the significant region in the force versus time graph for run 1 is in figure \ref{figure.08.run.1}. Beyond this region in time, there are further oscillations, but they are not large enough to be significant and are thus regarded as noise.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}
	\centering
    \begin{tabular}{|r|r|}\hline
        Extra mass & Percent difference \\ \hline
        0 kg & 0.355\% \\
        0.1 kg & 0.554\% \\
        0.2 kg & 0.408\% \\
        0.3 kg & 0.146\% \\
        \hline
    \end{tabular}
    \caption{Summary of results for the inelastic collision}
    \label{table.08.results.inelastic}
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}
    \centering
    \includegraphics[scale=0.71]{image/08-impulse/run1.png}
    \caption{}
    \label{figure.08.run.1}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Your Data}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
You collected data for elastic collisions. Everyone is going to use the same data for the inelastic case.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Your Lab Report}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
In your lab report you should include:
\begin{enumerate}
    \item A table like table \ref{table.08.results.elastic} for both the elastic and the inelastic collisions. Use these tables to answer the questions below.
    \item A table like table \ref{table.08.results.inelastic} for both the elastic and the inelastic collisions.
    \item How does the average force during the elastic collisions compare to the average force during the inelastic collision?
    \item How does the collision duration $\Delta t$ for the elastic collisions compare to the inelastic collisions?
\end{enumerate}