% This is part of the TFTB Reference Manual.
% Copyright (C) 1996 CNRS (France) and Rice University (US).
% See the file refguide.tex for copying conditions.

\markright{tfrsp}
\section*{\hspace*{-1.6cm} tfrsp}

\vspace*{-.4cm}
\hspace*{-1.6cm}\rule[0in]{16.5cm}{.02cm}
\vspace*{.2cm}

{\bf \large \sf Purpose}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
Spectrogram time-frequency distribution.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Synopsis}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
\begin{verbatim}
[tfr,t,f] = tfrsp(x)
[tfr,t,f] = tfrsp(x,t)
[tfr,t,f] = tfrsp(x,t,N)
[tfr,t,f] = tfrsp(x,t,N,h)
[tfr,t,f] = tfrsp(x,t,N,h,trace)
\end{verbatim}
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf Description}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
        {\ty tfrsp} computes the spectrogram distribution of a
        discrete-time signal {\ty x}. It corresponds to the squared modulus
        of the short-time Fourier transform. Its expression writes
\[S_x(t,\nu) = \left|\int_{-\infty}^{+\infty} x(u)\ h^*(u-t)\ e^{-j2\pi \nu
u}\ du\right|^2.\]

\hspace*{-.5cm}\begin{tabular*}{14cm}{p{1.5cm} p{8cm} c}
Name & Description & Default value\\
\hline
        {\ty x}     & analyzed signal ({\ty Nx=length(x)})\\
        {\ty t}     & time instant(s)          & {\ty (1:Nx)}\\
        {\ty N}     & number of frequency bins & {\ty Nx}\\
        {\ty h}     & smoothing window, {\ty h} being normalized so as to
                be  of unit energy.      & {\ty window(odd(N/4))}\\
        {\ty trace} & if nonzero, the progression of the algorithm is shown
                                         & {\ty 0}\\
     \hline {\ty tfr}   & time-frequency representation\\
        {\ty f}     & vector of normalized frequencies\\

\hline
\end{tabular*}
\vspace*{.2cm}

When called without output arguments, {\ty tfrsp} runs {\ty tfrqview}.
\end{minipage}
\vspace*{1cm}

{\bf \large \sf Example}
\begin{verbatim}
         sig=fmlin(128,0.1,0.4);
         h=window(17,'Kaiser');
         tfrsp(sig,1:128,64,h,1);
\end{verbatim}

\newpage

{\bf \large \sf See Also}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
all the {\ty tfr*} functions.
\end{minipage}
\vspace*{.5cm}

{\bf \large \sf References}\\
\hspace*{1.5cm}
\begin{minipage}[t]{13.5cm}
[1] W. Koenig, H. Dunn, L. Lacy ``The sound spectrograph'',
J. Acoust. Soc. Am., Vol. 18, No. 1, pp. 19-49, 1946.\\

[2] J. Allen, L. Rabiner ``A Unified Approach to Short-Time Fourier
Analysis and Synthesis'' Proc. IEEE, Vol. 65, No. 11, pp. 1558-64, 1977.
\end{minipage}


\documentclass[draft]{article}
%\usepackage[final]{graphics}
% final means "include the picture".  draft means "put a space with filename"
\usepackage[final]{graphicx}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
%\usepackage{showkeys}  %shows labels in margins see Gratzer p. 249
\setlength{\abovecaptionskip}{0pt}
\setlength{\parindent}{0cm} % no indent for paragraphs
\setlength{\parskip}{1.5ex} % more space between paragraphs.
\setlength{\textwidth}{7in} % width of text
\setlength{\oddsidemargin}{0pt}  % makes margin narrower
\title{Double Pendulum as Rigid Bodies}
\author{Erik Neumann\\
erikn@myphysicslab.com}
\date{April 2, 2011}
\begin{document}

\maketitle
%===============================================================
\section{Introduction}

This is a derivation of the equations of motion for a double pendulum where we regard the pendulums as rigid bodies.  In an alternate double pendulum model, the so-called ``ideal double pendulum'', the two pendulums are modelled as massless rods with a point mass at the end of each pendulum rod.  The present rigid body model of the double pendulum allows for more realistic configurations, because the pendulums can have any distribution of mass and can be connected together at any point.  The mass distribution is reflected in the rotational inertia of each pendulum.  By contrast in the ideal double pendulum model, the rotational inertia is zero for each pendulum and the connection must be at the end points of the massless rods.

\begin{figure}
    \centering
    \includegraphics[width=0.40 \textwidth]{Rigid_Double_Pendulum_fig_1.pdf}
    \caption{Rigid Body Double Pendulum Model} \label{fig_1}
\end{figure}

Please refer to figure \ref{fig_1} below.

Let $\mathbf{i}$ be the unit vector along the $x$ axis, and let $\mathbf{j}$ be the unit vector along the $y$ axis.  We regard $y$ as increasing upwards (this is the usual mathematical convention, as opposed to computer graphics systems which often have $y$ increasing downwards).

The fixed pivot, which we name pivot 1, is at location $\mathbf{P_1}$.  Pivot 2 is the moving pivot point connecting the two pendulums at location $\mathbf{P_2}$.

Let pendulum 1 be the upper pendulum.  It is connected to a fixed location at pivot 1, and connected to the lower pendulum at pivot 2.\\
Let $\mathbf{X_1} = x_1 \mathbf{i} + y_1 \mathbf{j}$ be the location of the center of mass of pendulum 1.\\
Let $\mathbf{R_1}$ be the vector from pivot 1 to the center of mass of pendulum 1, with length $R_1$.\\
Let $\theta_1$ be the angle at pivot 1 between $\mathbf{R_1}$ and the downward vertical position.\\
Let $\mathbf{L_1}$ be the vector from pivot 1 to pivot 2, with length $L_1$.\\
Let $\phi$ be the angle from vector $\mathbf{R_1}$ to $\mathbf{L_1}$.  Note that $\phi$ is a constant.

Let pendulum 2 be the lower pendulum.  It is connected to the upper pendulum at pivot 2.\\
Let $\mathbf{X_2} = x_2 \mathbf{i} + y_2 \mathbf{j}$ be the location of the center of mass of pendulum 2.\\
Let $\mathbf{R_2}$ be the vector from pivot 2 to the center of mass of pendulum 2, with length $R_2$.\\
Let $\theta_2$ be the angle at pivot 2 between $\mathbf{R_2}$ and the downward vertical position.

Let $m_1$, $m_2$ be the mass of pendulum 1 and 2 respectively.\\
Let $I_1$, $I_2$ be the rotational inertia about the center of mass of pendulum 1 and 2 respectively.

%===============================================================
\section{Kinematics}
We have the following relationships just from the geometry of the double pendulum, without using any information about forces.
\[
\mathbf{R_1} = R_1 \sin(\theta_1) \mathbf{i} - R_1 \cos(\theta_1) \mathbf{j}
\]
\[
\mathbf{R_2} = R_2 \sin(\theta_2) \mathbf{i} - R_2 \cos(\theta_2) \mathbf{j}
\]
\[
\mathbf{L_1} = L_1 \sin(\theta_1+\phi) \mathbf{i} - L_1 \cos(\theta_1+\phi) \mathbf{j}
\]

\[
\mathbf{X_1} = \mathbf{R_1}
\]
\[
x_1 = R_1 \sin(\theta_1)
\]
\[
y_1 = -R_1 \cos(\theta_1)
\]
\[
\mathbf{X_2} = \mathbf{L_1} + \mathbf{R_2}
\]
\[
x_2 = L_1 \sin(\theta_1+\phi) + R_2 \sin(\theta_2)
\]
\[
y_2 = -L_1 \cos(\theta_1+\phi) - R_2 \cos(\theta_2)
\]

Take the first derivative with respect to time to get velocity.

\[
\mathbf{X_1'} = \mathbf{R_1'}
\]
\[
x_1' = \theta_1' R_1 \cos(\theta_1)
\]
\[
y_1' = \theta_1' R_1 \sin(\theta_1)
\]
\[
\mathbf{X_2'} = \mathbf{L_1'} + \mathbf{R_2'}
\]
\[
x_2' = \theta_1' L_1 \cos(\theta_1+\phi) + \theta_2' R_2 \cos(\theta_2)
\]
\[
y_2' = \theta_1' L_1 \sin(\theta_1+\phi) + \theta_2' R_2 \sin(\theta_2)
\]

Take the second derivative with respect to time to get acceleration.

\[
\mathbf{X_1''} = \mathbf{R_1''}
\]
\begin{equation}\label{E01}
x_1'' = -\theta_1'^2 R_1 \sin(\theta_1) + \theta_1'' R_1 \cos(\theta_1)
\end{equation}
\begin{equation}\label{E02}
y_1'' = \theta_1'^2 R_1 \cos(\theta_1) + \theta_1'' R_1 \sin(\theta_1)
\end{equation}
\[
\mathbf{X_2''} = \mathbf{L_1''} + \mathbf{R_2''}
\]
\begin{equation}\label{E1}
x_2'' = -\theta_1'^2 L_1 \sin(\theta_1+\phi) + \theta_1'' L_1 \cos(\theta_1+\phi)
- \theta_2'^2 R_2 \sin(\theta_2) + \theta_2'' R_2 \cos(\theta_2)
\end{equation}
\begin{equation}\label{E2}
y_2'' = \theta_1'^2 L_1 \cos(\theta_1+\phi) + \theta_1'' L_1 \sin(\theta_1+\phi)
+ \theta_2'^2 R_2 \cos(\theta_2) + \theta_2'' R_2 \sin(\theta_2)
\end{equation}

%===============================================================
\section{Forces}

Let $\mathbf{T_1} = T_{1x} \mathbf{i} + T_{1y} \mathbf{j}$ be the force vector operating on pendulum 1 at pivot 1.\\
Let $\mathbf{T_2} = T_{2x} \mathbf{i} + T_{2y} \mathbf{j}$ be the force vector operating on pendulum 1 at pivot 2.
Then by Newton's law of equal and opposite reaction, $-\mathbf{T_2}$ is the force vector operating on pendulum 2 at pivot 2.

From Newton's laws of motion we can write the following force equations:
\[
m_1 \mathbf{X_1}'' = \mathbf{T_1} + \mathbf{T_2} - m_1 g \mathbf{j}
\]
\begin{equation}\label{E3}
m_1 x_1'' = T_{1x} + T_{2x}
\end{equation}
\begin{equation}\label{E4}
m_1 y_1'' = T_{1y} + T_{2y} - m_1 g
\end{equation}
\begin{multline}\label{E5}
  I_1 \theta_1'' = (-\mathbf{R_1}) \times \mathbf{T_1} + (\mathbf{L_1 - R_1}) \times \mathbf{T_2} \\
  = -(R_1 \sin(\theta_1) T_{1y} + R_1 \cos(\theta_1) T_{1x}) \\
  + (L_1 \sin(\theta_1+\phi)- R_1 \sin(\theta_1))  T_{2y}
  + (L_1 \cos(\theta_1+\phi) - R_1 \cos(\theta_1)) T_{2x}
\end{multline}
\[
m_2 \mathbf{X_2}'' = -\mathbf{T_2} - m_2 g \mathbf{j}
\]
\begin{equation}\label{E6}
m_2 x_2'' = -T_{2x}
\end{equation}
\begin{equation}\label{E7}
m_2 y_2'' = -T_{2y} - m_2 g
\end{equation}
\begin{equation}\label{E8}
  I_2 \theta_2'' = (-\mathbf{R_2}) \times (-\mathbf{T_2})
  = R_2 \sin(\theta_2) T_{2y} + R_2 \cos(\theta_2) T_{2x}
\end{equation}

To derive these force equations we used Newton's law of motion $\mathbf{F} = m \mathbf{a}$ and the rotational version for angular torque $I \theta'' = \tau$.  For more about how to calculate the torque see \texttt{http://www.myphysicslab.com/collision.html}.

%===============================================================
\section{Equations of Motion}

Substitute the four equations (\ref{E01}) thru (\ref{E2}) into the six equations (\ref{E3}) thru (\ref{E8}) to eliminate the unknowns $x_1''$, $y_1''$, $x_2''$, $y_2''$.  This gives us modified versions of the six equations (\ref{E3}) thru (\ref{E8}) with  six unknowns: $T_{1x}$, $T_{2x}$,  $T_{1y}$, $T_{2y}$, $\theta_1''$,  $\theta_2''$.  We then solve for $\theta_1''$, $\theta_2''$ and eliminate the other four unknowns.  See the accompanying Mathematica notebook \texttt{Rigid\_Double\_Pendulum\_Algebra.nb} for the calculations.

\small
\begin{multline}
\theta_1'' = -\Big(2 g m_1 R_1 (I_2 + m_2 R_2^2) \sin(\theta_1) + L_1 m_2 \Big(g (2 I_2 + m_2 R_2^2) \sin(\theta_1 + \phi) + \\
R_2 \Big(g m_2 R_2 \sin(\theta_1 - 2 \theta_2 + \phi) + 2 (\theta_2'^2 (I_2 + m_2 R_2^2) +
\theta_1'^2 L_1 m_2 R_2 \cos(\theta_1 - \theta_2 + \phi)) \sin(\theta_1 - \theta_2 + \phi)
\Big)\Big)\Big)\\
\Big/
\Big(2 I_2 L_1^2 m_2 + 2 I_2 m_1 R_1^2 +
L_1^2 m_2^2 R_2^2 + 2 m_1 m_2 R_1^2 R_2^2 + 2 I_1 (I_2 + m_2 R_2^2) -
L_1^2 m_2^2 R_2^2 \cos(2 (\theta_1 - \theta_2 + \phi))\Big)
\end{multline}

\begin{multline}
\theta_2'' = \Big(m_2 R_2 \Big(-(g (2 I_1 + L_1^2 m_2 + 2 m_1 R_1^2) \sin(\theta_2)) + \\
L_1 \Big(g m_1 R_1 \sin(\theta_2 - \phi) + 2 \theta_1'^2 (I_1 + L_1^2 m_2 + m_1 R_1^2) \sin(\theta_1 - \theta_2 + \phi) + \\
\theta_2'^2 L_1 m_2 R_2 \sin(2 (\theta_1 - \theta_2 + \phi)) + g m_1 R_1 \sin(2 \theta_1 - \theta_2 + \phi) +
g L_1 m_2 \sin(2 \theta_1 - \theta_2 + 2 \phi)\Big)\Big)\Big)\\
\Big/
\Big(2 I_2 L_1^2 m_2 + 2 I_2 m_1 R_1^2 + L_1^2 m_2^2 R_2^2 +
2 m_1 m_2 R_1^2 R_2^2 + 2 I_1 (I_2 + m_2 R_2^2) - L_1^2 m_2^2 R_2^2 \cos(2 (\theta_1 - \theta_2 + \phi))\Big)
\end{multline}

Do these equations match the ideal double pendulum equations? Yes.

In the ideal double pendulum there are two point masses at the end of each pendulum.  This corresponds to setting $L_1=R_1$, $\phi=0$, and having rotational inertia be zero for both pendulums.  If we substitute these values into the above equations, we do indeed get the ideal double pendulum equations (see the Mathematica document).

\end{document}


\documentclass[11pt]{article}
\usepackage{natbib,unatbib}
\usepackage[nohide,twocolumn]{ulecnot}

\usepackage{bussproofs}

\pagestyle{fancy}
\lhead{COGS 502 -- Programming and Logic}
\chead{$\lambda$-Calculus}
\rhead{Updated \it \today}
\lfoot{Umut \"Ozge}
\cfoot{}
\rfoot{Page \thepage/\pageref{LastPage}}
\setlength{\headheight}{13.6pt}

\usepackage{tikz-qtree}

\begin{document}

%\section{Lambda operator, bondage, freedom, substitution}
\section{Expressions}

\ezimeti{

\item Our basic notions here are \uterm{expression} and \uterm{evaluation}.

\begin{udefinition}[Expression]
Let $A=\{ a,b,\ldots,z\}$ be the set of names.
\begin{itemize}
\item[i.] all names are expressions;
\item[ii.] if $\omega_1$ and $\omega_2$ are expressions, so is $(\omega_1\omega_2)$;
\item[iii.] if $\omega$ is an expression and $\alpha$ is a name, then
$(\lambda\alpha.\omega)$ is an expression.
\item[iv.] nothing else is an expression.
\end{itemize}
\end{udefinition}

\item Some example expressions:
\renewcommand{\arraycolsep}{6pt}
\renewcommand{\arraystretch}{2}

$$
\begin{array}{cccc}
x & (xy) & (x(yz))  & ((xy)z) \\
(\lambda x.x) & (\lambda y.(\lambda x.x)) & (\lambda z.(x(\lambda y.(yz)))) &
(x(\lambda z.(\lambda y.(yz))))\\
x(\lambda x.x) & (\lambda y.(\lambda x.x))(\lambda x.x) & (\lambda y.(\lambda x.x))(\lambda x.x)(xy)& (x(yz))((xy)z)
\end{array}
$$

\item Note that in lambda calculus we write $f x$ rather than the usual $f(x)$
to represent the application of function $f$ to the argument $x$.

\item[] {\bf Notational conventions:}

\ezimeti{
\item[i.] Omit the outermost parentheses:

$$
\begin{array}{cccc}
x & xy & x(yz)  & (xy)z \\
\lambda x.x & \lambda y.(\lambda x.x) & \lambda z.(x(\lambda y.(yz))) & x(\lambda z.(\lambda y.(yz)))
\end{array}
$$

\item[ii.] Parentheses associate to left:

\begin{align*}
fxyz & \equiv (((fx)y)z)
\end{align*}

\item[iii.] Stacked lambdas:
\begin{align*}
(\lambda f.(\lambda x.(f(fx))))  &\equiv \lambda f \lambda x.(f(fx)) \\
& \equiv \lambda f x.(f(fx))
\end{align*}
}

\item The notions of bondage, freedom and substitution we covered in predicate
logic apply here as well.

\section{$\beta$-reduction}

\item An expression of the form $(\lambda \alpha.\gamma)\omega$ is called a
\uterm{$\beta$-redex}.

\item It can be \uterm{$\beta$-reduced} to $\subs{\gamma}{\omega}{\alpha}$,
called a \uterm{reduct}, if $\omega$ is free for $\alpha$ in $\gamma$.

\item  A lambda expression can be reduced by turning all the redexes to reducts,
which results in a \uterm{$\beta$-normal} form.

\item Some example reductions:
\begin{align*}
(\lambda f.fx)g  & \breduce gx \\
(\lambda f.fx)ga  & \breduce gxa \\
(\lambda f.fx)(ga) & \breduce gax \\
(\lambda f\lambda x.fx)g a & \breduce ga \\
%(\lambda x\lambda y \lambda z.x(yz))f & \breduce \\
\end{align*}

\item There may be more than one redex in a
expression:

\begin{align*}
(\lambda x.y)((\lambda z.zz)(\lambda w.w)) & \breduce (\lambda x.y)((\lambda w.w)(\lambda w.w))\\
											& \breduce (\lambda x.y)(\lambda w.w)
											& \breduce y
\end{align*}

\item Another reduction of the same expression would be:

\begin{align*}
(\lambda x.y)((\lambda z.zz)(\lambda w.w)) & \breduce y
\end{align*}

\item The first is called the \uterm{applicative order} reduction; the second is
called the \uterm{normal order} reduction.

\item Reduce the following expressions:
\begin{align*}
(\lambda x. m x)j\\
(\lambda y. y j)m\\
(\lambda x.\lambda y. y(y x))jm\\
(\lambda y.y j)(\lambda x. m x)\\
(\lambda x. xx)(\lambda y. yyy)
\end{align*}

% \item Reduce the following expression in both applicative and normal order:
%
% \begin{align*}
% (\lambda p_1\lambda p_2. p_1 0 \land p_2)(\lambda x. x\not= 0)((\lambda y.\frac{5}{y} = 0)0)
% \end{align*}

}
\section{Lambda calculus in action: some examples}

\subsection{Logic}
\ezimeti{
\item Let's define the truth values:

\begin{align*}
\combf{T} \equiv \lambda x\lambda y.x\\
\combf{F} \equiv \lambda x\lambda y.y
\end{align*}

\item Verify that $\lambda x\lambda y.yxy$ behaves like \emph{and} in prefix
notation (i.e. $\land p q$).

\item Can you think of lambda expressions for $\lor$ and $-$?
\item What about an if-then-else function that applies to the test, a function
to execute if the test is true and a function to execute if the test is false.

}
\subsection{Arithmetic}

\ezimeti{

\item Number can be represented as lambda expressions in the following way:
\begin{align*}
0 & \equiv \lambda f\lambda x.x\\
1 & \equiv \lambda f\lambda x.fx\\
2 & \equiv \lambda f\lambda x.f(fx)\\
3 & \equiv \lambda f\lambda x.f(f(fx))\\
\vdots
\end{align*}

\item A successor function which returns $n+1$ given $n$ is:
\begin{align*}
\mathbf{S}\equiv \lambda a\lambda f\lambda x. f(afx)
\end{align*}

\item Here are addition and multiplication (again in prefix notation); verify
that they do what they are meant to do.

\begin{align*}
\mathbf{+} & \equiv \lambda a\lambda b\lambda f\lambda x.af(bfx)\\
\mathbf{\times} & \equiv \lambda a\lambda b\lambda f.a(bf)
\end{align*}

}

\end{document}


% Part: first-order-logic
% Chapter: model-theory
% Section: reducts-and-expansions

\documentclass[../../../include/open-logic-section]{subfiles}

\begin{document}

\olfileid{mod}{bas}{red}
\section{Reducts and Expansions}

Often it is useful or necessary to compare languages which have
symbols in common, as well as !!{structure}s for these languages.  The
most comon case is when all the symbols in !!a{language}~$\Lang{L}$
are also part of !!a{language}~$\Lang{L'}$, i.e., $\Lang{L} \subseteq
\Lang{L'}$. An $\Lang{L}$-!!{structure}~$\Struct{M}$ can then always
be expanded to an $\Lang{L'}$-!!{structure} by adding interpretations
of the additional symbols while leaving the interpretations of the
common symbols the same.  On the other hand, from an
$\Lang{L'}$-structure~$\Struct{M'}$ we can obtain an
$\Lang{L}$-structure simpy by ``forgetting'' the interpretations of
the symbols that do not occur in~$\Lang{L}$.

\begin{defn}
\ollabel{defn:reduct}
Suppose $\Lang L \subseteq \Lang L'$, $\Struct M$ is an
$\Lang L$-!!{structure} and $\Struct M'$ is an $\Lang L'$-!!{structure}.
$\Struct M$ is the \emph{reduct} of $\Struct M'$ to $\Lang L$, and
$\Struct M'$ is an \emph{expansion} of $\Struct M$ to $\Lang L'$ iff
\begin{enumerate}
\item $\Domain{M} = \Domain{M'}$
\item For every !!{constant}~$c \in \Lang L$, $\Assign{c}{M} =
  \Assign{c}{M'}$.
\item For every !!{function}~$f \in \Lang L$, $\Assign{f}{M} =
  \Assign{f}{M'}$.
\item For every !!{predicate}~$P \in \Lang L$, $\Assign{P}{M} =
  \Assign{P}{M'}$.
\end{enumerate}
\end{defn}

\begin{prop}
\ollabel{prop:reduct}
If an $\Lang{L}$-!!{structure}~$\Struct{M}$ is a reduct of an
$\Lang{L'}$-!!{structure} $\Struct{M'}$, then for all
$\Lang{L}$-!!{sentence}s~$!A$,
\[
\Sat{M}{!A} \text{ iff } \Sat{M'}{!A}.
\]
\end{prop}

\begin{proof}
  Exercise.
\end{proof}

\begin{prob}
Prove \olref[mod][bas][red]{prop:reduct}.
\end{prob}

\begin{defn}
When we have an $\Lang{L}$-structure $\Struct{M}$, and $\Lang{L'} =
\Lang{L} \cup \{P\}$ is the expansion of $\Lang{L}$ obtained by adding
a single $n$-place !!{predicate}~$P$, and $R \subseteq \Domain{M}^n$
is an $n$-place relation, then we write $\Expan{M}{R}$ for the
expansion~$\Struct{M'}$ of~$\Struct{M}$ with $\Assign{P}{M'} = R$.
\end{defn}

\end{document}


\chapter{Fundamental groups}
Topologists can't tell the difference between a coffee cup and a doughnut.
So how do you tell \emph{anything} apart?

This is a very hard question to answer, but one way we can
try to answer it is to find some \emph{invariants} of the space.
To draw on the group analogy, two groups are clearly not isomorphic if,
say, they have different orders, or if one is simple and the other isn't, etc.
We'd like to find some similar properties for topological spaces
so that we can actually tell them apart.

Two such invariants for a space $X$ are
\begin{itemize}
	\ii Defining homology groups $H_1(X)$, $H_2(X)$, \dots
	\ii Defining homotopy groups $\pi_1(X)$, $\pi_2(X)$, \dots
\end{itemize}
Homology groups are hard to define, but in general easier to compute.
Homotopy groups are easier to define but harder to compute.

This chapter is about the fundamental group $\pi_1$.

\section{Fusing paths together}
Recall that a \emph{path} in a space $X$ is a function $[0,1] \to X$.
Suppose we have paths $\gamma_1$ and $\gamma_2$
such that $\gamma_1(1) = \gamma_2(0)$.
We'd like to fuse\footnote{%
	Almost everyone else in the world uses ``gluing'' to describe this
	and other types of constructs.
	But I was traumatized by Elmer's glue when I was in high school
	because I hated the stupid ``make a poster'' projects and hated
	having to use glue on them.
	So I refuse to talk about ``gluing'' paths together, referring
	instead to ``fusing'' them together, which sounds cooler anyways.
} them together to get a path $\gamma_1 \ast \gamma_2$.  Easy, right?

\begin{center}
	\begin{asy}
		size(8cm);
		bigblob("$X$");
		pair A = Drawing("\gamma_1(0)", (-3,-1));
		pair B = Drawing("\gamma_1(1) = \gamma_2(0)", (1,1), dir(90));
		pair C = Drawing("\gamma_2(1)", (2,-2), dir(-90));
		path p = A..(-2,0)..(0,0.5)..B;
		path q = B..(1.8,-0.5)..C;
		draw(p, red, EndArrow);
		draw(q, blue, EndArrow);
		MP("\gamma_1", midpoint(p), dir(90));
		MP("\gamma_2", midpoint(q), dir(0));
	\end{asy}
\end{center}

We unfortunately do have to hack the definition a tiny bit. In an ideal world, we'd have a path $\gamma_1 : [0,1] \to X$ and $\gamma_2 : [1,2] \to X$ and we could just merge them together to get $\gamma_1 \ast \gamma_2 : [0,2] \to X$.
But the ``$2$'' is wrong here.
The solution is that we allocate $[0, \half]$ for the first path
and $[\half, 1]$ for the second path; we run ``twice as fast''.

\begin{definition}
	Given two paths $\gamma_1, \gamma_2 : [0,1] \to X$
	such that $\gamma_1(1) = \gamma_2(0)$, we define
	a path $\gamma_1 \ast \gamma_2 : [0,1] \to X$ by
	\[
		(\gamma_1 \ast \gamma_2)(t)
		=
		\begin{cases}
			\gamma_1(2t) & 0 \le t \le \half \\
			\gamma_2(2t-1) & \half \le t \le 1.
		\end{cases}
		\]
\end{definition}

This hack unfortunately reveals a second shortcoming: this ``product'' is not associative.
If we take $(\gamma_1 \ast \gamma_2) \ast \gamma_3$ for some suitable paths,
then $[0, \frac14]$, $[\frac14, \frac12]$ and $[\frac12, 1]$
are the times allocated for $\gamma_1$, $\gamma_2$, $\gamma_3$.
\begin{ques}
	What are the times allocated
	for $\gamma_1 \ast (\gamma_2 \ast \gamma_3)$?
\end{ques}
But I hope you'll agree that even though this operation isn't associative,
the reason it fails to be associative is kind of stupid.
It's just a matter of how fast we run in certain parts.

\begin{center}
	\begin{asy}
		unitsize(6cm);
		Drawing( unitsquare);
		MP("0", (0,0), S);
		MP("1", (1,0), S);
		MP("\frac{1}{4}", (1/4, 0), S);
		MP("\frac{1}{2}", (1/2, 0), S);
		MP("0", (0,1), N);
		MP("1", (1,1), N);
		MP("\frac{3}{4}", (3/4, 1), N);
		MP("\frac{1}{2}", (1/2, 1), N);
		MP("\gamma_1", (1/8, 0), N);
		MP("\gamma_2", (3/8, 0), N);
		MP("\gamma_3", (3/4, 0), N);
		MP("\gamma_1", (1/4, 1), S);
		MP("\gamma_2", (5/8, 1), S);
		MP("\gamma_3", (7/8, 1), S);

		MP("\boxed{\gamma_1 \ast \left( \gamma_2 \ast \gamma_3 \right)}", (0.5,1.2), origin);
		MP("\boxed{\left( \gamma_1 \ast \gamma_2 \right) \ast \gamma_3}", (0.5,-0.2), origin);

		Drawing((1/4,0)--(1/2,1), blue);
		Drawing((1/2,0)--(3/4,1), blue);
		Drawing( (1/2,0)--(1/2,1), dotted);
	\end{asy}
\end{center}

So as long as we're fusing paths together,
we probably don't want to think of $[0,1]$ itself too seriously.
And so we only consider everything up to (path) homotopy equivalence.
(Recall that two paths $\alpha$ and $\beta$ are homotopic if
there's a path homotopy $F : [0,1]^2 \to X$ between them,
which is a continuous deformation from $\alpha$ to $\beta$.)
It is definitely true that
\[
	\left( \gamma_1 \ast \gamma_2 \right) \ast \gamma_3
	\simeq
	\gamma_1 \ast \left( \gamma_2 \ast \gamma_3 \right) . \]
It is also true that if $\alpha_1 \simeq \alpha_2$ and $\beta_1 \simeq \beta_2$
then $\alpha_1 \ast \beta_1 \simeq \alpha_2 \ast \beta_2$.

Naturally, homotopy is an equivalence relation,
so paths $\gamma$ lives in some ``homotopy type'',
the equivalence classes under $\simeq$. We'll denote this $[\gamma]$.
Then it makes sense to talk about $[\alpha] \ast [\beta]$.
Thus, \textbf{we can think of $\ast$ as an operation on homotopy classes}.

\section{Fundamental groups}
\prototype{$\pi_1(\RR^2)$ is trivial and $\pi_1(S^1) \cong \ZZ$.}

At this point I'm a little annoyed at keeping track of endpoints,
so now I'm going to specialize to a certain type of path.
\begin{definition}
	A \vocab{loop} is a path with $\gamma(0) = \gamma(1)$.
\end{definition}
\begin{center}
	\begin{asy}
		bigblob("$X$");
		pair A = Drawing("x_0", (-1,0), dir(100));
		path p = A..(1,1)..(2,0)..(0.5,-1)..(-1.5,-0.5)..cycle;
		draw(p, blue, EndArrow);
		MP("\gamma", midpoint(p), dir(-20));
	\end{asy}
\end{center}

Hence if we restrict our attention to paths starting at a single point $x_0$,
then we can stop caring about endpoints and start-points, since
everything starts and stops at $x_0$.
We even have a very canonical loop: the ``do-nothing'' loop\footnote{Fatty.} given by standing at $x_0$ the whole time.

\begin{definition}
	Denote the trivial ``do-nothing loop'' by $1$.
	A loop $\gamma$ is \vocab{nulhomotopic} if it is homotopic to $1$; i.e.\ $\gamma \simeq 1$.
\end{definition}

For homotopy of loops, you might visualize ``reeling in'' the loop, contracting it to a single point.

\begin{example}[Loops in $S^2$ are nulhomotopic]
	As the following picture should convince you, every loop in
	the simply connected space $S^2$ is nulhomotopic.
	\begin{center}
		\includegraphics[width=6cm]{media/S2-simply.png}
	\end{center}
	(Starting with the purple loop, we contract to the red-brown point.)
\end{example}

Hence to show that spaces are simply connected it suffices to understand
the loops of that space.
We are now ready to provide:
\begin{definition}
	The \vocab{fundamental group} of $X$ with basepoint $x_0$,
	denoted $\pi_1(X, x_0)$, is the set of homotopy classes
	\[ \left\{ [\gamma] \mid \gamma \text{ a loop at $x_0$} \right\} \]
	equipped with $\ast$ as a group operation.
\end{definition}

It might come as a surprise that this has a group structure.
For example, what is the inverse?
Let's define it now.
\begin{definition}
	Given a path $\alpha : [0,1] \to X$ we can define a path $\ol\alpha$
	\[ \ol\alpha (t) = \alpha(1-t). \]
	In effect, this ``runs $\alpha$ backwards''.
	Note that $\ol\alpha$ starts at the endpoint of $\alpha$
	and ends at the starting point of $\alpha$.
\end{definition}
\begin{exercise}
	Show that for any path $\alpha$,
	$\alpha \ast \ol\alpha$ is homotopic
	to the ``do-nothing'' loop at $\alpha(0)$.
	(Draw a picture.)
\end{exercise}

Let's check it.
\begin{proof}
	[Proof that this is a group structure]
	Clearly $\ast$ takes two loops at $x_0$ and spits out a loop at $x_0$.
	We also already took the time to show that $\ast$ is associative.
	So we only have to check that (i) there's an identity, and (ii)
	there's an inverse.
	\begin{itemize}
		\ii We claim that the identity is the ``do-nothing'' loop $1$
		we described above. The reader can check that for any $\gamma$,
		\[ \gamma \simeq \gamma \ast 1 = 1 \ast \gamma. \]
		\ii For a loop $\gamma$, recall again we define its ``backwards'' loop $\ol\gamma$ by
		\[ \ol\gamma(t) = \gamma(1-t). \]
		Then we have $\gamma \ast \ol\gamma = \ol\gamma \ast \gamma = 1$.
	\end{itemize}
	Hence $\pi_1(X,x_0)$ is actually a group.
\end{proof}

Before going any further I had better give some examples.
\begin{example}
	[Examples of fundamental groups]
	Note that proving the following results is not at all trivial.
	For now, just try to see intuitively why the claimed answer ``should'' be correct.
	\begin{enumerate}[(a)]
		\ii The fundamental group of $\CC$ is the
		trivial group: in the plane, every loop is nulhomotopic.
		(Proof: imagine it's a piece of rope and reel it in.)
		\ii On the other hand, the fundamental group of $\CC - \{0\}$
		(meteor example from earlier) with any base point is actually $\ZZ$!
		We won't be able to prove this for a while,
		but essentially a loop is determined by the number of times
		that it winds around the origin -- these are so-called
		\emph{winding numbers}.  Think about it!
		\ii Similarly, we will soon show that the fundamental group of $S^1$
		(the boundary of the unit circle) is $\ZZ$.
	\end{enumerate}
	Officially, I also have to tell you what the base point is, but
	by symmetry in these examples, it doesn't matter.
\end{example}
Here is the picture for $\CC \setminus \{0\}$, with the hole exaggerated
as the meteor from \Cref{sec:meteor}.
\begin{center}
	\begin{asy}
		size(6cm);
		bigbox("$\mathbb C \setminus \{0\}$");
		filldraw(scale(0.5)*unitcircle, grey, black);
		dot("$x_0$", (1.4,0), dir(0));
		draw( (1.4,0)..(0,1.4)..(-1.4,0)..(1.4*dir(-30))..cycle, blue, EndArrow );
	\end{asy}
\end{center}

\begin{ques}
	Convince yourself that the fundamental group of $S^1$ is $\ZZ$,
	and understand why we call these ``winding numbers''.
	(This will be the most important example of a fundamental group
	in later chapters, so it's crucial you figure it out now.)
\end{ques}

\begin{example}
	[The figure eight]
	\label{ex:figure8}
	Consider a figure eight $S^1 \vee S^1$, and let $x_0$
	be the center.
	Then  \[\pi_1(S^1 \vee S^1, x_0) \cong \left<a,b\right> \]
	is the \emph{free group} generated on two letters.
	The idea is that one loop of the eight is $a$,
	and the other loop is $b$, so we expect $\pi_1$
	to be generated by this loop $a$ and $b$ (and its inverses
	$\ol a$ and $\ol b$).
	These loops don't talk to each other.
	\begin{center}
		\begin{asy}
			draw( shift( (1,0) ) * unitcircle, grey + 5 );
			draw( shift( (-1,0) ) * unitcircle, grey + 5 );
			dot(origin);
			path g = dir(20)..dir(100)..dir(180)..dir(260)..dir(340);
			draw( shift( (1,0) ) * scale(0.8) * reflect(dir(90),dir(-90)) * g, blue, EndArrow );
			draw( shift( (-1,0) ) * scale(0.8) * g, red, EndArrow );
			label("$a$", (-1.6,0), dir(0));
			label("$b$", (1.6,0), dir(180));
		\end{asy}
	\end{center}
\end{example}

Recall that in graph theory, we usually assume our graphs are connected,
since otherwise we can just consider every connected component separately.
Likewise, we generally want to restrict our attention to path-connected spaces, since if a space isn't path-connected then it can be broken into a bunch of ``path-connected components''.
(Can you guess how to define this?)
Indeed, you could imagine a space $X$ that consists of the objects on my desk (but not the desk itself): $\pi_1$ of my phone has nothing to do with $\pi_1$ of my mug. They are just totally disconnected, both figuratively and literally.

But on the other hand we claim that in a path-connected space,
the groups are very related!
\begin{theorem}[Fundamental groups don't depend on basepoint]
	Let $X$ be a path-connected space.
	Then for any $x_1 \in X$ and $x_2 \in X$, we have
	\[ \pi_1(X, x_1) \cong \pi_1(X, x_2). \]
\end{theorem}
Before you read the proof, see if you can guess the isomorphism based just on the picture below.
\begin{center}
	\begin{asy}
		size(7cm);
		bigblob("$X$");
		pair A = Drawing("x_1", (-1.5,0), dir(180));
		pair B = Drawing("x_2", (1.5,0), dir(0));
		draw(A..(-2.5,-0.8)..(-2.5,0.9)..cycle, blue);
		draw(B..(2.2,-1.1)..(2.4,0.8)..cycle, blue);
		draw(A--B, red+dashed, Arrows);
		label("$\alpha$/$\overline{\alpha}$", origin, dir(90));
	\end{asy}
\end{center}
\begin{proof}
	Let $\alpha$ be any path from $x_1$ to $x_2$ (possible by path-connectedness), and let $\ol\alpha$ be its reverse.
	Then we can construct a map
	\[
		\pi_1(X,x_1) \to \pi_1(X,x_2)
		\text{ by }
		[\gamma] \mapsto [\ol\alpha \ast \gamma \ast \alpha]. \]
	In other words, given a loop $\gamma$ at $x_1$,
	we can start at $x_2$, follow $\ol\alpha$ to $x_1$,
	run $\gamma$, then run along $\alpha$ home to $x_2$.
	Hence this is a map which builds a loop of $\pi_1(X, x_2)$
	from every loop at $\pi_1(X, x_1)$.
	It is a \emph{homomorphism} of the groups just because
	\[ \left( \ol \alpha \ast \gamma_1 \ast \alpha \right)
		\ast \left( \ol\alpha \ast \gamma_2 \ast \alpha \right)
		= \ol\alpha \ast \gamma_1 \ast \gamma_2 \ast \alpha \]
	as $\alpha \ast \ol\alpha$ is nulhomotopic.

	Similarly, there is a homomorphism
	\[
		\pi_1(X,x_2) \to \pi_1(X,x_1)
		\text{ by }
		[\gamma] \mapsto [\alpha \ast \gamma \ast \ol\alpha]. \]
	As these maps are mutual inverses, it follows
	they must be isomorphisms. End of story.
\end{proof}
This is a bigger reason why we usually only care about path-connected spaces.

\begin{abuse}
	For a path-connected space $X$ we will often abbreviate $\pi_1(X, x_0)$
	to just $\pi_1(X)$, since it doesn't matter which $x_0 \in X$
	we pick.
\end{abuse}

Finally, recall that we originally defined ``simply connected'' as saying
that any two paths with matching endpoints were homotopic.
It's possible to weaken this condition and then rephrase it using
fundamental groups.
\begin{exercise}
	Let $X$ be a path-connected space.
	Prove that $X$ is \vocab{simply connected} if and only if
	$\pi_1(X)$ is the trivial group.
	(One direction is easy; the other is a little trickier.)
\end{exercise}
This is the ``usual'' definition of simply connected.

\section{Fundamental groups are functorial}
One quick shorthand I will introduce to clean up the discussion:
\begin{definition}
	By $f : (X, x_0) \to (Y, y_0)$, we will mean that
	$f : X \to Y$ is a continuous function of spaces
	which also sends the point $x_0$ to $y_0$.
\end{definition}

Let $X$ and $Y$ be topological spaces and $f : (X, x_0) \to (Y, y_0)$.
We now want to relate the fundamental groups of $X$ and $Y$.

Recall that a loop $\gamma$ in $(X, x_0)$ is a map $\gamma : [0,1] \to X$
with $\gamma(0) = \gamma(1) = x_0$.
Then if we consider the composition
\[ [0,1] \taking\gamma (X, x_0) \taking f (Y, y_0) \]
then we get straight-away a loop in $Y$ at $y_0$!
Let's call this loop $f_\sharp \gamma$.
\begin{lemma}[$f_\sharp$ is homotopy invariant]
	\label{lem:fsharp_homotopy_invariant}
	If $\gamma_1 \simeq \gamma_2$ are path-homotopic,
	then in fact
	\[ f_\sharp \gamma_1 \simeq f_\sharp \gamma_2. \]
\end{lemma}
\begin{proof}
	Just take the homotopy $h$ taking $\gamma_1$ to $\gamma_2$
	and consider $f \circ h$.
\end{proof}

It's worth noting at this point that if $X$ and $Y$ are homeomorphic,
then their fundamental groups are all isomorphic.
Indeed, let $f : X \to Y$ and $g : Y \to X$ be mutually inverse continuous maps.
Then one can check that $f_\sharp : \pi_1(X, x_0) \to \pi_1(Y, y_0)$
and $g_\sharp : \pi_1(Y, y_0) \to \pi_1(X, x_0)$ are inverse maps
between the groups (assuming $f(x_0) = y_0$ and $g(y_0) = x_0$).

%Now we want to show that by taking the map $f_\sharp$, we get a \emph{functor}
%\begin{diagram}
%	& (X, x_0) & & \pi_1(X, x_0) & \\
%	\catname{Top}_\ast \ni & \dTo^f & \rDotted & \dTo_{f_\sharp} & \in \catname{Grp} \\
%	& (Y, y_0) & & \pi_1(Y, y_0) &
%\end{diagram}
%\begin{ques}
%	Check this -- we need that $(f \circ g)_\sharp = f_\sharp \circ g_\sharp$
%	and that $(\id_X)_\sharp = \id_{\pi_1(X)}$.
%	Both are totally obvious once you can tell what they're asking.
%\end{ques}
%Thus in this way we've constructed a functor
%\[ \catname{Top}_\ast \to \catname{Grp}. \]
%In particular, by the fact that functors preserve isomorphism (\Cref{thm:functor_isom}), we have
%\begin{moral}
%	Homeomorophic topological spaces have isomorphic fundamental groups.
%	Category theory gives this to us for free.
%\end{moral}
%
%\begin{remark}
%	Note the similarity between this and the construction
%	of the covariant Yoneda functor (\Cref{ex:covariant_yoneda}).
%\end{remark}

\section{Higher homotopy groups}
Why the notation $\pi_1$ for the fundamental group?
And what are $\pi_2$, \dots?
The answer lies in the following rephrasing:
\begin{ques}
	Convince yourself that a loop is the same thing
	as a continuous function $S^1 \to X$.
\end{ques}
It turns out we can define homotopy for things other than paths.
Two functions $f, g : Y \to X$ are \vocab{homotopic} if there exists a continuous
function $Y \times [0,1] \to X$ which continuously deforms $f$ to $g$.
So everything we did above was just the special case $Y = S^1$.

For general $n$, the group $\pi_n(X)$ is defined as the homotopy classes
of the maps $S^n \to X$.
The group operation is a little harder to specify.
You have to show that $S^n$ is homeomorphic to $[0,1]^n$ with
some endpoints fused together; for example $S^1$ is $[0,1]$ with $0$ fused to $1$.
Once you have these cubes, you can merge them together on a face.
(Again, I'm being terribly imprecise, deliberately.)

For $n \neq 1$, $\pi_n$ behaves somewhat differently than $\pi_1$.
(You might not be surprised, as $S^n$ is simply connected for all $n \ge 2$ but not when $n=1$.)
In particular, it turns out that $\pi_n(X)$ is an abelian group for all $n \ge 2$.

Let's see some examples.
\begin{example}[$\pi_n(S^n) \cong \mathbb Z$]
	As we saw, $\pi_1(S^1) \cong \ZZ$; given the base circle $S^1$,
	we can wrap a second circle around it as many times as we want.
	In general, it's true that $\pi_n(S^n) \cong \ZZ$.
\end{example}
\begin{example}[$\pi_n(S^m) \cong \{1\}$ when $n < m$]
	We saw that $\pi_1(S^2) \cong \{1\}$, because
	a circle in $S^2$ can just be reeled in to a point.
	It turns out that similarly, any smaller $n$-dimensional sphere
	can be reeled in on the surface of a bigger $m$-dimensional sphere.
	So in general, $\pi_n(S^m)$ is trivial for $n < m$.
\end{example}
However, beyond these observations, the groups behave quite weirdly.
Here is a table of $\pi_n(S^m)$ for $1 \le m \le 8$ and $2 \le n \le 10$,
so you can see what I'm talking about.
(Taken from Wikipedia.)

\bgroup
\footnotesize
\[
	\begin{array}{r|ccccccccc}
		\pi_n(S^m) & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\ \hline
		m = 1 & \{1\} & \{1\} & \{1\} & \{1\} & \{1\} & \{1\} & \{1\} & \{1\} & \{1\} \\
		2 &  \ZZ & \ZZ & \Zc2 & \Zc2 & \Zc{12} & \Zc2 & \Zc2 & \Zc3 & \Zc{15}\\
		3 & & \ZZ & \Zc2 & \Zc2 & \Zc{12} & \Zc2 & \Zc2 & \Zc3 & \Zc{15}\\
		4 & &  & \ZZ & \Zc2 & \Zc2 & \ZZ \times \Zc{12} & (\Zc2)^2 & \Zc2 \times \Zc2 & \Zc{24} \times \Zc3 \\
		5 & &  &  & \ZZ & \Zc2 & \Zc2 & \Zc{24} & \Zc2 & \Zc2 \\
		6 & &  &  &  & \ZZ & \Zc2 & \Zc2 & \Zc{24} & \{1\} \\
		7 & &  &  &  &  & \ZZ & \Zc2 & \Zc2 & \Zc{24} \\
		8 & &  &  &  &  &  & \ZZ & \Zc2 & \Zc2
	\end{array}
\]
\egroup

Actually, it turns out that if you can compute $\pi_n(S^m)$
for every $m$ and $n$,
then you can essentially compute \emph{any} homotopy classes.
Thus, computing $\pi_n(S^m)$ is sort of a lost cause in general,
and the mixture of chaos and pattern in the above table is a testament to this.

\section{Homotopy equivalent spaces}
\prototype{A disk is homotopy equivalent to a point, an annulus is homotopy equivalent to $S^1$.}
Up to now I've abused notation and referred to ``path homotopy'' as just ``homotopy'' for two paths.
I will unfortunately continue to do so (and so any time I say two paths are homotopic, you should assume I mean ``path-homotopic'').
But let me tell you what the general definition of homotopy is first.
\begin{definition}
	Let $f,g : X \to Y$ be continuous functions.
	A \vocab{homotopy} is a continuous function $F : X \times [0,1] \to Y$,
	which we'll write $F_s(x)$ for $s \in [0,1]$, $x \in X$, such that
	\[ F_0(x) = f(x) \text{ and } F_1(x) = g(x) \text{ for all $x \in X$.} \]
	If such a function exists, then $f$ and $g$ are \vocab{homotopic}.
\end{definition}
Intuitively this is once again ``deforming $f$ to $g$''.
You might notice this is almost exactly the same definition as path-homotopy,
except that $f$ and $g$ are any functions instead of paths, and hence
there's no restriction on keeping some ``endpoints'' fixed through the deformation.

This homotopy can be quite dramatic:
\begin{example}
	The zero function $z \mapsto 0$ and the identity function $z \mapsto z$
	are homotopic as functions $\CC \to \CC$.
	The necessary deformation is
	\[ [0,1] \times \CC \to \CC \text{ by } (t,z) \mapsto tz. \]
\end{example}

I bring this up because I want to define:
\begin{definition}
	Let $X$ and $Y$ be continuous spaces.
	They are \vocab{homotopy equivalent} if there exist
	functions $f : X \to Y$ and $g : Y \to X$ such that
	\begin{enumerate}[(i)]
		\ii $f \circ g : X \to X$ is homotopic to the identity map on $X$, and
		\ii $g \circ f : Y \to Y$ is homotopic to the identity map on $Y$.
	\end{enumerate}
	If a topological space is homotopy equivalent to a point,
	then it is said to be \vocab{contractible}.
\end{definition}
\begin{ques}
	Why are two homeomorphic spaces also homotopy equivalent?
\end{ques}

Intuitively, you can think of this as a more generous form of stretching
and bending than homeomorphism: we are allowed to compress huge spaces into single points.

\begin{example}[$\CC$ is contractible]
	Consider the topological spaces $\CC$
	and the space consisting of the single point $\{0\}$.
	We claim these spaces are homotopy equivalent (can you guess what $f$ and $g$ are?)
	Indeed, the two things to check are
	\begin{enumerate}[(i)]
		\ii $\CC \to \{0\} \hookrightarrow \CC$ by $z \mapsto 0 \mapsto 0$
		is homotopy equivalent to the identity on $\CC$, which we just saw, and
		\ii $\{0\} \hookrightarrow \CC \to \{0\}$ by $0 \mapsto 0 \mapsto 0$, which \emph{is} the identity on $\{0\}$.
	\end{enumerate}
	Here by $\hookrightarrow$ I just mean $\to$ in the special case
	that the function is just an ``inclusion''.
\end{example}
\begin{remark}
	$\CC$ cannot be \emph{homeomorphic} to a point
	because there is no bijection of sets between them.
\end{remark}

\begin{example}[$\CC \setminus \{0\}$ is homotopy equivalent to $S^1$]
	Consider the topological spaces $\CC \setminus \{0\}$,
	the \vocab{punctured plane}, and the circle $S^1$ viewed as a subset of $S^1$.
	We claim these spaces are actually homotopy equivalent!
	The necessary functions are the inclusion
	\[ S^1 \hookrightarrow \CC \setminus \{0\} \]
	and the function
	\[ \CC \setminus \{0\} \to S^1
		\quad\text{by}\quad
		z \mapsto \frac{z}{\left\lvert z \right\rvert}. \]
	You can check that these satisfy the required condition.
\end{example}
\begin{remark}
	On the other hand, $\CC \setminus \{0\}$ cannot be \emph{homeomorphic} to $S^1$.
	One can make $S^1$ disconnected by deleting two points;
	the same is not true for $\CC \setminus \{0\}$.
\end{remark}
\begin{example}
	[$\text{Disk} = \text{Point}$, $\text{Annulus} = \text{Circle}$.]
	By the same token, a disk is homotopic to a point;
	an annulus is homotopic to a circle.
	(This might be a little easier to visualize, since it's finite.)
\end{example}

I bring these up because it turns out that
\begin{moral}
	Algebraic topology can't distinguish between homotopy equivalent spaces.
\end{moral}
More precisely,
\begin{theorem}[Homotopy equivalent spaces have isomorphic fundamental groups]
	\label{thm:fundgrp_homotopy_invariant}
	Let $X$ and $Y$ be path-connected, homotopy-equivalent spaces.
	Then $\pi_n(X) \cong \pi_n(Y)$ for every positive integer $n$.
\end{theorem}
\begin{proof}
	Let $\gamma : [0,1] \to X$ be a loop.
	Let $f : X \to Y$ and $g : Y \to X$ be maps witnessing that $X$ and $Y$ are homotopy equivalent
	(meaning $f \circ g$ and $g \circ f$ are each homotopic to the identity).
	Then the composition
	\[ [0,1] \taking\gamma X \taking f Y \]
	is a loop in $Y$ and hence $f$ induces a natural homomorphism $\pi_1(X) \to \pi_1(Y)$.
	Similarly $g$ induces a natural homomorphism $\pi_1(Y) \to \pi_1(X)$.
	The conditions on $f$ and $g$ now say exactly that these two homomorphisms
	are inverse to each other, meaning the maps are isomorphisms.
\end{proof}
In particular,
\begin{ques}
	What are the fundamental groups of contractible spaces?
\end{ques}

That means, for example, that algebraic topology can't tell
the following homotopic subspaces of $\RR^2$ apart.
\begin{center}
	{\color{red} \Huge \venus}
	\qquad
	{\color{blue} \Huge \mars}
\end{center}

\section{The pointed homotopy category}
This section is meant to be read by those who know some basic category theory.
Those of you that don't should come back after reading \Cref{ch:cats,ch:functors}.
Those of you that do will enjoy how succinctly we can summarize
the content of this chapter using categorical notions.

\begin{definition}
	The \vocab{pointed homotopy category} $\catname{hTop}_\ast$ is defined as follows.
	\begin{itemize}
		\ii Objects: pairs $(X, x_0)$ of spaces with a distinguished basepoint, and
		\ii Morphisms: \emph{homotopy classes} of continuous functions $(X, x_0) \to (Y, y_0)$.
	\end{itemize}
\end{definition}
In particular, two path-connected spaces are isomorphic in this category exactly
when they are homotopy equivalent.
Then we can summarize many of the preceding results as follows:
\begin{theorem}[Functorial interpretation of fundamental groups]
	\label{thm:fundgrp_functor}
	There is a functor
	\[ \pi_1 : \catname{hTop}_\ast \to \catname{Grp} \]
	sending
	\begin{diagram}
		(X,x_0) & \rTo & \pi_1(X, x_0) \\
		\dTo^f & & \dTo^{f_\sharp} \\
		(Y,y_0) & \rTo & \pi_1(Y, y_0)
	\end{diagram}
\end{theorem}
This implies several things, like
\begin{itemize}
	\ii The functor bundles the information of $f_\sharp$,
	including the fact that it respects composition.
	In the categorical language, $f_\sharp$ is $\pi_1(f)$.
	\ii Homotopic spaces have isomorphic fundamental group
	(since the spaces are isomorphic in $\catname{hTop}$,
	and functors preserve isomorphism by \Cref{thm:functor_isom}).
	In fact, you'll notice that the proofs
	of \Cref{thm:functor_isom} and \Cref{thm:fundgrp_homotopy_invariant}
	are secretly identical to each other.
	\ii If maps $f, g : (X, x_0) \to (Y, y_0)$ are homotopic,
	then $f_\sharp = g_\sharp$. This is basically \Cref{lem:fsharp_homotopy_invariant}
\end{itemize}

\begin{remark}
	In fact, $\pi_1(X, x_0)$ is the set of arrows $(S^1, 1) \to (X, x_0)$ in $\catname{hTop}_\ast$,
	so this is actually a covariant Yoneda functor (\Cref{ex:covariant_yoneda}),
	except with target $\catname{Grp}$ instead of $\catname{Set}$.
\end{remark}

\section\problemhead

\begin{problem}[Harmonic fan]
	Exhibit a subspace $X$ of the metric space $\RR^2$ which is
	path-connected but for which a point $p$ can be found such that
	any $r$-neighborhood of $p$ with $r < 1$ is not path-connected.
	% harmonic fan
\end{problem}

\begin{dproblem}
	[Special case of Seifert-van Kampen] \gim
	Let $X$ be a topological space.
	Suppose $U$ and $V$ are connected open subsets of $X$, with $X = U \cup V$,
	so that $U \cap V$ is nonempty and path-connected.

	Prove that if $\pi_1(U) = \pi_1(V) = \{1\}$ then $\pi_1(X) = 1$.
\end{dproblem}
\begin{remark}
	The \vocab{Seifert--van Kampen theorem} generalizes this
	for $\pi_1(U)$ and $\pi_1(V)$ any groups; it gives a formula for calculating $\pi_1(X)$
	in terms of $\pi_1(U)$, $\pi_1(V)$, $\pi_1(U \cap V)$.
	The proof is much the same.

	Unfortunately, this does not give us a way to calculate $\pi_1(S^1)$,
	because it is not possible to write $S^1 = U \cup V$ for $U \cap V$ \emph{connected}.
\end{remark}

\begin{problem}
	[RMM 2013] \yod
	Let $n \ge 2$ be a positive integer.
	A stone is placed at each vertex of a regular $2n$-gon.
	A move consists of selecting an edge of the $2n$-gon and swapping the two stones at the endpoints of the edge.
	Prove that if a sequence of moves swaps every pair of stones exactly once, then there is some edge never used in any move.
\end{problem}
(This last problem doesn't technically have anything to do with the chapter,
but the ``gut feeling'' which motivates the solution is very similar.)


\documentclass{article}
\usepackage[utf8]{inputenc}

\title{MAT257 Notes}
\author{Jad Elkhaleq Ghalayini}
\date{October 24 2018}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{graphicx}
\usepackage{cancel}

\usepackage[margin=1in]{geometry}

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}{Lemma}
\newtheorem{definition}{Definition}
\newtheorem*{corollary}{Corollary}
\newtheorem{exercise}{Exercise}

\DeclareMathOperator{\Int}{Int}

\newcommand{\reals}[0]{\mathbb{R}}
\newcommand{\nats}[0]{\mathbb{N}}
\newcommand{\ints}[0]{\mathbb{Z}}
\newcommand{\rationals}[0]{\mathbb{Q}}
\newcommand{\brac}[1]{\left(#1\right)}
\newcommand{\sbrac}[1]{\left[#1\right]}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\eval}[3]{\left.#3\right|_{#1}^{#2}}
\newcommand{\ip}[2]{\left\langle#1,#2\right\rangle}
\newcommand{\prt}[2]{\frac{\partial #1}{\partial #2}}

\begin{document}

\maketitle

\section*{Proof of the Inverse Function Theorem}

Let \(f: \reals^n \to \reals^n\) be \(\mc{C}^1\) on an open set containing \(a \in \reals^n\) and let \[\det f'(a) \neq 0\]
We can assume, as shown in last lecture, that \(f'(a) = I\).
We show that there are open \(V, W\) containing \(a\) and \(f(a)\) respectively such that \(f: V \to W\) with a continuous inverse \(f': W \to V\)

We will begin by showing that we can't have \(f(x) = f(a)\) if \(x \neq a\) is sufficiently close to \(a\):
\[f'(a) = I \land Ih = h \implies \lim_{h \to 0}\frac{|f(a + h) - f(a) - h|}{|h|} = 0\]
If \(f(a + h) = f(a)\) then the quotient is 1. So the quotient being zero means that there exists a closed ball \(B\) centered at \(a\) such that
\[x \in B \setminus \{a\} \implies f(x) \neq f(a)\]
But that's not enough to mean that \(f\) is one to one in \(B\): it could be, for example, that \(f(\partial B)\), the image of the boundary of \(B\), intersects itself, for example. What we want to do is find an even smaller ball where \(f\) really is one-to-one. So, since \(f\) is \(\mc{C}^1\) in a neighborhood of \(a\) we can also assume:
\begin{enumerate}

  \item \(x \in B \implies \det f'(x) \neq 0\) since \(f'\) is continuous

  \item Given \(\epsilon\), we can make, for all \(i, j\), \[
    \left|\prt{f_i}{x_j}(x) - \prt{f_i}{x_j}(a)\right| < \epsilon
  \]
  Note that, by our previous assumption that \(f'(a) = I\),
  \[\prt{f_i}{x_j}(a) = I_{ij}\]

\end{enumerate}
Apply the Mean Value Theorem to \(g(x) = f(x) - x\). According to the MVT, we can also assume that
\[|g(x_1) - g(x_2)| \leq cb|x_1 - x_2|\]
where \(c\) is a constant and \(b\) is a bound on the partial derivatives of \(g\). But what is \(\prt{g_i}{x_j}\)? It's the same as what's in the absolute value brackets in assumption (2), since
\[\prt{x_i}{x_j} = \delta_{ij} = \prt{f_i}{x_j}\]
So we have that
\[|g(x_1) - g(x_2)| \leq c\epsilon|x_1 - x_2|\]
for some constant \(c\). That was for any given \(\epsilon\). Let's choose \(\epsilon\) such that \(c\epsilon = \frac{1}{2}\), giving
\[|g(x_1) - g(x_2)| \leq \frac{1}{2}|x_1 - x_2|\]
If you remember that problem we did on the MVT, we gave a precise bound on \(\epsilon\), specifically it suffices to choose \(\epsilon = \frac{1}{2n}\). So what does this tell us?
\[|f(x_1) - x_1 - f(x_2) + x_2| \leq \frac{1}{2}|x_1 - x_2|\]
using the Triangle Inequality, we obtain
\[|x_1 - x_2| \leq 2|f(x_1) - f(x_2)|\]
So what does \textit{this} tell us? It tells us that \(f\) is one-to-one on \(B\), since if \(f(x_1) = f(x_2)\) and \(x_1 \neq x_2\) then
\[|x_1 - x_2| > 2|f(x_1) - f(x_2)| = 0\]
We have that \(f(\partial B)\) is a compact set not including \(a\). So we have that
\[d = d(f(a), f(\partial B)) > 0\]
Let
\[W = \{y : |y - f(a)| \leq d/2\}\]
Then if \(y \in W\), \(x \in \partial B\), then what's the relationship between
\(|y - f(a)|\) and \(|y - f(x)|\)? Since \(W\) is the ball of radius \(\frac{d}{2}\), we have that
\[|y - f(a)| < |y - f(x)|\]
This tells us that \(W\) is completely in the image of \(B\). It follows that for all \(y \in W\), there is some \(x \in \Int B\) such that \(f(x) = y\). I could have said unique \(x\), but I didn't bother because it must be unique anyways since we already checked one to one. But let's check this. We're going to do so by solving an extreme value problem. Let's define \(h: B \to \reals\) by
\[x \mapsto |y - f(x)|^2 = \sum_{i = 1}^n|y_i - f_i(x)|^2\]
\(h\) is continuous, and therefore it has a minimum on the compact set \(B\). So this is the usual business of a max-min problem: it could be that the minimum occurs on the bounary. So can it? No, since, as we saw above,
\[\forall y \in W, |y - f(a)| < |y - f(x)|\]
So that means it occurs at the interior, and since \(f\) and hence \(|y - f(x)|^2\) is differentiable, at a critical point, a point where all the partial derivatives are zero, \(x \in \Int B\). But what does the following exactly mean:
\[\prt{h}{x_j}(x) = 0\]
Expanding, we get
\[\forall j \in \{1,...,n\}, \sum_{i = 1}^n2(y_i - f_i(x))\prt{f_i}{x_j}(x) = 0\]
So what does this tell us? This is a system of \(n\) equations linear in \(y_i - f_i(x)\) with coefficients \(\prt{f_i}{x_j}(x)\). But since the matrix
\[\left(\prt{f_i}{x_j}\right)\]
is invertible, since \(\det f'(x) \neq 0\), we have
\[[\forall i \in \{1,...,n\}, (y_i - f_i(x)) = 0] \iff y = f(x)\]
which is what we wanted to show.

So back to what we wanted to do, we wanted to find those open sets \(V\) and \(W\). So what should we use as \(V\)?
\[V = f^{-1}(W) \cap \Int B\]
Then \(f: V \to W\) has an inverse \(f^{-1}: W \to V\), since \(f\) is one to one. We also wanted to show that the inverse is continuous. So how do we see that? Well, we go back to what we showed above:
\[\forall x_1, x_2 \in V, |x_1 - x_2| \leq 2|f(x_1) - f(x_2)| \implies \forall y_1, y_2 \in W, |f^{-1}(y_1) - f^{-1}(y_2)| \leq 2|y_1 - y_2|\]
implying \(f^{-1}\) is continuous. So the only thing remaining is to show that \(f^{-1}\) is differentiable. So let's take a point \(x_0 \in V\), \(y_0 = f(x_0)\). Call \(\mu = Df(x_0)\). We'll show \(f^{-1}\) is differentiable at \(y_0\) and \((f^{-1})'(y_0) = \mu^{-1}\). So what do we know. We know that
\[f(x) = f(x_0) + \mu(x - x_0) + \varphi(x)\]
where
\[\lim_{x \to x_0}\frac{|\varphi(x)|}{|x - x_0|} = 0\]
Each \(y \in W\) can be written \(y = f(x), x \in V\). We have
\[\mu^{-1}(y - y_0) = \mu^{-1}(f(x) - f(x_0)) = x - x_0 + \mu^{-1}\varphi(x)\]
So what this says is that
\[f^{-1}(y) = f^{-1}(y_0) + \mu^{-1}(y - y_0) - \mu^{-1}\varphi(f^{-1}(y))\]
That's like what we need to show that \(f^{-1}\) is differentiable. Specifically, we have to show
\[\lim_{y \to y_0}\frac{\mu^{-1}\varphi(f^{-1}(y))}{|y - y_0|} = 0\]
We have
\[\frac{\varphi(f^{-1}(y))}{|y - y_0|} = \frac{\varphi(f^{-1}(y))}{|f^{-1}(y) - f^{-1}(y_0)|} \cdot \frac{|f^{-1}(y) - f^{-1}(y_0)|}{|y - y_0|} \leq 2\frac{\varphi(f^{-1}(y_0))}{|f^{-1}(y) - f^{-1}(y_0)}\]
And that's the proof of the inverse function theorem, and hence the implicit function theorem.

\end{document}


\documentclass[a4paper]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{libertine}
\usepackage[libertine]{newtxmath}
\usepackage{amsmath}
\usepackage{commath}
\usepackage{mathrsfs}
% \usepackage{enumitem}
\usepackage{bm}
\usepackage{authblk}
% \usepackage{esdiff}
% \usepackage{microtype}

\newcommand{\M}[1]{\bm{#1}}
\newcommand{\Mc}[1]{\mathbf{#1}}
\newcommand{\V}[1]{\mathbf{#1}}
\newcommand{\transpose}{^{\text{T}}}
\newcommand{\E}{\text{E}}
\newcommand{\fourier}{\mathcal{F}}
\newcommand{\lagrange}{\mathscr{L}}
\newcommand{\sub}[1]{_{\mathrm{#1}}}
\DeclareMathOperator{\Var}{Var}
\DeclareMathOperator{\nul}{nul}
\DeclareMathOperator{\rank}{rank}

\title{Summary of TTK4115}
\author{Morten Fyhn Amundsen}
\affil{NTNU}

\begin{document}
\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Matrix stuff}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Nullity} $\nul(\M{A}) = \mbox{No. of columns of } \M{A} - \rank(\M{A})$
\paragraph{Positive definite} A symmetric $n \times n$ real matrix $\M{M}$ is \emph{positive definite} if all its eigenvalues are positive. (Or if $\V{z}\transpose \M{M}\V{z} > 0$ for every non-zero vector $\V{z}$ of $n$ real numbers.) It is positive \emph{semidefinite} if all eigenvalues are positive or zero.
\paragraph{Singularity} A square matrix is singular if it is not invertible, i.e. if its determinant is $0$.
\paragraph{Matrix exponential (diagonal)}
$$\M{A} =
\begin{bmatrix}
a_1		& \cdots	& 0			\\
\vdots 	& \ddots	& \vdots	\\
0		& \cdots	& a_n		\\
\end{bmatrix}
\quad \implies \quad
e^{\M{A}t} =
\begin{bmatrix}
e^{a_1t}	& \cdots	& 0			\\
\vdots 		& \ddots	& \vdots	\\
0			& \cdots	& e^{a_nt}	\\
\end{bmatrix}$$
\paragraph{Matrix exponential (Cayley-Hamilton Method)}
$$e^{\M{A}t} = \sum_{k=0}^{n-1} \alpha_k \M{A}^k
\quad \text {with } \alpha_0 \cdots \alpha_{n-1} \text{ determined by} \quad
e^{\lambda_i t} = \sum_{k=0}^{n-1} \alpha_k \lambda_i^k$$
\paragraph{Matrix exponential (Laplace method)}
$$e^{\M{A}t} = \lagrange \left\{ (s\Mc{I}-\M{A})^{-1} \right\}$$
\paragraph{Matrix exponential (Jordan form)}
$$e^{\M{A}t} = \M{Q} e^{\bar{\M{A}}t} \M{Q}^{-1} \quad \text{where} \quad \bar{\M{A}} = \M{Q}^{-1}\M{AQ}$$
\paragraph{Controllability matrix} $\mathcal{C} = \begin{bmatrix}\M{B} & \M{AB} & \M{A}^{2}\M{B} & \hdots & \M{A}^{n-1}\M{B}\end{bmatrix}$
\paragraph{Observability matrix} $\mathcal{O} = \begin{bmatrix}\M{C} & \M{CA} & \M{CA}^2 & \hdots & \M{CA}^{n-1}\end{bmatrix}^{\text{T}}$
\paragraph{Minimal realisation} Given a transfer function; a state-space model that is controllable and observable, and has the same input-output behaviour as the function, is minimal.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Eigen stuff}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Eigenvalues} Values of $\lambda$ such that $\Delta(\lambda) = |\lambda \M{I} - \M{A}| = 0$.
\paragraph{Eigenvectors} Vectors $\V{v}$ such that $(\M{A} - \lambda \Mc{I})\V{v} = 0$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Stability}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Asymptotic stability} Occurs if all poles have strictly negative real parts.
\paragraph{Instability} Occurs if one or more poles have positive real parts.
\paragraph{Marginal stability} Occurs when the real part of every pole is non-positive, at least one pole has zero real value, and there are no repeated poles on the imaginary axis.
\paragraph{BIBO stability} If bounded input $\rightarrow$ bounded output. Defined for the zero-state response (initially relaxed system). See Section \ref{sec:bibo}.
\paragraph{Lyapunov stability} If every finite initial state gives a finite response. I.e. the zero-input response.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{BIBO Stability}\label{sec:bibo}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{BIBO Stability for Continuous Systems}
A continuous system is BIBO stable \emph{iff}:
\begin{itemize}
\item	(SISO) $g(t)$ is absolutely integrable in $[0, \infty)$ \quad or \quad $\int_{0}^{\infty} |g(t)| \dif t \leq M < \infty $ for some constant $M$.
\item	(SISO/MIMO) Every pole of every transfer function in $\M{\hat{G}}(s)$ or $\hat{g}(s)$ has a negative real part.
\end{itemize}
\subsection{BIBO Stability for Discrete Systems}
A discrete system is BIBO stable iff:
\begin{itemize}
\item	Every pole of every transfer function in $\M{\hat{G}}(s)$ or $\hat{g}(s)$ has magnitude less than $1$.
\end{itemize}
\subsection{Lyapunov Stability for Linear Systems}
An LTI system $\V{\dot{x}} = \M{A}\V{x}$ is stable if there exists a \emph{symmetric} positive definite matrix $\M{P}$ that satisfies the Lyapunov Equation
$$\M{A} \transpose \M{P} + \M{MP} = - \M{N}$$
Where $\M{N}$ is an arbitrary positive definite matrix.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Discretisation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$$\M{A}_d = e^{\M{A}T},\qquad \M{B}_d = \int_0^T e^{\M{A}\tau} \dif \tau \M{B}, \qquad \M{C}_d = \M{C}, \qquad \M{D}_d = \M{D}$$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Similarity transform}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A linear change of coordinates where the original object is expressed with respect to a different basis. The representation of $\V{x}$ with respect to the basis $\{ \V{q}_1, \dots, \V{q}_n \}$ is $\V{\bar{x}}$ and with $\M{Q} = [ \V{q}_1, \dots, \V{q}_n ]$, the similarity transform is
$$\V{x} = \M{Q}\V{\bar{x}}.$$
The system originally expressed as
$$\V{\dot{x}} = \M{A}\V{x} + \M{B}\V{u}$$
$$\V{y} = \M{C}\V{x} + \M{D}\V{u}$$
is transformed to
$$\V{\dot{\bar{x}}} = \M{\bar{A}}\V{\bar{x}} + \M{\bar{B}}\V{u}$$
$$\V{y} = \M{\bar{C}}\V{\bar{x}} + \M{\bar{D}}\V{u}$$
where
$$\M{\bar{A}} = \M{Q}^{-1}\M{AQ},\qquad \M{\bar{B}} = \M{Q}^{-1}\M{B},\qquad \M{\bar{C}} = \M{CQ},\quad \M{\bar{D}} = \M{D}$$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Jordan canonical form}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
General strategy:
\begin{enumerate}
\item Find all eigenvectors corresponding to an eigenvalue of $\M{A}$.
\item The number of L.I. eigenvectors is the number of Jordan blocks.
\item For each eigenvector $\V{q}$, solve $(\lambda \Mc{I} - \M{A}) \V{v} = \V{q}$ for the vector $\V{v}$.
\end{enumerate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Statistics}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{Expected value} $\E[X] = \int_{-\infty}^{\infty} x f(x) \dif t$
\paragraph{Variance} $\Var(X) = \E[(X-\E[X])^{2}] = \E[X^{2}] - (\E[X])^{2}$
\paragraph{Autocorrelation} $R_X(t_1, t_2) = \E[X(t_1)X(t_2)]$
\paragraph{Wide-sense stationary process} $X(t)$ is WSS if its mean and autocorrelation functions are time invariant: \quad  $\E[X(t)] = \nu$ \quad and \quad $R_X(t_1, t_2) = f(t_2-t_1)$.
\paragraph{Spectral density function} $S_X(\jmath\:\omega) = \fourier\left\{ R_X(\tau) \right\}$
\paragraph{Gauss--Markov process} A stationary Gaussian process $X(t)$ that has an exponential autocorrelation is called a \emph{Gauss--Markov} process.
$$R_X(\tau) = \sigma^2 e^{-\beta |\tau|}$$ $$S_X(\jmath\:\omega) = \frac{2\sigma^2\beta}{\beta^2 + \omega^2} \quad\text{or}\quad S_X(s) = \frac{2\sigma^2\beta}{\beta^2 - s^2}$$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Linear-quadratic regulator}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A system is given as $$\V{\dot{x}} = \M{A}\V{x} + \M{B}\V{u}$$
with a state feedback $\V{u} = - \M{K}\V{x}$ chosen to minimise the cost function
$$J = \int_0^\infty \V{x}\transpose \M{Q} \V{x} + \V{u}\transpose \M{R} \V{u} \dif t$$
where $\M{Q}$ is symmetric and positive semidefinite, $\M{R}$ is symmetric and positive definite, and $\M{K} = \M{R}^{-1}\M{B}\transpose\M{P}$. The matrix $\M{P}$ is found by solving $$\M{A}\transpose \M{P} + \M{PA} - \M{PBR}^{-1}\M{B}\transpose \M{P} + \M{Q} = \M{0}$$

The relative values of the elements of $Q$ and $R$ enforce tradeoffs between the magnitude of the control action and the speed of the response. The equilibrium can be shifted from $\V{0}$ to $\V{x}\sub{eq}$ by instead using $\V{u} = \M{P}\V{x}\sub{eq} - \M{K}\V{x}$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Kalman filter}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The system is given as:
$$\V{x}_{k+1} = \M{A}\V{x}_k + \M{B}\V{u}_k + \V{w}_k$$
$$\V{z}_k = \M{H}_k\V{x}_k + \V{v}_k$$
The Kalman measurement update equations are:
$$\M{K}_k = \M{P}_k^- \M{H}_k\transpose (\M{H}_k\M{P}_k^- \M{H}_k\transpose + \M{R}_k)^{-1}$$
$$\V{\hat{x}}_k = \V{\hat{x}}_k^- + \M{K}_k(\V{z}_k - \M{H}_k \V{\hat{x}}_k^-)$$
$$\M{P}_k = (\Mc{I} - \M{K}_k \M{H}_k) \M{P}_k^- (\Mc{I}-\M{K}_k\M{H}_k)\transpose + \M{K}_k\M{R}_k\M{K}_k\transpose$$
And the time update equations are:
$$\V{\hat{x}}_{k+1}^- = \M{A}\V{\hat{x}}_k + \M{B}\V{u}_k$$
$$\M{P}_{k+1}^- = \M{AP}_k\M{A}\transpose + \M{Q}_k$$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Extended Kalman filter}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
The system is given as:
$$\V{x}_{k+1} = \V{f}(\V{x}_k, \V{u}_k) + \V{w}_k$$
$$\V{y}_k = \V{h}(\V{x}_k) + \V{v}_k$$
The Kalman measurement update equations are:
$$\M{K}_k = \M{P}_k^- \M{C}_k\transpose (\M{C}_k \M{P}_k^- \M{C}_k\transpose + \M{R})^{-1}$$
$$\V{\hat{x}}_k = \V{\hat{x}}_k^- + \M{K}_k \left(\V{y}_k - \V{h}(\V{\hat{x}}_k^-)\right)$$
$$\M{P}_k = (\Mc{I} - \M{K}_k\M{C}_k) \M{P}_k^- (\Mc{I} - \M{K}_k\M{C}_k)\transpose + \M{K}_k\M{R}_k\M{K}_k\transpose$$
And the time update equations are:
$$\V{\hat{x}}_{k+1}^- = \V{f}(\V{\hat{x}}_k, \V{u}_k)$$
$$\M{P}_{k+1}^- = \M{A}_k\M{P}_k\M{A}_k\transpose + \M{Q}_k$$
Where:
$$\M{A}_k = \pd{\V{f}}{\V{x}_k}\bigg|_{\V{x}_k = \V{\hat{x}}_k} \qquad\text{and}\qquad \M{C}_k = \od{\V{h}}{\V{x}_k}\bigg|_{\V{x}_k = \V{\hat{x}}_k^-}$$

\end{document}

TTK4115 Linear system theory/TTK4115-Summary.tex


\subsubsection{Mission}
	It is necessary to obtain a reasonable estimation of the mission
	performance requirements in order to carry out system level trade studies.
	It is important to note that the exact mission route is dependent on the
	topography of the land between the two notional endpoints. Currently, it is
	beyond the scope of the model to account for the effect that varying
	topology will have on the pod’s trajectory. For simplicity, the model
	assumes that the pod travels in a straight, flat line between the departure
	and arrival locations, in this case between Los Angeles (LAX) and San
	Francisco (SFO) International airports.
	The mission velocity profile contains three phases: acceleration, coasting
	with periodic boosting, and deceleration.
	\begin{figure}
		\centering
		\includegraphics{../images/mission_profile.png}
		\caption{Notional Velocity Profile in Mission Analysis}
		\label{fig:mission_profile}
	\end{figure}
	\Cref{fig:mission_profile} shows a notional velocity profile using the
	mission analysis model. The initial acceleration is
	modeled as a constant linear acceleration of 1g from rest to top speed.
	Previous analyses have modeled the start up as an incremental acceleration,
	as is shown in \cref{fig:mission_profile}, to allow for more maneuverability
	near departure and arrival points, and to avoid sustaining potentially
	uncomfortable g forces for prolonged periods of time \cite{Chin}.
	The difference in energy consumption between an incremental acceleration
	and the constant acceleration used in this model is negligible.
	The second phase of travel consists of a coasting pod with periodic boosting sections.
	In this phase, the pod begins at top speed and is allowed to coast until it
	reaches some minimum allowable speed set by the user.
	Then, the pod will enter an electromagnetic boosting section which will
	accelerate the pod at 1g back to the desired top speed.
	For straight and level travel, the acceleration of the pod is given by the equation
	\begin{equation}
		\label{eq:acceleration}
		\frac{\mathrm{d} v}{\mathrm{d} t} = f ( v  ) = \frac{1}{m} ( F_{thrust} - \frac{1}{2}C_{D}\rho V^{2}A - D_{mag})
	\end{equation}
	where $F_{thrust}$ is the net thrust generated by the flow through the pod
	nozzle, $C_D$ is the pod drag coefficient, $\rho$ is the free stream air
	density, $A$ is the pod planform area, and $D_{mag}$ is the drag produced
	by the magnetic levitation system. The acceleration equation is integrated
	to find the time and distance it takes for the pod to decelerate to the
	minimum allowable speed using a predictor-corrector integration method.

  The coast distance is used to determine the number of propulsive sections
	needed along the track to complete the mission. The energy consumed in a
	single propulsive section is then multiplied by the number of propulsive
	sections along the track to determine the electromagnetic propulsive energy
	consumed per flight during the coasting phase of the mission. The final
	phase of the mission is a constant linear deceleration of 0.5g from top
	speed to rest. Many systems driven by electromagnetic propulsion conserve
	energy through regenerative braking \cite{inductrack}. For the sake of
	conservatism, it is assumed that there is no regenerative braking in this
	process, although the model allows for regenerative braking to be
	accounted for if the user desires. The energy consumed per flight is
	computed by adding the consumption of all three phases.

\subsubsection{Cost}
	The cost module estimates the cost of energy, materials, pods, and
	construction capital. The cost of construction is highly subjective and is
	difficult to get an accurate estimation within less than an order of
	magnitude of uncertainty. However, the cost of materials and energy
	consumption can be estimated with significantly greater certainty.
	Thus, in this analysis, the cost estimations of materials and energy are of greater interest.
	The average price of electricity used in the model is 0.13 USD/kWh, based on
	data from the Electricity Information Administration\cite{EIA}.
	Using a different value will not significantly change the trends in the trade studies this model produces.
	A rough estimation of the ticket cost is included, which projects ticket cost based on the equation
	\begin{equation}
		\label{eq:ticket_cost}
    \text{Cost}_\text{ticket} = \frac{ (\frac{\partial \text{Cost}}{\partial D}D+\frac{\partial \text{Cost} }{\partial \text{pod}}n_{\text{pods}}+\text{Cost}_\text{capital} ( 1+ib ) + \frac{\partial \text{Cost}}{\partial \mathcal{E}} (\mathcal{E}_\text{tube} + \mathcal{E}_\text{pod}  ))  )}{n_\text{passengers}*\frac{\text{pods}}{s}*3600\frac{s}{\text{\text{year}}}*24\frac{\text{\text{year}}}{\text{day}}*365\frac{\text{day}}{\text{year}}*bm}
	\end{equation}
	Where $ib$ is the bond interest rate, $bm$ is the number of years for bond
	maturity, and $D$ is the total length of the track. Previous research
	indicated that construction costs are likely to be the largest cost factor
	in the system \cite{Musk}. Due to the lack of a reliable method of
	estimating construction cost or ticket markup at this stage of the design process,
	the exact values of the ticket cost produced by this model will have a high level of uncertainty.
	However, the trade studies conducted in these analyses can provide useful
	information to inform the development of more accurate ticket cost models in the future.


% !TeX root = ./type-system.tex
\pdfcompresslevel=0
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage{mathtools}

\newcommand{\subt}{\mathrel{<\vcentcolon}}
\newcommand{\supt}{\mathrel{>\vcentcolon}}

\setlength{\headheight}{15pt}
\pagestyle{fancy}
\begin{document}

\section*{Representation of Types}
\begin{itemize}
    \item type void = \( \bot \)
    \item type any = \( \top \)
    \item type union \( \alpha_\epsilon \) = \( \bigcup\limits_{i < \epsilon} x_i \)
    \item type func \( \alpha~\tau \) = \( \alpha \rightarrow \tau \)
    \item type poly \( \sigma \) = \( \forall\alpha.\tau[\alpha \coloneqq \sigma ]\)
    \item type list \( \alpha \) = \( \{ x : x \in \alpha \} \)
\end{itemize}

\end{document}


\chapter{Results}
\begin{comment}

\end{comment}

\section{Lenard-Jones Potential with direct Summation}
\begin{comment}

\end{comment}

% Plot of the total energy as a function of time

First we take a look at a simulation with just the lenard-jones-potential.
First a good timestep for the simulation has to be chosen.
So we search for a good $ \mathrm{prefactor} $ for the following equation \cite{molDymCourse}.
\begin{equation}
	\label{timestepDeterminant}
 \mathrm{timestep} = \mathrm{prefactor} * \sqrt{(m\sigma^2)/\epsilon}
\end{equation}
To decide on a good timestep a sequence of plots, as can be seen in Fig. \ref{SimWithTimestep},was created.
\par
As the prefactor gets bigger, the energy in the simulation goes from stable (prefactor 0.01) over a drifting behavior (prefactor 0.03) to being unstable (prefactor 0.05). A good prefactor would be 0.01.

\begin{figure}
	\begin{center}
		\includegraphics[scale= 1.0]{/home/cm/CLionProjects/MDCode/AData//totalEnergyDrift.png}
	\end{center}
	\caption[Comparison of the energy in the simulation with different timesteps]{Comparison of the energy in the simulation for different timesteps. We run the simulation with $\mathrm{m}, \sigma, \epsilon = 1$ for a constant number of steps $\mathrm{n_{steps}} = 10000 $}
	\label{SimWithTimestep}
\end{figure}
\par
To visualize the simulation OVITO \cite{ovito} was used and a series of snapshots, visible in Fig. \ref{SimulationSnapshot1} - \ref{SimulationSnapshot3}, was created. The following images show one of the first simulations, where the forces were calculated with the Lenard-Jones-Potential. The simulated cluster had a size of 52 atoms, and was given in the course lecture material \cite{molDymCourse}.
% Simulation Snapshots
\begin{figure}
	\begin{center}
		\includegraphics[scale= 0.65]{Figure/1ImageS.png}
	\end{center}
	\caption[Simulation Snapshot 1]{Initial state of the cluster}
	\label{SimulationSnapshot1}
\end{figure}

\begin{figure}
	\begin{center}
		\includegraphics[scale= 0.75]{Figure/2ImageS.png}
	\end{center}
	\caption[Simulation Snapshot 2]{State after 2000 timesteps}
	\label{SimulationSnapshot2}
\end{figure}

\begin{figure}
	\begin{center}
		\includegraphics[scale= 0.65]{Figure/3ImageS.png}
	\end{center}
	\caption[Simulation Snapshot 3]{State after 4000 timesteps}
	\label{SimulationSnapshot3}
\end{figure}
As it can be seen in the images \ref{SimulationSnapshot1}, \ref{SimulationSnapshot2} and \ref{SimulationSnapshot3} the Atoms are initially ordered into a cluster.
Later in the simulation some of the atoms escaped the initial cluster and flew outward separately.
\section{Simulation with the Berendsen Thermostat}
\begin{comment}
computational complexity
why on2
optimization not every force is looked at individually as the force resluting form this atom is the same for the other atom but negative
\end{comment}
After incorporating the Berendsen thermostat into the code it is interesting to look at the computational complexity of the simulation.
With growing numbers of atoms the computation-time should grow quadratically.
The main source for this is the force-computation, as each interaction with all the other atoms in the simulation has to be computed. This is also shown in the next figure as the computation time seems to follow a quadratic function.

\begin{figure}
	\begin{center}
		\includegraphics[scale=1]{Figure/plotAtomTimesM5.png}
	\end{center}
	\caption[Comparison of the time needed to simulate 8 to 192 Atoms]{Comparison of the time needed to simulate 8 to 192 Atoms. The simulation was run with the parameters $\sigma, \epsilon = 1$ , $m = 12~\mathrm{u}$ for a total of 10000 steps with a duration of each $\mathrm{timestep}$ being $0.01\sqrt{(m\sigma^2)/\epsilon} $. The relaxationtime of the thermostat was set to 50 $\mathrm{timestep} $, which is very low, but was done to get the simulation stable in all cases. The thermostat had a target-temperature of 275 (as a value).}
	\label{PlotSimulationTimeBerendsenThermostat}
\end{figure}

Although all the interaction between the atoms are computed, the individual forces do not carry the same weight to the force that affects the atom. It should be rather clear that, the further atoms are apart, the smaller the forces get. After a certain distance it gets so small that it can be ignored. This leads to the idea to use neighborhood-lists that ignore the atoms outside of a certain radius. It has been done in the next section.

\section{Simulation with the Neighborhood-List}
\begin{comment}

\end{comment}
After running the simulation in the previous section, it was clear that they follow a computational complexity of the order O(N²). This can be reduced to a linear order O(N) with the usage of neighborhood-lists. Only the atoms in a certain radius around the atom will be considered and a force will be added to the total force affecting the atom. This can be seen in Fig. \ref{PlotSimulationTimesCutoffNew}.
\begin{figure}
	\begin{center}
		\includegraphics[scale=1.25]{Figure/plotAtomTimesM6.png}
	\end{center}
	\caption[Comparison of the simulationtime with neighborhood-lists ]{Comparison of the simulationtime with Neighborhood-lists. Basic parameters are the same as in Fig. \ref{PlotSimulationTimeBerendsenThermostat}, but with an additional cutoff of 2.5$\sigma$.}
	\label{PlotSimulationTimesCutoffNew}
\end{figure}

\section{Simulation with the Embedded-Atom Method Potential}
\begin{comment}
1 graph
- potential energy gets less with an increase to the clustersize
- the

2
Heat capacity and latent heat should converge
\end{comment}
In the next step the embedded-atom method was used to compute the potential energy and the forces between the atoms.
A neighborhood-list was also used.
With this it was possible to look at the actual physical properties(meltingpoint, latent heat, heat capacity) of the different materials - in this case gold.

\par
%hard to get sim right quite the hassle
%We now look at the steps to get good data from the simulation.
%get the units right fix to time unit
First we have to get the units right. In the simulations beforehand, we simulated in Lenard-Jones units.
Here we will use real units.
This means for the timestep fs, for the distance \r{A}, for the mass u and for the energy eV.
We have to fix either the mass unit (mass of gold is 196.97u \cite{Kurzweil2015}) or the time unit.
The later was chosen. To get to a timestep of 1 fs we have to consider the expression $ [m] = [E][t]^2/[l]^2 = 1.6\mathrm{E}-19 * 1\mathrm{E}-30/1\mathrm{E}-20~\mathrm{kg} = 1.6\mathrm{E}-29~\mathrm{kg} $. For the final result we have to divide the mass of gold by the factor $ f = 1.6\mathrm{E}-29/\mathrm{u} = 0.009635 $
\cite{molDymCourse}.

%stettled on 3 steps: preheating, waiting vor a time after switching sim off -> diagram looks nicer
In the next step it is necessary to come up with a scheme to acquire good data.
For this it is very helpful to look at the kinetic energy in relation to time.
This is shown in Fig. \ref{GoldClusterSimulationKinVsTime}.
When the temperature is being increased via rescaling of the kinetic energy, we pump energy into the system.
If we do this at temperatures, that are too low, the cluster is unstable and will start pulsing.
So in the first step of the simulation we preheat the cluster via a thermostat to 300~K.
After this is done, we stop using the thermostat, as it would interfere with the measurement.
Now we could start to heat up the system and obtain the data for the next figures. But it has been rather helpful to wait for a bit after the thermostat is switched off. In doing so, we can obtain smoother graphs and data.
\par
%TODO not sure if nesessary lol
%heat up with 5e-3 eV per step
We heat the system up for a total of 50000 steps. Then we wait for 1000 steps after switching of the thermostat.
After that we start to heat up the system for a total of 120 times and deposit 5e-3~eV per Atom.
In one of these steps, we run the simulation for a total of 6000 times and record the temperature in the later half.
Then the average temperature is recorded.
The exact number of steps were practically determined via small experiments that were scaled up.
%Dude i dont know my own code
\begin{figure}
	%Higher than 9 just nicer to look at!!!
	\begin{center}
		\includegraphics[scale=1.15]{/home/cm/CLionProjects/MDCode/AData/Clusters/kineticEnergyCurve14.png}
	\end{center}
	\caption[Gold cluster simulation: Kinetic Energy vs Time]{Gold cluster simulation: Kinetic energy vs time for 10179 Atoms}
	\label{GoldClusterSimulationKinVsTime}
\end{figure}

\par
In Fig.  \ref{GoldClusterSimulationTemperaturEnergy4In1} energy and temperature for different cluster sizes are plotted.
It is possible to extract the melting point, the heat-capacity and the latent-heat from this diagram.
This can be seen in the next Fig.\ref{GoldClusterSimulationVsClustersize} in relation to the size of the atom-cluster.
\par
The first interesting property is the melting point of the cluster. It can be seen in the different curvatures in the graphs in figure \ref{GoldClusterSimulationTemperaturEnergy4In1} (for the red graph at 900~K for example).
The melting point increases as the clusters get bigger.
But it is still not near it's macroscopic equivalent of 1337~K \cite{Kurzweil2015}. %TODO this was converted but i think its ok
\par
It can also be seen that the potential energy of the average atom decreases with bigger clustersizes.
To explain this, the ratio of surface to volume of the cluster and the fact that atoms at the border of the cluster need to have a higher energy, have to be considered.
With increased clustersizes a smaller percentage of atoms is at the edge, which leads to an increases in the total energy of the cluster.
The slope of the jump at the melting point also grows with bigger clustersizes.
For many atoms these curves would be piecewise linear with a high-slope section around the melting point.
The simulated system seems to converge to that.

\begin{figure}
	\begin{center}
		\includegraphics[scale=1.15]{/home/cm/CLionProjects/MDCode/AData/Clusters/temperaturPotentialEnergyCurveMoreInOne.png}
	\end{center}
	\caption[Gold cluster simulation]{Gold cluster simulation with different quantities of atoms with a cutoff-distance of 10~\r{A}}
	\label{GoldClusterSimulationTemperaturEnergy4In1}
\end{figure}

In the diagram of Fig. \ref{GoldClusterSimulationVsClustersize} which plots the heat capacity and the latent heat, it can be seen that both seem to converge. On the other hand, the melting point still seems to increase as it is still away from it's true melting point.

\begin{figure}
	\begin{center}
		\includegraphics[scale=1.15]{/home/cm/CLionProjects/MDCode/AData/Clusters/VsClusterSizeAll.png}
	\end{center}
	\caption[Melting point, heat capacity and latent heat vs clustersize]{Melting point, heat capacity and latent heat vs clustersize}
	\label{GoldClusterSimulationVsClustersize}
\end{figure}


% Chapter Template

\chapter{Classification Algorithms} % Main chapter title

\label{Chapter4} % Change X to a consecutive number; for referencing this chapter elsewhere, use \ref{ChapterX}

\lhead{\emph{Classification Algorithms}} % Change X to a consecutive number; this is for the header on each page - perhaps a shortened title

%----------------------------------------------------------------------------------------
%	SECTION 1
%----------------------------------------------------------------------------------------

Machine learning algorithms are the fundamental of all classification program.
These algorithms are divided in two big families: the supervised learning and the unsupervised learning.
In this project only supervised learning models are used.
This section presents briefly the classification algorithms used in this work.
\section{Naïve Bayes classifier}
A Naïve Bayes classifier\cite{website:Naive_Bayes_classifier} is a simple probabilistic classifier based on applying Bayes' theorem (from Bayesian
statistics) with strong (naive) independence assumptions.
In simple terms, a naive Bayes classifier assumes that the presence (or absence) of a particular feature of a class is unrelated to the presence (or absence) of any other feature.
Depending on the precise nature of the probability model, naive Bayes classifiers can be trained very efficiently in a supervised learning setting.

\subsection{The Naïve Bayes probabilistic model}
Abstractly, the probability model for a classifier is a conditional model.
$$ P(C|F_1, \cdots, F_n) $$

Over a dependent class variable $C$ with a small number of outcomes or $classes$, conditional on several feature
variables $F_1$ through $F_n$ . The problem is that if the number of features $n$ is large or when a feature can take on a
large number of values, then basing such a model on probability tables is infeasible. Therefore the
model is formulated to make it more tractable using Bayes' theorem:
$$ P(C|F_1, \cdots, F_n) = \frac{p(C)p(F_1, \cdots, F_n|C)}{p(F_1, \cdots, F_n)}$$  The equation could be formulated as follow in a literal way $$posterior = \frac{prior * likelihood}{evidence}$$

%----------------------------------------------------------------------------------------
%	SECTION 2
%----------------------------------------------------------------------------------------

\section{Support Vector Machine}
A Support Vector Machine (SVM) is a discriminative classifier formally defined by a separating hyperplane. In other words, given labeled training data (supervised learning), the algorithm outputs an optimal hyperplane which categorizes new examples.
The figure \ref{fig:hyperplane} shows an example for a linearly separable set of 2D-points which belong to one of two classes.
\begin{figure}[H]
  \centering
  \includegraphics[width=60mm]{figures/optimal-hyperplane.png}
  \caption{Optimal hyperplane \label{fig:hyperplane}}
\end{figure}
The optimal hyperplane computedusing equation \ref{eq:hyperplane}:

\begin{equation}
\label{eq:hyperplane}
f(x) = \beta_{0} + \beta^{T} x
\end{equation}
Where $\beta$ is known as the weight vector and $\beta_{0}$ as the bias.

%----------------------------------------------------------------------------------------
%	SECTION 3
%----------------------------------------------------------------------------------------

\section{Maximum Entropy}
The maximum entropy classifier estimates probabilities
based on the principle of making as few
assumptions as possible, other than the constraints
imposed. Such constraints are derived from training
data, expressing some relationship between features
and outcome. The probability distribution
that satisfies the above property is the one with
the highest entropy. It is unique, agrees with the
maximum-likelihood distribution, and has the exponential
form :

\begin{equation}
\label{eq:maxent}
p(o|h) = \frac{1}{Z(h)}\prod_{j=1}^k\alpha_j^{f_j(h,o)}
\end{equation}

Where:
\begin{itemize}
\item $o$ refers to the outcome
\item $h$ refers to the history or context.
\item $Z(h)$ is a normalization function.
\item $f_j(h,o)$ is a binary function.
\item $\alpha_j$ is estimated by a procedure called Generalized Iterative Scaling (GIS). This is an iterative method that improves the estimation of the parameters at each iteration.
\end{itemize}


\problemname{Driving Lanes}

While driving around a curve on the highway, Sam realizes that if they
use the inside lane, they travel a shorter distance. Sam wonders what
is the minimum distance needed to travel to the destination.
%across the entire highway.

The multilane highway consists of a sequence of straightaways that are
connected by curves. When going around a curve, the distance travelled
depends on which lane you are in. Each curve has a curvature $c$ and
stretch $s$. Specifically, if Sam is in lane $i$, then they travel
$s + c \cdot i$ meters while going around this curve.

Whenever Sam is on a straightaway, they may change from one lane into
an adjacent lane.  When changing to an adjacent lane, Sam moves
forward $k$ meters, but travels a total of $k+r$ meters.  Each lane
change must be completed before the car reaches the end of the current
straightaway.  Sam may change lanes multiple times in the same
straightaway. For safety reasons, changing lanes is not possible on
curves.

\begin{center}
 \includegraphics[width=0.8\textwidth]{chla.pdf}
\end{center}

Sam starts in lane $1$ and wishes to end in lane $1$. What is the minimum
distance they must travel?

\section*{Input}

The first line of input contains two integers
$n$~($1 \leq n \leq 250$), which is the number of straightaways, and
$m$~($1 \leq m \leq 250$), which is the number of lanes on the
highway. The lanes are numbered $1, 2, \dots, m$.

The second line of input contains two integers
$k$~($1 \leq k \leq 10^6$) and $r$~($1 \leq r \leq 10^6$), which are
the lane changing parameters.

The next $n$ lines describe the straightaways in order. Each of these lines
contains a single integer $\ell$~($1 \leq \ell \leq 10^6$), which is
the length of this straightaway.

The next $n-1$ lines describe the curves in order. Each of these lines contains
two integers $s$~($1 \leq s \leq 10^6$), which is the stretch of
this curve, and $c$~($-10^6 \leq c \leq 10^6$), which is the curvature of
this curve. It is guaranteed that $s + c \cdot m > 0$.

The $i$th curve connects the $i$th and $(i+1)$th straightaway.

\section*{Output}

Display the minimum distance Sam must travel.


%%%%this file inputes all section-02-*.tex files.
\chapter{Overview of various smoothers}
A scatter plot smoother is a tool for finding structure in a scatter
plot: $(x_1,y_1),\dots,(x_n,y_n)$

\begin{figure}[htp]
\caption{\label{f2.1} CD4 cell count since seroconversion for HIV
  infected men.}
\centerline{\epsfig{figure=Plots/plot-02-01.ps,angle=270,width=.8\textwidth}}
\end{figure}

\begin{itemize}
\item Suppose that we consider $\by = (y_1,\dots,y_n)'$ as the {\it response
measurements} and $\bx = (x_1,\dots,x_n)'$ as the {\it design points}.

\item We can think of $\bx$ and $\by$ as outcomes of random variable $X$
and $Y$. However, for scatter plot smoothers we don't
really need stochastic assumptions, it can be considered as a
descriptive tool.

\item A scatter plot smoother can be defined as a function (remember
  the general definition of {\it function}) of $\bx$ and
$\by$ with domain at least containing the values in $\bx$: $s =
\bS[\by | \bx]$.

\item There is usually a ``recipe'' that gives $s(x_0)$, which is the function
$\bS[\by | \bx]$ evaluated at $x_0$,  for all $x_0$. We will be
calling $x_0$ the {\it target value} when we giving the recipe. Note:
Some recipes don't give an $s(x_0)$ for all $x_0$, but only for the
$x$'s included in $\bx$.

\end{itemize}

Note we will call the vector $\{s(x_1),\dots,s(x_n)\}'$ as {\it the smooth}.

Here is a stupid example: If we assume a random desing model and take
expectations over the empirical distribution $\hat{F}$, defined by the
observations, we have for any $x_0 \in \{x_1,\dots,x_n\}$,
\[
E_{\hat{F}}[Y|X=x_0] = \ave \{ y_i; x_i = x_0\}.
\]
Define $s(x_0)=\E_{\hat{F}}[Y|X=x_0]$. What happens if the $x_i$ are
unique?

Since $Y$ and $X$ are, in general,  non-categorical we don't expect to
find many replicates at any given value of $X$. This means that we
could end up with the data again, $s(x_0)=y_0$ for all $x_0$. Not very
smooth!

Note: For convenience, through out this chapter,  we assume that the
data are sorted by $X$.

Many smoothers force  $s(x)$ to be a smooth function of $x$. This is
a fancy way of saying we think data points that are close (in $x$)
should have roughly the same expectation.

\newpage

\input{section-02-01}

\newpage

\input{section-02-02}

\newpage

\input{section-02-03}

\input{section-02-04}

\input{section-02-05}


\documentclass{article}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{amsmath}

\usepackage{Sweave}
\begin{document}
\input{sweave_example-concordance}

%------------------------------------------------------------
\title{An example Sweave document}
\author{Eli Holmes}
\maketitle
%------------------------------------------------------------

This is a super simple template to show you how to use Sweave to combine LaTeX with R code and create a PDF. Google 'Sweave tutorial' or 'LaTeX tutorial' to learn more about Sweave and LaTeX.  You will need LaTeX installed.  Mac users should have this already installed.  PC users will need to install MikTeX (and then talk to Eli to get it set up properly).

\section*{Problem 1}
%The * tells LaTeX not to number the sections

This is my solution to problem 1: add together 2 numbers. I decided to do $1+1$. It was not very hard.
\begin{Schunk}
\begin{Sinput}
> 1+1
\end{Sinput}
\begin{Soutput}
[1] 2
\end{Soutput}
\end{Schunk}

\section*{Problem 2}

This question asked me to add together the numbers 1 to 9, so $\sum_{i=1}^9 i$. This question was also easy.

\begin{Schunk}
\begin{Sinput}
> sum(1:9)
\end{Sinput}
\begin{Soutput}
[1] 45
\end{Soutput}
\end{Schunk}

\section*{Problem 3}

Use the \verb@lm@ function to do a linear regression using the example in \verb@?lm@.

\begin{Schunk}
\begin{Sinput}
> ## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
> ## Page 9: Plant Weight Data.
> ctl = c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
> trt = c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
> group = gl(2, 10, 20, labels = c("Ctl","Trt"))
> weight = c(ctl, trt)
> lm.D9 = lm(weight ~ group)
\end{Sinput}
\end{Schunk}

We can use \verb@summary@ to get a summary. Figure \ref{fig:summarylm} shows the 4 figures that plotting a lm object produces.

\begin{Schunk}
\begin{Sinput}
> summary(lm.D9)
\end{Sinput}
\begin{Soutput}
Call:
lm(formula = weight ~ group)

Residuals:
    Min      1Q  Median      3Q     Max
-1.0710 -0.4938  0.0685  0.2462  1.3690

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   5.0320     0.2202  22.850 9.55e-15 ***
groupTrt     -0.3710     0.3114  -1.191    0.249
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared:  0.07308,	Adjusted R-squared:  0.02158
F-statistic: 1.419 on 1 and 18 DF,  p-value: 0.249
\end{Soutput}
\end{Schunk}

\section*{Problem 4}

Use \verb@plot()@to get diagnostic plots.  This is the code I used:
%just show code but don't evaluate here.
\begin{Schunk}
\begin{Sinput}
> #set the par to 4x4 figure and then set back at the end
> opar <- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0))
> plot(lm.D9, las = 1)      # Residuals, Fitted, ...
> par(opar)
\end{Sinput}
\end{Schunk}
The figure generated by this is in Figure \ref{fig:summarylm}.

% The first bit is the set up of a figure in LaTeX and the middle bit is the code that makes the figure. The [h] says to place the figure "here" approximately. [t] is top. [b] is bottom. Notice I pass in echo=FALSE so that the code doesn't show up.
\setkeys{Gin}{width=5in}
\begin{figure}[h]
\begin{center}
\includegraphics{sweave_example-summary_plot}
\end{center}
\caption{This is a summary of the linear regression.}
\label{fig:summarylm}
\end{figure}
\setkeys{Gin}{width=\textwidth}

\section*{Problem 5}
The last problem asked me to write a function to do $$\sqrt{b^2 - 4ac}$$.

\begin{Schunk}
\begin{Sinput}
> myfun = function(a,b,c){return(sqrt(b^2-4*a*c))}
> myfun(1,3,1)
\end{Sinput}
\begin{Soutput}
[1] 2.236068
\end{Soutput}
\end{Schunk}

\section*{Problem 6}

This problem asked me to write out a matrix equation $\mathbf{A}\mathbf{B}$ with $\mathbf{A}$ as a $3 \times 2$ matrix and $\mathbf{B}$ as a $2 \times 2$ matrix.  I chose this equation:
$$
\mathbf{A}\mathbf{B}=
\begin{bmatrix} 1 & 4\\ 2 & 5 \\ 3 & 6\end{bmatrix}
\begin{bmatrix} 3 & 0 \\ 0 & 3 \end{bmatrix}
$$
Here's my R code:

\begin{Schunk}
\begin{Sinput}
> A=matrix(1:6,3,2)
> B=diag(3,2)
> A%*%B
\end{Sinput}
\begin{Soutput}
     [,1] [,2]
[1,]    3   12
[2,]    6   15
[3,]    9   18
\end{Soutput}
\end{Schunk}

\end{document}


\clearpage %or \cleardoublepage
\phantomsection
\chapter*{Notation}
\markright{}
\addcontentsline{toc}{chapter}{Notation}

\begin{longtable}[l]{ l p{0.85\textwidth} }
  $a=\cfrac{dC_L}{d \alpha}$                   & [1/rad] lift curve slope \\
  $A=\cfrac{b^2}{S}$                           & [-] wing aspect ratio \\
  $b$                                          & [m] wing span \\
  $c_r$                                        & [m] chord at wing root \\
  $c_t$                                        & [m] chord at wing tip \\
  $\hat c$, $MAC$                              & [m] mean aerodynamic chord \\
  $C_D$                                        & [-] drag coefficient \\
  $C_l$                                        & [-] rolling moment coefficient \\
  $C_L$                                        & [-] lift coefficient \\
  $C_m$                                        & [-] pitching moment coefficient \\
  $C_n$                                        & [-] yawing moment coefficient \\
  $C_Y$                                        & [-] side force coefficient \\
  $C_{\mu}$                                    & [-] k-$\varepsilon$ turbulence model constant \\
  $d$                                          & [m] fuselage diameter \\
  $D$                                          & [N] drag \\\
  $e$                                          & [-] Oswald efficiency factor \\
  $i$                                          & [rad] incidence angle \\
  $I$                                          & [-] turbulence intensity \\
  $k$                                          & [m\textsuperscript{2}/s\textsuperscript{2}] turbulence kinetic energy \\
  $L$                                          & [N] lift \\
  $L$                                          & [m] reference length scale \\
  $p$                                          & [Pa] pressure \\
  $Re$                                         & [-] Reynolds number \\
  $S$                                          & [m\textsuperscript{2}] wing area \\
  $V$                                          & [m/s] velocity \\
  $\alpha$                                     & [rad] angle of attack \\
  $\beta$                                      & [rad] angle of sideslip \\
  $\lambda=\cfrac{c_t}{c_r}$                   & [-] wing taper ratio \\
  $\Lambda_{LE}$                               & [rad] leading edge sweep angle \\
  $\Lambda_{t/c}$                              & [rad] sweep angle at maximum thickness \\
  $\omega$                                     & [1/s] specific turbulence dissipation rate \\
  $\cfrac{\partial \epsilon}{\partial \alpha}$ & [-] horizontal stabilizer downwash angle derivative with respect to the aircraft angle of attack \\
\end{longtable}