\section{Calculation}

We start on the $E_2$ page.
On the zeroth column, we get only the cohomology of $U(2)$, hence we at least see

\adjustbox{scale=0.9, center}{
\begin{tikzcd}[column sep=small]
4 & a_1a_3 &   &   &   &   &   &   &   &   \\
3 & a_3    &   &   &   &   &   &   &   &   \\
2 & 0      &   &   &   &   &   &   &   &   \\
1 & a_1    &   &   &   &   &   &   &   &   \\
0 & 1      &   &   &   &   &   &   &   &   \\
  & 0      & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8
\end{tikzcd}
}

Since we know that $H^*(V_2(\mathbb{C}^4))$ has no elements in degree $1$,
we know that $H^2(G_2(\mathbb{C}^4))\cong H^1(V_2(\mathbb{C}^4))$,
as the generator $a_1$ has to be killed by a differential.
Call the generator for the group $H^2(G_2(\mathbb{C}^4))$ that is the image of $a_1$ for $x$.
By multiplications by the other generators and itself we then know we have

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 & a_1a_3                   &   & a_1a_3x &   & a_1a_3x^2 &   & a_1a_3x^3 &   & a_1a_3x^4 \\
3 & a_3                      &   & a_3x    &   & a_3x^2    &   & a_3x^3    &   & a_3x^4    \\
2 &                          &   &         &   &           &   &           &   &           \\
1 & a_1 \arrow[rrd, "\cong"] &   & a_1x    &   & a_1x^2    &   & a_1x^3    &   & a_1x^4    \\
0 & 1                        &   & x       &   & x^2       &   & x^3       &   & x^4       \\
  & 0                        & 1 & 2       & 3 & 4         & 5 & 6         & 7 & 8
\end{tikzcd}
}

We know that the differential is a derivation,
hence we get that $d_2(a_1x)=d_2(a_1)x+(-1)^{|x|}a_1d_2(x) = d_2(a_1)x = x^2$ since $d_2(x)=0$.
The same calculation for higher powers of $x$ and for $a_1a_3$ and $a_1a_3x$,
gives us isomorphisms all the way to the right

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 & a_1a_3 \arrow[rrd, "\cong"] &   & a_1a_3x \arrow[rrd, "\cong"] &   & a_1a_3x^2 \arrow[rrd, "\cong"] &   & a_1a_3x^3 \arrow[rrd, "\cong"] &   & a_1a_3x^4 \\
3 & a_3                         &   & a_3x                         &   & a_3x^2                         &   & a_3x^3                         &   & a_3x^4    \\
2 &                             &   &                              &   &                                &   &                                &   &           \\
1 & a_1 \arrow[rrd, "\cong"]    &   & a_1x \arrow[rrd, "\cong"]    &   & a_1x^2 \arrow[rrd, "\cong"]    &   & a_1x^3 \arrow[rrd, "\cong"]    &   & a_1x^4    \\
0 & 1                           &   & x                            &   & x^2                            &   & x^3                            &   & x^4       \\
  & 0                           & 1 & 2                            & 3 & 4                              & 5 & 6                              & 7 & 8
\end{tikzcd}
}

Here we see a problem.
The generator $a_3$ never gets killed by a differential,
but the cohomology of $V_2(\mathbb{C}^4))$ has no elements in degree $3$,
so it cant survive.
The only degree a differential starting from $a_3$ can land in is $4$,
and the only possible non-zero cohomology in degree 4 comes from $H^4(G_2(\mathbb{C}^4))$,
which by the likes of it so far has already been killed by a $d_2$ differential.
Hence we got to have a $d_4$ differential hitting another generator in $H^4(G_2(\mathbb{C}^4))$,
hence we need higher dimensional cohomology in this degree.
We call this new generator which is the image of $a_3$ under the $d_3$ differential for $y$.
Looking back at the $E_2$ page, we then have new elements

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 & a_1a_3 \arrow[rrd, "\cong"] &   & a_1a_3x \arrow[rrd, "\cong"] &   & {a_1a_3x^2, a_1a_3y} \arrow[rrd, "\cong"] &   & {a_1a_3x^3, a_1a_3xy} \arrow[rrd, "\cong"] &   & {a_1a_3x^4, a_1a_3y^2} \\
3 & a_3                         &   & a_3x                         &   & {a_3x^2, a_3y}                            &   & {a_3x^3, a_3xy}                            &   & {a_3x^4, a_3y^2}       \\
2 &                             &   &                              &   &                                           &   &                                            &   &                        \\
1 & a_1 \arrow[rrd, "\cong"]    &   & a_1x \arrow[rrd, "\cong"]    &   & {a_1x^2, a_1y} \arrow[rrd, "\cong"]       &   & {a_1x^3, a_1xy} \arrow[rrd, "\cong"]       &   & {a_1x^4, a_1y^2}       \\
0 & 1                           &   & x                            &   & {x^2, y}                                  &   & {x^3, xy}                                  &   & {x^4, y^2}             \\
  & 0                           & 1 & 2                            & 3 & 4                                         & 5 & 6                                          & 7 & 8
\end{tikzcd}
}

Now, what does this new information and new elements give us?
By the same calculation as previously, we get that $d_2(a_1y) = xy$,
but here have more information.
We know that $H^*(V_2(\mathbb{C}^4))$ has a generator in degree $5$,
and this new generator $a_1y$ is the only generator left in total degree $5$ in the spectral sequence.
Thus it can't die by a $d_2$ differential.
And since it's image is $xy$, this image has to be zero, which gives us the first of two relations on the cohomology ring of our Grassmannian, namely $xy=0$.
Hence, as far as we know so far, our $E_2$ page looks like this:

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 & a_1a_3 \arrow[rrd, "\cong"] &   & a_1a_3x \arrow[rrd, "\cong"] &   & {a_1a_3x^2, a_1a_3y} \arrow[rrd, "\cong"] &   & a_1a_3x^3 \arrow[rrd, "\cong"] &   & {a_1a_3x^4, a_1a_3y^2} \\
3 & a_3                         &   & a_3x                         &   & {a_3x^2, a_3y}                            &   & a_3x^3                         &   & {a_3x^4, a_3y^2}       \\
2 &                             &   &                              &   &                                           &   &                                &   &                        \\
1 & a_1 \arrow[rrd, "\cong"]    &   & a_1x \arrow[rrd, "\cong"]    &   & {a_1x^2, a_1y} \arrow[rrd, "\cong"]       &   & a_1x^3 \arrow[rrd, "\cong"]    &   & {a_1x^4, a_1y^2}       \\
0 & 1                           &   & x                            &   & {x^2, y}                                  &   & x^3                            &   & {x^4, y^2}             \\
  & 0                           & 1 & 2                            & 3 & 4                                         & 5 & 6                              & 7 & 8
\end{tikzcd}
}

As far as I'm aware, we can't squeeze any more information out of the $E_2$ page yet.
Let us pass to the $E_3$ page and see which generator we are left with after all the isomorphisms kill the generators.
We have

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 &     &   &   &   & a_1a_3y &   &   &   & {a_1a_3y^2} \\
3 & a_3 &   &   &   & a_3y    &   &   &   & a_3y^2                 \\
2 &     &   &   &   &         &   &   &   &                        \\
1 &     &   &   &   & a_1y    &   &   &   & {a_1y^2}       \\
0 & 1   &   &   &   & y       &   &   &   & y^2                    \\
  & 0   & 1 & 2 & 3 & 4       & 5 & 6 & 7 & 8
\end{tikzcd}
}

and we see that all the $d_3$ differentials either start or land in places which are zero,
hence $E_3 = E_4$. On the $E_4$ page however,
we know that we at least have one differential,
namely the one we used to justify the generator $y$'s existence.
By the derivation property of the differentials,
we also get that $d_4(a_1a_3y)=a_1y^2$,
hence we at least have an $E_4$ page looking like

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 &                              &   &   &   & a_1a_3y \arrow[rrrrddd, "\cong"] &   &   &   & a_1a_3y^2 \\
3 & a_3 \arrow[rrrrddd, "\cong"] &   &   &   & a_3y                             &   &   &   & a_3y^2    \\
2 &                              &   &   &   &                                  &   &   &   &           \\
1 &                              &   &   &   & a_1y                             &   &   &   & a_1y^2    \\
0 & 1                            &   &   &   & y                                &   &   &   & y^2       \\
  & 0                            & 1 & 2 & 3 & 4                                & 5 & 6 & 7 & 8
\end{tikzcd}
}

We are also lucky enough to know that $H^*(V_2(\mathbb{C}^4))$ has a generator in degree $7$,
which we see is $a_3y$ since it is the only one left in the correct total degree.
But what happens to the differential $d_4(a_3y) = y^2$ you ask? Do we have $y^2=0$ then,
same as last time?
Actually, no.
Since we know that $a_1y$ and $a_3y$ both are non-zero generators in $H^*(V_2(\mathbb{C}^4))$,
their product $a_1a_3y^2$ is also a generator in degree $12$,
hence it has to be non-zero,
and then $y^2$ has to be non-zero in $H^8(G_2(\mathbb{C}^4))$.
But, it still has to die in the spectral sequence though,
and the solution is the second relation on the cohomology ring,
namely $x^4=y^2$.
This ensures that $y^2$ is already killed on the $E_2$ page,
and hence that $a_3y$ isn't killed on the $E_4$ page.

To retrospectively correct some things now that we have all the information,
we first note that we were lucky we didn't bother writing more that $8$ columns,
because everything in row $0$ and columns above $8$ either is a product of $x$'s and $y$'s,
or contain powers of $x$ greater or equal to $5$ or powers of $y$ greater or equal to $3$,
making $x^5 = xx^4=xy^2=(xy)y=0$ and $y^3=yx^4=0$.
Hence our generators $a_1x^4$ and $a_1a_3x^4$ never was killed by any $d_2$ differentials,
since their images are $x^5=0$ and $a_3x^5=0$ respectively.
Hence we still have $a_1x^4=a_1y^2$ and $a_1a_3x^4=a_1a_3y^2$ on the $E_4$ page.
Also, we get that $a_3x^4=a_3y^2$,
which means that $a_3y^2$ was killed by a $d_2$ differential on the $E_2$ page,
and hence it does not show up on the $E_4$ page.
The final form of the $E_2$ page is then

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 & a_1a_3 \arrow[rrd] &   & a_1a_3x \arrow[rrd] &   & {a_1a_3x^2, a_1a_3y} \arrow[rrd] &   & a_1a_3x^3 \arrow[rrd] &   & a_1a_3x^4=a_1a_3y^2 \\
3 & a_3                &   & a_3x                &   & {a_3x^2, a_3y}                   &   & a_3x^3                &   & a_3x^4=a_3y^2       \\
2 &                    &   &                     &   &                                  &   &                       &   &                     \\
1 & a_1 \arrow[rrd]    &   & a_1x \arrow[rrd]    &   & {a_1x^2, a_1y} \arrow[rrd]       &   & a_1x^3 \arrow[rrd]    &   & a_1x^4=a_1y^2       \\
0 & 1                  &   & x                   &   & {x^2, y}                         &   & x^3                   &   & x^4=y^2             \\
  & 0                  & 1 & 2                   & 3 & 4                                & 5 & 6                     & 7 & 8
\end{tikzcd}
}

and the final form of the $E_4$ page is

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 &                              &   &   &   & a_1a_3y \arrow[rrrrddd, "\cong"] &   &   &   & a_1a_3y^2 \\
3 & a_3 \arrow[rrrrddd, "\cong"] &   &   &   & a_3y                             &   &   &   &           \\
2 &                              &   &   &   &                                  &   &   &   &           \\
1 &                              &   &   &   & a_1y                             &   &   &   & a_1y^2    \\
0 & 1                            &   &   &   & y                                &   &   &   &           \\
  & 0                            & 1 & 2 & 3 & 4                                & 5 & 6 & 7 & 8
\end{tikzcd}
}

Since all higher degree differentials,
i.e. $d_5$ and above miss any generators due to being too long,
we have $E_5=E_{\infty}$.
We can also see this because we have arrived at the correct cohomology ring for $V_2(\mathbb{C}^4)$,
namely the final page

\adjustbox{scale=0.8, center}{
\begin{tikzcd}[column sep=small]
4 &   &   &   &   &      &   &   &   & a_1a_3x^4=a_1a_3y^2 \\
3 &   &   &   &   & a_3y &   &   &   &                     \\
2 &   &   &   &   &      &   &   &   &                     \\
1 &   &   &   &   & a_1y &   &   &   &                     \\
0 & 1 &   &   &   &      &   &   &   &                     \\
  & 0 & 1 & 2 & 3 & 4    & 5 & 6 & 7 & 8
\end{tikzcd}
}

Hence we are done,
and we have found the correct cohomology ring for our Grassmannian $G_2(\mathbb{C}^4)$.
By all our extensive calculations and work,
we finally can say that $H^*(G_2(\mathbb{C}^4)) = \mathbb{Z}(x,y)/(xy, x^4-y^2)$ or if we add the degrees into the names of the generators,
$H^*(G_2(\mathbb{C}^4)) = \mathbb{Z}(a_2, a_4)/(a_2a_4, a_2^4-a_4^2)$.
Hence the calculation is finished, and we are done.


\section{The \sortheap algorithm}
\Label{sec:sortheap}

Whereas in the \cxx Standard Library \cite[\S 28.7.7.4]{cxx-17-draft}
\sortheap works on a range of random access iterators,
our version operates on an array of \valuetype.
We therefore use the following signature for \sortheap

\begin{lstlisting}[style = acsl-block]

    void sort_heap(value_type* a, size_type n);
\end{lstlisting}

The function \sortheap rearranges the elements of a given heap \inl{a[0..n-1]}
in increasing order.
Thus, applying \sortheap to the heap in Figure~\ref{fig:heap-array}
produces the increasing array in Figure~\ref{fig:sortheap-array-post}.

\begin{figure}[hbt]
\centering
\includegraphics[width=0.65\linewidth]{Figures/sort_heap_array_post.pdf}
\caption{\Label{fig:sortheap-array-post}Array after the call of \sortheap}
\end{figure}

\FloatBarrier

\subsection{Formal specification of \sortheap}

The following listing shows our specification of \sortheap.
The formal specification of \sortheap must ensure that the
resulting array is increasing.
Furthermore the multiset contained by the array must be the same
as in the pre-state of the function.
The postconditions \inl{increasing} and \inl{reorder} express these properties, respectively.
The specification effort is relatively simple because we can reuse

\input{Listings/sort_heap.h.tex}

\clearpage

\subsection{Implementation of \sortheap}

The implementation of \sortheap is relatively simple because it relies on
\specref{popheap} performing essential work.
Our implementation of \sortheap repeatedly calls \popheap
to extract the maximum of the shrinking heap and adding it
to the part of the array that is already in increasing order.
The loop invariants of \sortheap describe the content of the array
in two parts.
The first \inl{i} elements form a heap and are described by the \inl{heap}
invariant.
The last \inl{n-i} elements are already arranged in increasing order.

As already mentioned in the introduction of Chapter~\ref{cha:binary-search},
we use the predicate \logicref{WeaklyIncreasing} for the loop annotation \inl{increasing}.
Thus, after leaving the loop we have in fact ``only'' shown that \inl{WeaklyIncreasing(a, n)}
holds.
In order to derive from this fact the final assertion \inl{increasing} that uses
the predicate \logicref{Increasing} we rely on lemma \logicref{WeaklyIncreasingIncreasing}.

\input{Listings/sort_heap.c.tex}

To verify the property \inl{reorder} we rely on the lemmas \logicref{MultisetReorder}
that express that the properties

\begin{itemize}
\item \inl{MultisetReorder\{K,L\}(a, 0, i)} and
\item \inl{Unchanged\{Old,Here\}(a, i, n)}
\end{itemize}

imply the desired loop invariant \inl{MultisetReorder\{K,L\}(a, 0, n)}.

%\clearpage


\documentclass[12pt]{cdblatex}
\usepackage{examples}

\begin{document}

\section*{Curvature of a 2-sphere}

This examples uses standard methods to compute the scalar curvature of a 2-sphere.

\begin{cadabra}
   {\theta, \varphi}::Coordinate.
   {\alpha, \beta, \gamma, \delta, \rho, \sigma, \mu, \nu, \lambda}::Indices(values={\varphi, \theta}, position=independent).

   \partial{#}::PartialDerivative.

   g_{\alpha\beta}::Metric.
   g^{\alpha\beta}::InverseMetric.

   Chr := \Gamma^{\alpha}_{\mu\nu} -> 1/2 g^{\alpha\beta} (  \partial_{\nu}{g_{\beta\mu}}
                                                           + \partial_{\mu}{g_{\beta\nu}}
                                                           - \partial_{\beta}{g_{\mu\nu}} ).

   Rabcd := R^{\rho}_{\sigma\mu\nu} ->   \partial_{\mu}{\Gamma^{\rho}_{\sigma\nu}}
                                       - \partial_{\nu}{\Gamma^{\rho}_{\sigma\mu}}
                                       + \Gamma^{\rho}_{\beta\mu} \Gamma^{\beta}_{\sigma\nu}
                                       - \Gamma^{\rho}_{\beta\nu} \Gamma^{\beta}_{\sigma\mu}.

   Rab := R_{\sigma\nu} -> R^{\rho}_{\sigma\rho\nu}.

   R := R -> R_{\sigma\nu} g^{\sigma\nu}.

   gab:={ g_{\theta\theta}   = r**2,
          g_{\varphi\varphi} = r**2 \sin(\theta)**2 }.   # cdb(gab,gab)

   complete   (gab, $g^{\alpha\beta}$)                   # cdb(iab,gab)

   evaluate   (Chr, gab, rhsonly=True)                   # cdb(Chr,Chr)

   substitute (Rabcd, Chr)
   evaluate   (Rabcd, gab, rhsonly=True)                 # cdb(Rabcd,Rabcd)

   substitute (Rab, Rabcd)
   evaluate   (Rab, gab, rhsonly=True)                   # cdb(Rab,Rab)

   substitute (R, Rab)
   evaluate   (R, gab, rhsonly=True)                     # cdb(R,R)
\end{cadabra}

\begin{minipage}[t]{0.65\textwidth}
\begin{align*}
   &\cdb{iab}\\[10pt]
   &\cdb{Chr}\\[10pt]
   &\cdb{Rabcd}\\[10pt]
   &\cdb{Rab}\\[10pt]
   &\cdb{R}
\end{align*}
\end{minipage}
\hskip 1cm
\lower16pt\hbox{%
\begin{minipage}[t]{0.35\textwidth}
\begin{latex}
   \begin{align*}
      &\cdb{iab}\\[10pt]
      &\cdb{Chr}\\[10pt]
      &\cdb{Rabcd}\\[10pt]
      &\cdb{Rab}\\[10pt]
      &\cdb{R}
   \end{align*}
\end{latex}
\end{minipage}}

\end{document}


\chapter{Solomonoff theory}

Why was Raymond J. Solomonoff \cite{SolAlpProb2011, GacsVitanyiSolomonoff}
interested in predicting sequences of bits?

Marcus Hutter approached intelligence from \emph{algorithmic} complexity theory (Solomonoff induction)
\cite{DefineMachIntel}.
Warren D. Smith approached intelligence from \emph{computational} complexity theory
(NP-completeness)
\cite{WdsIntel, WdsIntelSlide}

\section{Generalization of Solomonoff theory}

Let \(\Bit = \{0,1\}\).
Let \(\Bits = \Bit^*\) where \(*\) is the Kleene star.
Let \(f : \Bits \to \Bits\).
Let \(p : \Bits \to [0,1]\) be the input distribution.
Define \(q~y\) as the probability of finding an input \(x\) such that \(f~x = y\).
Solomonoff used a universal Turing machine for \(f\),
but I'm interested on the consequences of relaxing this constraint.

Bijection allows us to use \(\Nat\) or any other countable set instead of \(\Bits\).
Let \(f : \Nat \to \Nat\) be a function.
We say that \emph{\(x\) \(f\)-explains \(y\)} iff \(f~x = y\).
Let \(p : \Nat \to [0,1]\) be the input distribution.
Define \(q~y\) as the probability of finding an \(x\) such that \(f~x = y\).
We call an input such as \(x\) a \emph{hypothesis}.

\newcommand\preimage{\fun{preimage}}

Let \(f\) be a binary relation.
We define \(\preimage~f~y = \{ x ~|~ f~x~y \}\).

\section{Generalizing Kolmogorov complexity}

Schmidh\"uber generalized Kolmogorov complexity to super Turing machines \cite{SchmidhuberKolmogorov}.

The Kolmogorov complexity of a string
is the length of the shortest program that generates that string.
This complexity depends on the machine.
Formally, we define \(\kolmogorov~f~y\),
the Kolmogorov complexity of \(y\) with respect to \(f\),
as the length of the shortest \(x\) that satisfies \(f~x = y\).

We can relax the constraint of \(f\) so that \(f\)
now only needs to be a surjective relation.
We can relax it further so that it is a relation.
However, if \(f\) is not surjective,
the Kolmogorov complexity will be partial
(undefined for some inputs).
That seems to be as general as logic allows.

We can relax the measure \(m : A \to \Real\) into a function \(m : A \to B\)
and an ordering \(c\).

\[
    \kolmogorov~c~m~f = \minimumBy~c \circ \map~m \circ \preimage~f
\]

Note the notation:
If \(f\) is a binary relation,
we overload the notation \(f\)
to also mean the binary predicate
that is the indicator function of the relation \(f\).
We conflate a predicate and its extension.
We write \(f~x~y\) to mean \((x,y) \in f\).
The type of the expression \(f~x~y\) is \(\Bool\).

We can generalize Kolmogorov complexity.
Instead of a space of strings and the length of strings,
we can use a measure space.
Furthermore, we can generalize the function into relation.
Let \(m : A \to \Real\) be a measure on \(A\).
Let \(f \subseteq A \times A\) be a binary relation.
Formally,
\[
    \kolmogorov~m~f~y = \minimum~(\map~m~(\preimage~f~y))
\]
or, more pointfreely,
\begin{equation}
    \kolmogorov~m~f = \minimum \circ \map~m \circ \preimage~f
\end{equation}

We define \(\kolmogorov~m~f~y\) as the measure of an \(x\)
that both minimizes \(m\) and satisfies \(f~x~y\).
Therefore \(\kolmogorov\) is a constrained optimization problem.
The classical Kolmogorov complexity is a special case of \(\kolmogorov\)
where \(m\) computes the length of a bitstring
and \(f\) is a universal Turing machine.

The Kolmogorov complexity is incomputable due to the halting problem.
It does not even have a brute-force algorithm.
However, Levin search allows us to approximate it.


\subsection{The Fisher equation}

The Fisher equation shows the relationship between the real and nominal interest rates.

\((1+i)=(1+r)(1+\pi )\)

For small values:

\(i\approx r+\pi \)


\documentclass[t]{beamer}
\usetheme{Copenhagen}
\setbeamertemplate{headline}{} % remove toc from headers
\beamertemplatenavigationsymbolsempty

\usepackage{amsmath, tikz, bm, tkz-euclide}
\usetkzobj{all}

\title{Trig Functions of Any Angle}
\author{}
\date{}

\AtBeginSection[]
{
  \begin{frame}
    \frametitle{Objectives}
    \tableofcontents[currentsection]
  \end{frame}
}

\begin{document}

\begin{frame}
\maketitle
\end{frame}

\begin{frame}{From Right Triangle Trig to the Coordinate Plane}
In this section, adjacent, opposite and hypotenuse
\begin{center}
\begin{tikzpicture}
    \tkzDefPoints{0/0/A, 3/0/C, 3/2/B}
    \tkzMarkRightAngle[color=red](A,C,B)
    \tkzDrawPolygon(A,B,C)
    \tkzLabelSegment[below](A,C){adjacent}
    \tkzLabelSegment[right](B,C){opposite}
    \tkzLabelSegment[above left](A,B){hypotenuse}
\end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}{From Right Triangle Trig to the Coordinate Plane}
become
\begin{center}
    \begin{tikzpicture}
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$x$};
    \draw [<->, >=stealth] (0,-3) -- (0,3) node [right] {$y$};
    \draw [color=red] (2.5,0) rectangle (2.25,0.25);
    \draw (0,0) -- (2.5,0) -- (2.5,2) -- cycle;
    \node at (1.25,0) [below] {$\bm{x}$};
    \node at (2.5,1) [right] {$\bm{y}$};
    \node at (1.25,1) [above] {$\bm{r}$};
    \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}{From Right Triangle Trig to the Coordinate Plane}
where $r$ represents the radius of the circle shown below.

\begin{center}
    \begin{tikzpicture}
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$x$};
    \draw [<->, >=stealth] (0,-3) -- (0,3) node [right] {$y$};
    \draw [color=red] (2.5,0) rectangle (2.25,0.25);
    \draw (0,0) -- (2.5,0) -- (2.5,2) -- cycle;
    \node at (1.25,0) [below] {$\bm{x}$};
    \node at (2.5,1) [right] {$\bm{y}$};
    \node at (1.25,1) [above] {$\bm{r}$};
    \draw [dashed] (0,0) circle (3.2cm);
    \node at (0,0) [below left] {$A$};
    \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}{From Right Triangle Trig to the Coordinate Plane}
The biggest difference between this section and the last is that in this section, trig ratios can be positive, negative, zero, or undefined, since $x$ and $y$ can each be positive, negative, or zero.
\end{frame}

\section{Calculate the 6 Trig Ratios for a Point in the Coordinate Plane}

\begin{frame}{The 6 Trig Ratios}
In the coordinate plane, the six trig ratios become \newline\\
\begin{center}
    \begin{tabular}{c|c}
        $\sin A = \dfrac{y}{r}$  &   \onslide<2->{$\csc A = \dfrac{r}{y}$}    \\[0.35in]
        $\cos A = \dfrac{x}{r}$ &   \onslide<2->{$\sec A = \dfrac{r}{x}$}   \\[0.35in]
        $\tan A = \dfrac{y}{x}$ &   \onslide<2->{$\cot A = \dfrac{x}{y}$}   \\
    \end{tabular}
\end{center}
\end{frame}

\begin{frame}{Example 1a}
For the given point, find the exact values of the 6 trig functions for the angle drawn in standard form.   \newline\\
(a)     \quad $(3,-4)$
\begin{align*}
\onslide<2->{3^2 + 4^2 &= r^2}	\\[8pt]
\onslide<3->{r &= \sqrt{25} = 5} \\
\end{align*}
\begin{tabular}{p{0.4\textwidth}p{0.4\textwidth}}
\onslide<4->{$\sin A = \frac{-4}{5}$}	&	\onslide<7->{$\csc A = \frac{5}{-4}$}	\\[8pt]
\onslide<5->{$\cos A = \frac{3}{5}$}	&	\onslide<8->{$\sec A = \frac{5}{3}$}	\\[8pt]
\onslide<6->{$\tan A = \frac{-4}{3}$}	&	\onslide<9->{$\cot A = \frac{3}{-4}$}	\\
\end{tabular}
\end{frame}

\begin{frame}{Example 1b}
(b)	\quad $(-8,-15)$
\begin{align*}
\onslide<2->{8^2 + 15^2 &= r^2}	\\[8pt]
\onslide<3->{r &= \sqrt{289} = 17} \\
\end{align*}
\begin{tabular}{p{0.4\textwidth}p{0.4\textwidth}}
\onslide<4->{$\sin A = \frac{-15}{17}$}					&	\onslide<7->{$\csc A = \frac{17}{-15}$}	\\[8pt]
\onslide<5->{$\cos A = \frac{-8}{17}$}					&	\onslide<8->{$\sec A = \frac{17}{-8}$}	\\[8pt]
\onslide<6->{$\tan A = \frac{-15}{-8} = \frac{15}{8}$}	&	\onslide<9->{$\cot A = \frac{8}{15}$}	\\
\end{tabular}
\end{frame}

\begin{frame}{Example 1c}
(c)	\quad $(-1,5)$
\begin{align*}
\onslide<2->{1^2 + 5^2 &= r^2}	\\[8pt]
\onslide<3->{r &= \sqrt{26}} \\
\end{align*}
\begin{tabular}{p{0.4\textwidth}p{0.4\textwidth}}
\onslide<4->{$\sin A = \frac{5}{\sqrt{26}} = \frac{5\sqrt{26}}{26}$}	&	\onslide<7->{$\csc A = \frac{\sqrt{26}}{5}$}	\\[8pt]
\onslide<5->{$\cos A = \frac{-1}{\sqrt{26}} = \frac{-\sqrt{26}}{26}$}	&	\onslide<8->{$\sec A = \frac{\sqrt{26}}{-1} = -\sqrt{26}$}	\\[8pt]
\onslide<6->{$\tan A = \frac{5}{-1} = -5$}	&	\onslide<9->{$\cot A = \frac{-1}{5}$}	\\
\end{tabular}
\end{frame}

\section{Find the Exact Values of the Trig Ratios of Special Angles in the Coordinate Plane}

\begin{frame}
If we put a 45-45-90 triangle in the second quadrant of the coordinate plane, it would resemble the following:

\begin{center}
    \begin{tikzpicture}[scale=0.8]
    \tkzDefPoints{0/0/A, -2/0/C, -2/2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \draw [<->, >=stealth] (-3,0) node [left] {$180^\circ$} -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) node [below] {$270^\circ$} -- (0,3) node [above] {$90^\circ$};
    \tkzLabelAngle[pos=0.75](C,A,B){$45^\circ$}
    \onslide<2->{\draw [->, >=stealth, color=blue] (0:1) arc (0:135:1) node [midway, above right, color=blue] {$135^\circ$};}
    \onslide<4->{\draw[->, >=stealth] (-1.75,-1) node [below] {Reference Angle} -- (-0.75,0);}
    \end{tikzpicture}
\end{center}
\pause

The hypotenuse, $r$, would have rotated $180^\circ - 45^\circ = 135^\circ$.
\end{frame}

\begin{frame}
In the second quadrant, $x$-coordinates are negative and $y$-coordinates are positive ($r$ is always positive). Thus, the values would be

\begin{center}
    \begin{tikzpicture}
    \tkzDefPoints{0/0/A, -2/0/C, -2/2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \tkzLabelAngle[pos=0.75](C,A,B){$45^\circ$}
    \node at (-1,0) [below] {$-1$};
    \node at (-2,1) [left] {$1$};
    \node at (135:1.75) [right] {$\sqrt{2}$};
    \end{tikzpicture}
\end{center}
\pause
So $\sin 135^\circ = \frac{\sqrt{2}}{2}$, $\cos 135^\circ = -\frac{\sqrt{2}}{2}$, and $\tan 135^\circ = -1$.
\end{frame}

\begin{frame}{Example 2a}
Find the exact values of the 6 trig functions for each of the following.	\newline\\
(a)	\quad $135^\circ = \frac{3\pi}{4}$	\newline\\
\begin{minipage}{0.25\textwidth}
\begin{tikzpicture}[scale=0.8]
    \tkzDefPoints{0/0/A, -2/0/C, -2/2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \onslide<1->{\tkzLabelAngle[pos=0.75](C,A,B){$45^\circ$}}
    \node at (-1,0) [below] {$-1$};
    \node at (-2,1) [left] {$1$};
    \node at (135:1.75) [right] {$\sqrt{2}$};
    \end{tikzpicture}
\end{minipage}
\begin{minipage}{0.65\textwidth}
\begin{tabular}{p{0.43\textwidth}p{0.53\textwidth}}
\onslide<1->{$\sin 135^\circ = \frac{\sqrt{2}}{2}$}		&	\onslide<2->{$\csc 135^\circ = \frac{\sqrt{2}}{1} = \sqrt{2}$}	\\[11pt]
\onslide<1->{$\cos 135^\circ = -\frac{\sqrt{2}}{2}$}	&	\onslide<3->{$\sec 135^\circ = \frac{\sqrt{2}}{-1} = -\sqrt{2}$}	\\[11pt]
\onslide<1->{$\tan 135^\circ = -1$}						&	\onslide<4->{$\cot 135^\circ = -1$}	\\
\end{tabular}
\end{minipage}
\end{frame}

\begin{frame}{Example 2b}
(b)	\quad $225^\circ = \frac{5\pi}{4}$	\newline\\
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, -2/0/C, -2/-2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \draw [<->, >=stealth] (-3,0) node [left] {$180^\circ$} -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) node [below] {$270^\circ$} -- (0,3) node [above] {$90^\circ$};
    \onslide<2->{\tkzLabelAngle[pos=-0.75](B,A,C){$45^\circ$}}
    \draw [->, >=stealth, color=blue] (0:1.2) arc (0:225:1.2) node [midway, above right, color=blue] {$225^\circ$};
\end{tikzpicture}
\end{frame}

\begin{frame}{Example 2b}
\begin{center}
\begin{tikzpicture}
    \tkzDefPoints{0/0/A, -2/0/C, -2/-2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \tkzLabelAngle[pos=-0.75](C,A,B){$45^\circ$}
    \tkzLabelSegment[midway](A,C){$-1$}
    \tkzLabelSegment[midway, left](C,B){$-1$}
    \tkzLabelSegment[below](A,B){$\sqrt{2}$}
\end{tikzpicture}
\end{center}
\begin{tabular}{p{0.5\textwidth}p{0.5\textwidth}}
\onslide<2->{$\sin 225^\circ = \frac{-1}{\sqrt{2}} = -\frac{\sqrt{2}}{2}$}	&	\onslide<5->{$\csc 225^\circ = \frac{\sqrt{2}}{-1} = -\sqrt{2}$}	\\[11pt]
\onslide<3->{$\cos 225^\circ = \frac{-1}{\sqrt{2}} = -\frac{\sqrt{2}}{2}$}	&	\onslide<6->{$\sec 225^\circ = \frac{\sqrt{2}}{-1} = -\sqrt{2}$}	\\[11pt]
\onslide<4->{$\tan 225^\circ = \frac{-1}{-1} = 1$}							&	\onslide<7->{$\cot 225^\circ = \frac{-1}{-1} = 1$}	\\
\end{tabular}
\end{frame}

\begin{frame}{Example 2c}
(c) \quad $315^\circ = \frac{7\pi}{4}$	\newline\\
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, 2/0/C, 2/-2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \draw [<->, >=stealth] (-3,0) node [left] {$180^\circ$} -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) node [below] {$270^\circ$} -- (0,3) node [above] {$90^\circ$};
    \onslide<2->{\tkzLabelAngle[pos=0.75](B,A,C){$45^\circ$}}
    \draw [->, >=stealth, color=blue] (0:1.2) arc (0:315:1.2) node [midway, above left, color=blue] {$315^\circ$};
\end{tikzpicture}
\end{frame}

\begin{frame}{Example 2c}
\begin{center}
\begin{tikzpicture}
    \tkzDefPoints{0/0/A, 2/0/C, 2/-2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \tkzLabelAngle[pos=0.75](C,A,B){$45^\circ$}
    \tkzLabelSegment[midway](A,C){$1$}
    \tkzLabelSegment[midway, right](C,B){$-1$}
    \tkzLabelSegment[below, left, yshift=-0.2cm](A,B){$\sqrt{2}$}
\end{tikzpicture}
\end{center}
\begin{tabular}{p{0.5\textwidth}p{0.5\textwidth}}
\onslide<2->{$\sin 315^\circ = \frac{-1}{\sqrt{2}} = -\frac{\sqrt{2}}{2}$}	&	\onslide<5->{$\csc 315^\circ = \frac{\sqrt{2}}{-1} = -\sqrt{2}$}	\\[11pt]
\onslide<3->{$\cos 315^\circ = \frac{1}{\sqrt{2}} = \frac{\sqrt{2}}{2}$}	&	\onslide<6->{$\sec 315^\circ = \frac{\sqrt{2}}{1} = \sqrt{2}$}	\\[11pt]
\onslide<4->{$\tan 315^\circ = \frac{-1}{1} = -1$}							&	\onslide<7->{$\cot 315^\circ = \frac{1}{-1} = -1$}	\\
\end{tabular}
\end{frame}

\begin{frame}{Example 2d}
(d) \quad $120^\circ = \frac{2\pi}{3}$	\newline\\
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, -2/0/C, -2/4/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \draw [<->, >=stealth] (-3,0) node [left] {$180^\circ$} -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) node [below] {$270^\circ$} -- (0,3) node [above] {$90^\circ$};
    \onslide<2->{\tkzLabelAngle[pos=0.75](B,A,C){$60^\circ$}}
    \draw [->, >=stealth, color=blue] (0:1) arc (0:120:1) node [midway, above right, color=blue] {$120^\circ$};
\end{tikzpicture}
\end{frame}

\begin{frame}{Example 2d}
\begin{center}
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, -2/0/C, -2/4/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \tkzLabelAngle[pos=0.75](C,A,B){$60^\circ$}
    \tkzLabelSegment[midway,below](A,C){$-1$}
    \tkzLabelSegment[midway, left](C,B){$\sqrt{3}$}
    \tkzLabelSegment[right, xshift=0.2cm](A,B){$2$}
\end{tikzpicture}
\end{center}
\begin{tabular}{p{0.5\textwidth}p{0.5\textwidth}}
\onslide<2->{$\sin 120^\circ = \frac{\sqrt{3}}{2}$}					&	\onslide<5->{$\csc 120^\circ = \frac{2}{\sqrt{3}} = \frac{2\sqrt{3}}{3}$}	\\[11pt]
\onslide<3->{$\cos 120^\circ = \frac{-1}{2}$}						&	\onslide<6->{$\sec 120^\circ = \frac{2}{-1} = -2$}	\\[11pt]
\onslide<4->{$\tan 120^\circ = \frac{\sqrt{3}}{-1} = -\sqrt{3}$}	&	\onslide<7->{$\cot 120^\circ = \frac{-1}{\sqrt{3}} = -\frac{\sqrt{3}}{3}$}	\\
\end{tabular}
\end{frame}

\begin{frame}{Example 2e}
(e) \quad $150^\circ = \frac{5\pi}{6}$	\newline\\
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, -3.5/0/C, -3.5/2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \draw [<->, >=stealth] (-4,0) node [left] {$180^\circ$} -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) node [below] {$270^\circ$} -- (0,3) node [above] {$90^\circ$};
    \onslide<2->{\tkzLabelAngle[pos=1](B,A,C){$30^\circ$}}
    \draw [->, >=stealth, color=blue] (0:1) arc (0:150:1) node [midway, above right, color=blue] {$150^\circ$};
\end{tikzpicture}
\end{frame}

\begin{frame}{Example 2e}
\begin{center}
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, -3.5/0/C, -3.5/2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \tkzLabelSegment[below](A,C){$-\sqrt{3}$}
    \tkzLabelSegment[left](C,B){1}
    \tkzLabelSegment[above, xshift = 0.2cm](A,B){2}
    \tkzLabelAngle[pos=1](B,A,C){$30^\circ$}
\end{tikzpicture}
\end{center}
\begin{tabular}{p{0.5\textwidth}p{0.5\textwidth}}
\onslide<2->{$\sin 150^\circ = \frac{1}{2}$}					&	\onslide<5->{$\csc 150^\circ = \frac{2}{1} = 2$}	\\[11pt]
\onslide<3->{$\cos 150^\circ = \frac{-\sqrt{3}}{2}$}			&	\onslide<6->{$\sec 150^\circ = \frac{2}{-\sqrt{3}} = -\frac{2\sqrt{3}}{3}$}	\\[11pt]
\onslide<4->{$\tan 150^\circ = \frac{1}{-\sqrt{3}} = -\frac{\sqrt{3}}{3}$}	&	\onslide<7->{$\cot 150^\circ = \frac{-\sqrt{3}}{1} = -\sqrt{3}$}	\\
\end{tabular}
\end{frame}

\begin{frame}{Example 2f}
(a) \quad $210^\circ = \frac{7\pi}{6}$	\newline\\
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, -3.5/0/C, -3.5/-2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \draw [<->, >=stealth] (-4,0) node [left] {$180^\circ$} -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) node [below] {$270^\circ$} -- (0,3) node [above] {$90^\circ$};
    \onslide<2->{\tkzLabelAngle[pos=-1](B,A,C){$30^\circ$}}
    \draw [->, >=stealth, color=blue] (0:1.5) arc (0:210:1.5) node [midway, above right, color=blue] {$210^\circ$};
\end{tikzpicture}
\end{frame}

\begin{frame}{Example 2f}
\begin{center}
\begin{tikzpicture}[scale=0.7]
    \tkzDefPoints{0/0/A, -3.5/0/C, -3.5/-2/B}
    \tkzDrawPolygon[fill=yellow!40](A,B,C)
    \tkzMarkRightAngle[color=red](B,C,A)
    \tkzLabelSegment[above](A,C){$-\sqrt{3}$}
    \tkzLabelSegment[left](C,B){$-1$}
    \tkzLabelSegment[below, xshift = 0.2cm](A,B){2}
    \tkzLabelAngle[pos=-1](B,A,C){$30^\circ$}
\end{tikzpicture}
\end{center}
\begin{tabular}{p{0.5\textwidth}p{0.5\textwidth}}
\onslide<2->{$\sin 210^\circ = \frac{-1}{2}$}					&	\onslide<5->{$\csc 210^\circ = \frac{2}{-1} = -2$}	\\[11pt]
\onslide<3->{$\cos 210^\circ = \frac{-\sqrt{3}}{2}$}			&	\onslide<6->{$\sec 210^\circ = \frac{2}{-\sqrt{3}} = -\frac{2\sqrt{3}}{3}$}	\\[11pt]
\onslide<4->{$\tan 210^\circ = \frac{-1}{-\sqrt{3}} = \frac{\sqrt{3}}{3}$}	&	\onslide<7->{$\cot 210^\circ = \frac{-\sqrt{3}}{-1} = \sqrt{3}$}	\\
\end{tabular}
\end{frame}

\begin{frame}{Quadrantal Angles}
A \alert{quadrantal angle} is an angle whose terminal side lies on an axis.  \newline\\  \pause

Finding the values of the trig functions for quadrantal angles can be found by using any point on the axes.
\end{frame}

\begin{frame}{Quadrantal Angles}
For simplicity, we will use combinations of 0s and 1s. Below is the point we will use for $0^\circ$.
\begin{center}
    \begin{tikzpicture}[scale=0.8]
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) -- (0,3);
    \draw [fill=black] (2,0) circle (2pt) node [below] {$(1,0)$};
    \draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [above] {$r=1$} (2,0);
    \node at (0,3) [right] {$90^\circ$};
    \node at (-3,0) [left] {$180^\circ$};
    \node at (0,-3) [right] {$270^\circ$};
    \end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}{Quadrantal Angles}
So, for $0^\circ$, we have $x=1, \, y=0, \, \text{and } r=1$. Thus  \newline\\

\begin{center}
\begin{tabular}{p{0.3\textwidth}p{0.5\textwidth}}
    \onslide<2->{$\sin 0 = \frac{0}{1} = 0$}  &
    \onslide<5->{$\csc 0 = \frac{1}{0} = \text{undefined}$}  \\[18pt]
    \onslide<3->{$\cos 0 = \frac{1}{1} = 1$}  &
    \onslide<6->{$\sec 0 = \frac{1}{1} = 1$}  \\[18pt]
    \onslide<4->{$\tan 0 = \frac{0}{1} = 0$}  &
    \onslide<7->{$\cot 0 = \frac{1}{0} = \text{undefined}$}   \\
\end{tabular}
\end{center}
\end{frame}

\begin{frame}{Example 3a}
Find the exact values of each of the 6 trig functions for the following angles.   \newline\\
(a) \quad $90^\circ = \frac{\pi}{2}$    \newline\\  \pause
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) -- (0,3);
    \draw [fill=black] (0,2) circle (2pt) node [right] {$(0,1)$};
    \draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [right] {$r=1$} (0,2);
    \node at (0,3) [right] {$90^\circ$};
    \node at (-3,0) [left] {$180^\circ$};
    \node at (0,-3) [right] {$270^\circ$};
\end{tikzpicture}
\end{minipage}
\hspace{0.35cm}
\begin{minipage}{0.3\textwidth}
\begin{align*}
    \onslide<3->{\sin 90^\circ &= \frac{1}{1} = 1} \\[18pt]
    \onslide<4->{\cos 90^\circ &= \frac{0}{1} = 0} \\[18pt]
    \onslide<5->{\tan 90^\circ &= \frac{1}{0} = \text{undefined}} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3a}
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) -- (0,3);
    \draw [fill=black] (0,2) circle (2pt) node [right] {$(0,1)$};
    \draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [right] {$r=1$} (0,2);
    \node at (0,3) [right] {$90^\circ$};
    \node at (-3,0) [left] {$180^\circ$};
    \node at (0,-3) [right] {$270^\circ$};
\end{tikzpicture}
\end{minipage}
\hspace{0.35cm}
\begin{minipage}{0.3\textwidth}
\begin{align*}
    \onslide<2->{\csc 90^\circ &= \frac{1}{1} = 1} \\[18pt]
    \onslide<3->{\sec 90^\circ &= \frac{1}{0} = \text{undefined}} \\[18pt]
    \onslide<4->{\cot 90^\circ &= \frac{0}{1} = 0} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3b}
    (b) \quad $180^\circ = \pi$    \newline\\  \pause
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) -- (0,3);
    \draw [fill=black] (-2,0) circle (2pt) node [below] {$(-1,0)$};
    \draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [above] {$r=1$} (-2,0);
    \node at (0,3) [right] {$90^\circ$};
    \node at (-3,0) [left] {$180^\circ$};
    \node at (0,-3) [right] {$270^\circ$};
\end{tikzpicture}
\end{minipage}
\hspace{0.35cm}
\begin{minipage}{0.3\textwidth}
\begin{align*}
    \onslide<3->{\sin 180^\circ &= \frac{0}{1} = 0} \\[18pt]
    \onslide<4->{\cos 180^\circ &= \frac{-1}{1} = -1} \\[18pt]
    \onslide<5->{\tan 180^\circ &= \frac{0}{-1} = 0} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3b}
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) -- (0,3);
    \draw [fill=black] (-2,0) circle (2pt) node [below] {$(-1,0)$};
    \draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [above] {$r=1$} (-2,0);
    \node at (0,3) [right] {$90^\circ$};
    \node at (-3,0) [left] {$180^\circ$};
    \node at (0,-3) [right] {$270^\circ$};
\end{tikzpicture}
\end{minipage}
\hspace{0.35cm}
\begin{minipage}{0.3\textwidth}
\begin{align*}
    \onslide<2->{\csc 180^\circ &= \frac{1}{0} = \text{undefined}} \\[18pt]
    \onslide<3->{\sec 180^\circ &= \frac{1}{-1} = -1} \\[18pt]
    \onslide<4->{\cot 180^\circ &= \frac{-1}{0} = \text{undefined}} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3c}
(c) \quad $270^\circ = \frac{3\pi}{2}$    \newline\\  \pause
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) -- (0,3);
    \draw [fill=black] (0,-2) circle (2pt) node [right] {$(0,-1)$};
    \draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [left] {$r=1$} (0,-2);
    \node at (0,3) [right] {$90^\circ$};
    \node at (-3,0) [left] {$180^\circ$};
    \node at (0,-3) [right] {$270^\circ$};
\end{tikzpicture}
\end{minipage}
\hspace{0.35cm}
\begin{minipage}{0.3\textwidth}
\begin{align*}
    \onslide<3->{\sin 270^\circ &= \frac{-1}{1} = -1} \\[18pt]
    \onslide<4->{\cos 270^\circ &= \frac{0}{1} = 0} \\[18pt]
    \onslide<5->{\tan 270^\circ &= \frac{-1}{0} = \text{undefined}} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Example 3c}
\begin{minipage}{0.5\textwidth}
\begin{tikzpicture}[scale=0.7]
    \draw [<->, >=stealth] (-3,0) -- (3,0) node [right] {$0$};
    \draw [<->, >=stealth] (0,-3) -- (0,3);
    \draw [fill=black] (0,-2) circle (2pt) node [right] {$(0,-1)$};
    \draw [->, >=latex, line width = 1.5, color=blue] (0,0) -- node [left] {$r=1$} (0,-2);
    \node at (0,3) [right] {$90^\circ$};
    \node at (-3,0) [left] {$180^\circ$};
    \node at (0,-3) [right] {$270^\circ$};
\end{tikzpicture}
\end{minipage}
\hspace{0.35cm}
\begin{minipage}{0.3\textwidth}
\begin{align*}
    \onslide<2->{\csc 270^\circ &= \frac{1}{-1} = -1} \\[18pt]
    \onslide<3->{\sec 270^\circ &= \frac{1}{0} = \text{undefined}} \\[18pt]
    \onslide<4->{\cot 270^\circ &= \frac{0}{-1} = 0} \\
\end{align*}
\end{minipage}
\end{frame}

\begin{frame}{Angles Not Between 0 and $360^\circ$ or 0 and $2\pi$}
    For angles not within 1 standard rotation, use \alert{coterminal angles} to bring the angle within 1 rotation and then apply the rules of the previous notes.  \newline\\

    For instance, $\cos\left(\frac{9\pi}{4}\right) = \cos\left(\frac{\pi}{4}\right)$
\end{frame}

\end{document}


\subsection{The infintesimal jackknife}

\subsubsection{The jackknife as a weighting}

In the jackknife we calculate the statistic leaving one observation out.

This is the same as weighting observations and giving one a weighting of \(0\) and the others \(1\).

\subsubsection{The infintesimal jackknife}

For the infintesimal jackknife we reduce the weight not to \(0\), but by an infintesimal amount.


\chapter{Kernel density estimation}
\section{Bandwidth and Kernel function}
In this chapter we are dealing with marks secured by students in various subject, along with  explanatory variables about the students viz., gender, ethnicity etc.. For our analysis for student's performance together with scores in mathematics, reading and writing tests, we consider students attendance for the test preparation course. We drop rest of the variables. Following is the sample for first few entries of the dataset;

\begin{table}[ht]
\centering
\begin{tabular}{llrrr}
  \hline
 & test preparation course & math score & reading score & writing score \\
  \hline
1 & none &  72 &  72 &  74 \\
  2 & completed &  69 &  90 &  88 \\
  3 & none &  90 &  95 &  93 \\
  4 & none &  47 &  57 &  44 \\
  5 & none &  76 &  78 &  75 \\
  6 & none &  71 &  83 &  78 \\
  7 & completed &  88 &  95 &  92 \\
  8 & none &  40 &  43 &  39 \\
  9 & completed &  64 &  64 &  67 \\
  10 & none &  38 &  60 &  50 \\
   \hline
\end{tabular}
\end{table}

In this exercise we are suppose to implement kernel density estimation. The data entries i.e. math score are integers variables. Kernel density estimation help us visualize the “shape” of data, even though its discrete. Essentially it is sort of continuous replacement for the discrete histogram. Kernel estimation uses a weighted sum of observations dependent on their distance from the variable. The precise definition is as follows, for the given data $X_1, X_2,..., X_n$, a kernel density estimator is
$$\widehat{f}_{n,h}(x)= \frac{1}{nh}\sum_{1 = j}^n K\left(\frac{x-X_j}{h}\right), \: x\in \RR .$$
where $K: \RR \rightarrow \RR$, such that $\int_{-\infty}^{\infty}K(x)dx=1$ is known as kernel and $h>0$ is called the bandwidth. $h$ is smoothing parameter which basically governs how many distinct observations are taken into account around certain location. Thus it has a strong influence on the resulting estimate. Examples of some classical kernels is illustrated below in Figure \ref{fig:types_kernels8}.

\begin{figure}[thb]
\centering
\includegraphics[width=0.75\textwidth, keepaspectratio]{ex8/types_kernels.png}
\caption{Classical examples of kernels often used for density estimation. }
\label{fig:types_kernels8}
\end{figure}

To visualise and examine the influence of the choice of bandwidth and kernel we have considered the math score variable from the data. First we fit a kernel density with different bandwidths using the Epanechnikov kernel (See Figure \ref{fig:diff_bandwidth8}) and then use different kernels with a fixed bandwidth Figure\ref{fig:diff_ker8} ). We can clearly see the influence of the choice of bandwidth.  The estimated curves get smoother with higher and higher $h$. For bandwidth $= 2$ it fluctuates highly.
For the values  of $h$ between $5$  and  $12$ seems reasonable where as for for  higher values, like $30$ density curve gets  too  smooth and it certainly does not represent the shape of the data distribution anymore. Since, visually it appears that the most reasonable bandwidth lies between $5$ and $12$, I have fixed $h= 8$ for the next analysis (See Figure \ref{fig:diff_ker8}). We will now compare different kernels choices with a fix bandwidth $h= 8$.

\begin{figure}[tbh]
\centering
\begin{subfigure}[c]{\textwidth}
\includegraphics[width=0.93\textwidth, keepaspectratio]{ex8/diff_bandwidths.png}
\subcaption{Epanechnikov kernel with different bandwidths.}
\label{fig:diff_bandwidth8}
\end{subfigure}
\begin{subfigure}[c]{\textwidth}
\includegraphics[width=0.98\textwidth, keepaspectratio]{ex8/diff_ker.png}
\subcaption{Different kernels with fixed bandwidth $h=8$.}
\label{fig:diff_ker8}
\end{subfigure}
\caption{Kernel density estimations for the math score  (first plot) and kernels (second plot).}
\label{6fit}
\end{figure}

%Comment on the effect of the bandwidth and of the kernel function on kernel density estimators
If we observe closely Figure \ref{fig:types_kernels8}, we can see that, the different shapes of the kernels shows how observations with certain weights at different distances influence the height of the density estimation at specific points. Therefore, the shape and some basic properties of the resulting density estimations depend highly on the choice of the kernel. The rectangular kernel for example will always result in a piece-wise constant estimation, which is not continuous.  The triangular kernel will give us a piece-wise linear density and the Gaussian kernel will result in smooth estimations. In Figure \ref{fig:diff_ker8} we can see that for the rectangular kernel the result is a step function, where as the rest of the kernels seem smoother. But as mentioned before the curve for the triangular kernel is piece-wise linear. Rectangular, triangular and Epanechnikov look quite similar with respect to the shape of the overall distribution. The Gaussian kernel produces a flatter curve that puts more mass to the tails. This might be because, of the differences in support of kernels. The support of the Gaussian kernel $\RR$ and its $ [ -1,1] $ for the other kernels. Thus, as we can also see in Figure \ref{fig:types_kernels8} Gaussian kernel puts more mass to the tails.

\section{Cross validation for optimal bandwidth}
Now we want to consider a more formal approach to examine the best bandwidth. Above we just did a graphical examination. To get the best fitting curve a common approach is trying to minimise the mean integrated square error (MISE) for the estimator $\hat{f}_{n,h}(x)$ of $f(x)$, which is given by $$MISE(\hat{f}_{n,h})=E\left[\int\left(\hat{f}_{n,h}(x)-f(x)\right)^2dx\right].$$ Because the real $f$ is unknown one minimises an unbiased estimator of the $h$-dependent part of the MISE, called the cross-validation criterion: $$CV(h)=\int\left(\hat{f}_{n,h}(x)\right)^2dx-\frac{2}{n(n-1)h}\sum_{i=1}^{n} \sum_{j\neq i} K\left(\frac{X_j - X_i}{h}\right).$$
\begin{figure}[!tb]
\centering
\includegraphics[width=0.9\textwidth, keepaspectratio]{ex8/CV1.png}
\caption{CV values for 40 different bandwidths. Red point shows minimum of the curve. Other points show the results for the \texttt{optimize} function in R with different limits (see legend).}
\label{6CV1}
\end{figure}

Implementing a function computing the CV for a given estimation we can use the minimising $h_{CV}=\argmin _{h>0} CV(h)$.
Afterwards we compared the results with the functions \texttt{bw.ucv} and \texttt{bw.bcv} of the package \texttt{density}, which compute the optimal bandwidth for an unbiased (\texttt{ucv}) or biased (\texttt{bcv}) CV implementation for Gaussian kernels.
Therefore I used the Epanechnikov kernel as well as the Gaussian kernel in my implementation to compare all results for the maths score. To find the minimizer of my function, I used the R function \texttt{optimize}. Before comparing the optimisation of my own CV function a little note about the disadvantages of using \texttt{optimize} here is important.
To get a first idea of the shape of CV for different $h$ as a curve I took 40 equidistant points in the interval $[1,25]$ - because it seemed as a (maximal) reasonable region for bandwidths in this case -  and computed CV there. Afterwards I took the minimum out of this observations as first reference point ($h=1.62$). After using the R implemented optimisation with limits 0 and 30, I was surprised by the result ($h=11.50$). As \texttt{optimize} just searches for local minima and starting points for the iteration are chosen as a golden section distance between the given limits, the result also depends highly on those borders. Obviously CV is a strongly fluctuating function as I got different results for every trial, none of them was near the first, say, 'scanned minimum'. Figure \ref{6CV1} shows the results. All in all, without an analytical examination of CV as a function one cannot be sure to really found the optimal bandwidth or even to be close to it. In the following I won't discuss this issue any more- I will use a combined strategy by first scanning the interval $[1, 20]$ with 40 points to get the area of small values visually and by taking the minimum. Afterwards I will use \texttt{optimize} limited to this region to get a local minimum. This should in total result in a somehow precise and at least acceptable minimum. The results for all three tests and the different methods are shown together in Table \ref{6table}. For the math score and the best bandwidth with a Epanechnikov kernel we use the above optimal $h=1.62$.
\begin{figure}[p]
\centering
\includegraphics[width=\textwidth, keepaspectratio]{ex8/CVplots.png}
\caption{CV against $h$ for math score and Gaussian kernel (first row), reading score (second row) and writing score (third row). Last two for Epanechnikov  kernel (left) and Gaussian kernel (right)}
\label{6CVs}
\end{figure}

First, observe (see Figure \ref{6CVs}) that for the Gaussian kernel the problem of fluctuating CV function is not that worse but the usage of the \texttt{optimize} function still improves the optimal bandwidth a bit. For the Epanechnikov kernel we have the same problem for every test. All in all the CV curves look very similar for math, reading and writing score. Therefore we get quite similar results for optimal bandwidths. As expected the values of my own optimisation for the Gauss kernel are similar to those of the R functions but differ from the optimal bandwidth for the Epanechnikov kernel. For every score the resulting CVs just differ on the presented scale between the kernels where always the Epanechnikov kernel gives a better result. Therefore we use this bandwidth an the Epanechnikov kernel for the last part of the exercise.

\begin{table}[!t]
\centering
\begin{tabular}{lrrrrrrrr}
  \hline
 & \multicolumn{2}{r}{Epa} &  \multicolumn{2}{r}{Gau}&  \multicolumn{2}{r}{\texttt{bw.bcv}}&  \multicolumn{2}{r}{\texttt{bw.ucv}} \\
\hline
 & h & CV & h & CV & h & CV & h & CV \\
  \hline
math & 1.62 & -0.0197 & 4.83 & -0.0186 & 4.26 & -0.0186 & 4.65 & -0.0186 \\
  reading & 1.41 & -0.0212 & 4.19 & -0.0191 & 4.40 & -0.0191 & 3.77 & -0.0191 \\
  writing & 1.41 & -0.0203 & 4.52 & -0.0184 & 4.18 & -0.0184 & 4.28 & -0.0184 \\
   \hline
\end{tabular}
\caption{Optimal bandwidths $h$ and corresponding CV for math, reading and writing score and different methods. First two columns are optimum of self-written function with Epanechnikov kernel (Epa) and Gaussian kernel (Gau) respectively, last two columns with R function in the package \texttt{density}.}
\label{6table}
\end{table}

\section{Comparison of groups}
Now we use the kernel density estimation for a comparison of those students attending a preparation course and those that did not. Therefore we fit a curve for both groups using the optimal bandwidth we got in the previous examinations and the Epanechnikov kernel. For the bandwidth we use a common value equal to the mean of the three optimal bandwidths (this is just for a simplification of the code and does not change the results crucially).

The result is shown in Figure \ref{6groups}. I decided to plot the histograms above each other, so that there is no confusion about the positioning and because one can still distinguish the bars with just two groups. We see that for the math score the whole distribution of scores is not changed very much in the shape but just shifted to the right, i.e. to better grades. For the other two scores we can recognise that the distribution of students with the preparation course is a bit more left skewed. This is just slightly visible for the reading score and a bit more distinct for the writing score. This is probably due to the fact that the student get better in total but the limit of the score is at 100. Psychologists call this effect \textit{ceiling effect}. This is maybe also the reason why the distribution has a smaller variation, especially for the writing score again. Summing up, we recognize better performance of students doing a preparation course. This is especially visible for the writing score. Apparently, one cannot train maths as easily as writing.
\begin{figure}[!t]
\centering
\includegraphics[width=\textwidth, keepaspectratio]{ex8/groups.png}
\caption{Histogram and kernel density estimate for two groups of students in different colors and the three scores, math (left), reading (middle) and writing (right).}
\label{6groups}
\end{figure}


\section{Taylor Series}\label{sec:taylorseries}

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
We have seen that some functions can be represented as series, which
may give valuable information about the function. So far, we have seen
only those examples that result from manipulation of our one
fundamental example, the geometric series. We would like to start with
a given function and produce a series to represent it, if possible.

Suppose that $\ds f(x)=\sum_{n=0}^\infty a_nx^n$ on some interval of
convergence centered at 0. Then we know that we can compute derivatives of $f$ by
taking derivatives of the terms of the series. Let's look at the first
few in general:
\begin{align*}
  f'(x)&=\sum_{n=1}^\infty n a_n x^{n-1}=a_1 + 2a_2x+3a_3x^2+4a_4x^3+\cdots	\\
  f''(x)&=\sum_{n=2}^\infty n(n-1) a_n x^{n-2}=2a_2+3\cdot2a_3x
    +4\cdot3a_4x^2+\cdots	\\
  f'''(x)&=\sum_{n=3}^\infty n(n-1)(n-2) a_n x^{n-3}=3\cdot2a_3
    +4\cdot3\cdot2a_4x+\cdots	\\
\end{align*}

By examining these it's not hard to discern the general pattern. The
$k$th derivative must be
\begin{align*}
  f^{(k)}(x)&=\sum_{n=k}^\infty n(n-1)(n-2)\cdots(n-k+1)a_nx^{n-k}	\\
  &=k(k-1)(k-2)\cdots(2)(1)a_k+(k+1)(k)\cdots(2)a_{k+1}x+{}	\\
  &\qquad {}+(k+2)(k+1)\cdots(3)a_{k+2}x^2+\cdots	\\
\end{align*}
We can express this more clearly by using factorial notation:
\[
  f^{(k)}(x)=\sum_{n=k}^\infty {n!\over (n-k)!}a_nx^{n-k}=
  k!a_k+(k+1)!a_{k+1}x+{(k+2)!\over 2!}a_{k+2}x^2+\cdots
\]

We can solve for $a_n$ by substituting $x=0$ in the formula for $f^{(k)}(x)$:
\[f^{(k)}(0)=k!a_k+\sum_{n=k+1}^\infty {n!\over (n-k)!}a_n0^{n-k}=k!a_k,\]
\[a_k={f^{(k)}(0)\over k!}.\]
Note that the original series for $f$ yields $f(0)=a_0$.

So if a function $f$ can be represented by a series, we can easily find such a series.
Given a function $f$, the series
\[\sum_{n=0}^\infty {f^{(n)}(0)\over n!}x^n\]
is called the \dfont{Maclaurin
series} for $f$.

\begin{example}{Maclaurin Series}{MacSeriesOne}
Find the Maclaurin series for $f(x)=1/(1-x)$.
\end{example}
\begin{solution}
We need to
compute the derivatives of $f$ (and hope to spot a pattern).
\begin{align*}
  f(x)&=(1-x)^{-1}	\\
  f'(x)&=(1-x)^{-2}	\\
  f''(x)&=2(1-x)^{-3}	\\
  f'''(x)&=6(1-x)^{-4}	\\
  f^{(4)}(x)&=4!(1-x)^{-5}	\\
  &\vdots	\\
  f^{(n)}(x)&=n!(1-x)^{-n-1}	\\
\end{align*}

So
\[a_n={f^{(n)}(0)\over n!}={n!(1-0)^{-n-1}\over n!}=1\]
and the Maclaurin series is
\[\sum_{n=0}^\infty 1\cdot x^n=\sum_{n=0}^\infty x^n,\]
the geometric series.
\end{solution}

A warning is in order here. Given a function $f$ we may be able to
compute the Maclaurin series, but that does not mean we have found a
series representation for $f$. We still need to know where the series
converges, and if, where it converges, it converges to $f(x)$. While
for most commonly encountered functions the Maclaurin series does
indeed converge to $f$ on some interval, this is not true of all
functions, so care is required.

As a practical matter, if we are interested in using a series to
approximate a function, we will need some finite number of terms of
the series. Even for functions with messy derivatives we can compute
these using computer software like Sage. If we want to describe a series
completely, we would like to be able to write down a formula for a typical
term in the series. Fortunately, a few of the most important functions are very
easy.

\begin{example}{Maclaurin Series}{MacSeriesTwo}
Find the Maclaurin series for $\sin x$.
\end{example}
\begin{solution}
Computing the first few derivatives is simple: $f'(x)=\cos x$, $f''(x)=-\sin x$,
$f'''(x)=-\cos x$, $\ds f^{(4)}(x)=\sin x$, and then the pattern
repeats. The values of the derivative when $x=0$ are:
1, 0, $-1$, 0, 1, 0, $-1$, 0,\dots, and so the Maclaurin series is
\[
  x-{x^3\over 3!}+{x^5\over 5!}-\cdots=
  \sum_{n=0}^\infty (-1)^n{x^{2n+1}\over (2n+1)!}.
\]

We should always determine the radius of convergence:
\[
  \lim_{n\to\infty} {|x|^{2n+3}\over (2n+3)!}{(2n+1)!\over |x|^{2n+1}}
  =\lim_{n\to\infty} {|x|^2\over (2n+3)(2n+2)}=0,
\]
so the series converges for every $x$. Since it turns out that this
series does indeed converge to $\sin x$ everywhere, we have a series
representation for $\sin x$ for every $x$.
\end{solution}

Sometimes the formula for the $n$th derivative of a function $f$ is
difficult to discover, but a combination of a known Maclaurin series
and some algebraic manipulation leads easily to the Maclaurin series
for $f$.

\begin{example}{Maclaurin Series}{MacSeriesThree}
Find the Maclaurin series for $x\sin(-x)$.
\end{example}
\begin{solution}
To get from $\sin x$ to $x\sin(-x)$ we substitute $-x$ for $x$ and
then multiply by $x$. We can do the same thing to the series for $\sin
x$:
\[
  x\sum_{n=0}^\infty (-1)^n{(-x)^{2n+1}\over (2n+1)!}
  =x\sum_{n=0}^\infty (-1)^{n}(-1)^{2n+1}{x^{2n+1}\over (2n+1)!}
  =\sum_{n=0}^\infty (-1)^{n+1}{x^{2n+2}\over (2n+1)!}.
\]
\end{solution}

As we have seen, a power series can be centered at a point
other than zero, and the method that produces the Maclaurin series can
also produce such series.

\begin{example}{Taylor Series}{TaylorSeriesOne}
Find a series centered at $-2$ for $1/(1-x)$.
\end{example}
\begin{solution}
If the series is $\ds\sum_{n=0}^\infty a_n(x+2)^n$ then looking at the
$k$th derivative:
$$k!(1-x)^{-k-1}=\sum_{n=k}^\infty {n!\over (n-k)!}a_n(x+2)^{n-k}$$
and substituting $x=-2$ we get
$\ds k!3^{-k-1}=k!a_k$ and $\ds a_k=3^{-k-1}=1/3^{k+1}$, so the series is
$$\sum_{n=0}^\infty {(x+2)^n\over 3^{n+1}}.$$
\end{solution}

Such a series is called the
\dfont{Taylor series} for the function,
and the general term has the form
\[{f^{(n)}(a)\over n!}(x-a)^n.\]

A Maclaurin series is simply a Taylor series with $a=0$.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Opensolutionfile{solutions}[ex]
\section*{Exercises for \ref{sec:taylorseries}}

\begin{enumialphparenastyle}

\begin{ex}
For each function, find the Maclaurin series or Taylor series centered
at $a$, and the radius of convergence.

\begin{enumerate}
	\item $\cos x$
	\item $\ds e^x$
	\item $1/x$, $a=5$
	\item $\ln x$, $a=1$
	\item $\ln x$, $a=2$
	\item $\ds 1/x^2$, $a=1$
	\item $\ds 1/\sqrt{1-x}$
	\item Find the first four terms of the Maclaurin series for $\tan
	x$ (up to and including the $\ds x^3$ term).
	\item Use a combination of Maclaurin series and algebraic
	manipulation to find a series centered at zero for
	$\ds x\cos (x^2)$.
	\item Use a combination of Maclaurin series and algebraic
	manipulation to find a series centered at zero for
	$\ds xe^{-x}$.
\end{enumerate}
\begin{sol}
\begin{enumerate}
	\item $\ds\sum_{n=0}^\infty (-1)^n x^{2n}/(2n)!$, $R=\infty$
	\item $\ds\sum_{n=0}^\infty x^n/n!$, $R=\infty$
	\item $\ds\sum_{n=0}^\infty (-1)^n{(x-5)^n\over 5^{n+1}}$, $R=5$
	\item $\ds\sum_{n=1}^\infty (-1)^{n-1}{(x-1)^n\over n}$, $R=1$
	\item $\ds\ln(2)+\sum_{n=1}^\infty (-1)^{n-1}{(x-2)^n\over n 2^n}$, $R=2$
	\item $\ds\sum_{n=0}^\infty (-1)^n(n+1)(x-1)^n$, $R=1$
	\item $\ds1+\sum_{n=1}^\infty {1\cdot3\cdot5\cdots(2n-1)\over
		n!2^n} x^n=1+\sum_{n=1}^\infty {(2n-1)!\over 2^{2n-1}(n-1)!\,n!}x^n$, $R=1$
	\item $\ds x+x^3/3$
	\item $\ds\sum_{n=0}^\infty (-1)^n x^{4n+1}/(2n)!$
	\item $\ds\sum_{n=0}^\infty (-1)^n x^{n+1}/n!$
\end{enumerate}
\end{sol}
\end{ex}

\end{enumialphparenastyle}


\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{amsthm}
\usepackage{geometry}
\geometry{a4paper}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{multicol}
\usepackage{float}
\theoremstyle{definition}
\newtheorem{definition}{Defintion}[section]
\newtheorem{exmp}{Example}[section]
\newtheorem{theorem}{Theorem}

\begin{document}
\author{Fractals}
\title{\textbf{Functions}}
\maketitle
\tableofcontents
\noindent
\section{Introduction}
\subsection{Defintions}

\begin{definition}
    A function \(f\) from a set \(X\) to a set \(Y\) is a relation that assigns to each element in
    set \(X\) exactly one element in set \(Y\).
\end{definition}

\begin{definition}
    The domain is the set of \(X\) (a.k.a. the input).
\end{definition}

\begin{definition}
    The range is a subset of Y (a.k.a. the output).
\end{definition}

\subsection{Existence of a Function}
\begin{theorem}[\textbf{Vertical Line Test}]
    if you can draw a Vertical line that passes through more than one point of a
    relation on a grap, it's not a function, if you cannot, it's a function.

\end{theorem}

\begin{exmp}
    what the domain and range of the function \(f(x) = \sqrt{16 - x^2}\)?
\end{exmp}

\(sloution\) Note that if \(a < 0 \), then \( \sqrt{a}\) is undefined for reals,
Thus, \(16 - x^2 \ge 0 \Rrightarrow \) \framebox[\width]{
    \(-4 \le x \le 4\)
} since \(x^2 \ge 0\), we have that \(0 \le 16 - x^2 \le 16\),
so the range is \framebox[\width]{ \(0 \le y \le 4\) }

\section{Combinations of Functions}
\begin{theorem}[\textbf{common function Combinations}]
    The following are some common combinations of functions:
    \begin{itemize}
        \item \textbf{Sum} \((f+g)(x) = f(x) + g(x)\)
        \item \textbf{Differnce} \((f-g)(x) = f(x) - g(x)\)
        \item \textbf{Product} \((fg)(x) = f(x)g(x)\)
        \item \textbf{Quotient} \((\dfrac{f}{g} )(x) = \dfrac{f(x)}{g(x)} \)
              where \(g(x) \ne 0\)
        \item \textbf{Compostion} \((f\circ g)(x) = f(g(x))\)
    \end{itemize}

\end{theorem}

\begin{exmp}
    if \(f(x) = 2x + 3\) and \(\quad g(x) = 2x - 3\), then what is \(fg(4)\)?
\end{exmp}
\(sloution\) \( (fg)(x) = (2x+3)(2x-3) \) Thus \((fg)(4) = 55\).
\subsection{Domain and Range of a Composite Function}
The domain of a composite function is the intersection of domains of the starting
and final function.

\noindent
The range of a composite function is the range of the final function restricted by the
starting function.

\begin{exmp}
    let \(f(x) = \dfrac{1}{x+2}\) and \( \dfrac{x}{x-3} \).
    Then \(g(x)\) is the starting function and \( f(g(x)) \) is the final
    function. Find the domain and range of \(f(g(x))\).
\end{exmp}

\noindent
\(sloution\) \(f(g(x)) = \dfrac{1}{\dfrac{x}{x-3} + 2}\) so \(x \ne 3\),
impleing the domain is \framebox[\width]{ \(x \ne 2,3\) }.

\begin{exmp}
    If \(f(x) = \sqrt{x}\) and \(g(x) = x - 1\), what is the domain and range
    of \((g\circ f)(x)\)?
\end{exmp}
\noindent
\(sloution\) \((g\circ f)(x) = \sqrt{x} - 1\) it's obivious that \(x \ge 0\),
and all other values work, so the domain is \framebox[\width]{ \(0 \le x < \infty \ \)}
. Since \( \sqrt{x} \ge 0\)we have \((g\circ f)(x) \ge -1\), with no other restrictions,
so the range is \framebox[\width]{ \([-1,\infty] \) }.

\section{Types of Functions}
\subsection{Piecewise-Defined Function}
A piecewise function is a function that is defined by two or more equations over a
specified domain.

\begin{exmp}
    let \(f(x) = |x|\) Then
    \[ f(x) =
        \begin{cases}
            x  & \text{if } x \ge 0 \\
            -x & \text{if } x < 0
        \end{cases}
    \]

\end{exmp}

\begin{exmp}
    What are the domain and range of the piecewise function as follows?
    \[
        f(x) =
        \begin{cases}
            x^2 + 1 & x < 0   \\
            x - 1   & x \ge 0
        \end{cases}
    \]
\end{exmp}

\(sloution\). The domain includes \(x < 0 \) and \(x \ge 0\),
which is all values, so the domain is
\framebox[\width]{ \((-\infty, \infty)\) }. for \(x \ge 0\), we have \(f(x) = x - 1\),
so the range is \(y \ge -1\). For \(x < 0\) we have \(f(x) = x^2 + 1\), so the range is \(y > 1\).
Thus the range together is \framebox[\width]{ \([-1, \infty )\) }

\section{Properties of Functions}
\subsection{Odd and Even Functions}
A function \(f\) is even if \(f(x) = f(-x)\)

\begin{figure}[ht]
    \begin{small}
        \begin{center}
            \includegraphics[width=0.75\textwidth]{../out/even.png}
        \end{center}
        \caption{Graph of an even function.}
        \label{fig: Even Function}
    \end{small}
\end{figure}

\pagebreak
A function \(f\) is odd if \(f(x) = - f(-x)\)

\begin{figure}[H]
    \begin{small}
        \begin{center}
            \includegraphics[width=0.75 \textwidth]{../out/odd.png}
        \end{center}
        \caption{Graph of an odd function.}
        \label{fig: Odd Function}

    \end{small}
\end{figure}

Note that
\begin{itemize}
    \item Reflecting an even function across the y-axis yields the same function, and
    \item Rotating an odd function across the x-axis also yields the same function.
\end{itemize}

\begin{theorem}[Parity of Functions Comes From Its Components]
    if \(h(x) = f(x) + g(x)\)then
    \(h(x)\) is even if \(f(x)\) and \(g(x)\) are both even,
    and \(h(x)\) is odd if \(f(x)\) and \(g(x)\) are both odd.
\end{theorem}

\begin{exmp}
    Is \(f(x) = x^3 - 2x\) odd, even, neither?  \\

    \(sloution\) Note thr \(f(-x) = -x^3 + 2x = -f(x)\) implying it's odd.
\end{exmp}

\section{Inverse Functions}
An inverse function is a function that reverses function \(f\).
If \(f\) is a function mapping \(x\) to \(y\),
then the inverse function of \(f\) maps \(y\) back to x. The
inverse function of f is usually denoted by \(f^{-1}\)

\begin{itemize}
    \item If \(f^{-1}\) exists, Then \(f^{-1}(f(x)) = f(f^{-1}(x)) = x\).
    \item The graph of the inverse is the graph of the function reflected across
          \(y = x\).2
\end{itemize}

\begin{exmp}
    what's the inverse function of \(f(x) = \dfrac{3x-5}{2}? \)
    \\

    \(sloution\) if we switch \(x\) and \(y\) we get \(x = \dfrac{3y-5}{2}
    \Rightarrow \) \framebox[1.1\width]{\(f^{-1}(x) = \dfrac{2x+5}{3}\)}.
\end{exmp}
\subsection{Existence of an Inverse Function}
\begin{definition}[One to one]
    If a function satisfies the property that each x-value corresponds to one y-value, and
    each y-value corresponds to one x-value, then the function is one-to-one.
\end{definition}
\begin{theorem}[Inverse Function Criterion]
    If a function \(f\) is one-to-one, then its inverse is a function. More specifically, f is
    one-to-one if \(f\) is increasing/decreasing on its entire domain
\end{theorem}
\begin{theorem}[Horizontal Line Test]
    If you can draw a horizontal line passing through more than one point of a function
    on a graph, its inverse is not a function. If you cannot, it is a function.
\end{theorem}
This makes a lot of sense, since the graph of the inverse is just the function flipped
across the \(y = x\) line. This also makes it a lot easier to draw graphs.

\begin{exmp}
    Does the function \(f(x) = \sqrt{x-2} + 3\) have an inverse function?

    \begin{figure}[H]
        \begin{small}
            \begin{center}
                \includegraphics[width=0.75 \textwidth]{../out/inverse.png}
            \end{center}
            \caption{Graph of square root function.}
            \label{fig: invetable Function}

        \end{small}
    \end{figure}
\end{exmp}
\section{problmes}
TO BE ADDED
\end{document}


% Created 2018-04-11 mié 19:09
\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{amssymb}
\usepackage{hyperref}
\tolerance=1000
\usepackage{khpreamble}
\usepackage{pgfplots}
\author{Kjartan Halvorsen}
\date{Due Friday 2017-03-15}
\title{Computerized control - homework 4}
\hypersetup{
  pdfkeywords={},
  pdfsubject={},
  pdfcreator={Emacs 24.5.1 (Org mode 8.2.10)}}
\begin{document}

\maketitle

\section*{An observer for the harmonic oscillator model}
\label{sec-1}
The harmonic oscillator model, which in continuous-time has poles in \(\pm i\omega\), can be described in discrete-time as the state-space model
\begin{equation}
\begin{aligned}
x(kh+h) &= \underbrace{\bbm \cos\omega{}h & \frac{1}{\omega} \sin\omega h\\ -\omega\sin\omega h & \cos\omega h\ebm}_{\Phi(h)} x(kh) + \underbrace{\bbm \frac{1}{\omega^2}(1-\cos\omega h)\\\frac{1}{\omega}\sin\omega h\ebm}_{\Gamma(h)} u(kh)\\
y(kh) &= \underbrace{\bbm 1 & 0\ebm}_{C} x(kh)
\end{aligned}
\end{equation}

\begin{enumerate}
\item Determine the eigenvalues of \(\Phi(h)\) (the discrete-time poles of the system). Verify that the poles are the same as obtained through the relationship \(p = \mexp{\lambda h}\) where \(\lambda\) is the continuous-time pole and $p$ is the discrete-time pole.
\item Form the observability matrix \[W_c = \bbm C\\ C\Phi(h) \ebm\] and determine for which values of $h$ the system becomes unobservable.
\item The observer for the system is given by the state-space system
\[ \hat{x}(kh+h) = (\Phi - KC) \hat{x}(kh) + \Gamma(h) u(kh) + Ky(kh) \]
Let \(\omega h = \frac{\pi}{6}\) and determine a gain vector \(K = \bbm k_1 & k_2 \ebm\transp \) that gives a deadbeat observer, i.e. an observer with characteristic polynomial \(z^2\) and poles in the origin.
\end{enumerate}

\section*{Active suspension}
\label{sec-2}
A model of the front suspension of a motorcycle is shown in the figure \ref{fig:quarter}. This model can also be a so-called \emph{quarter model} for the suspension of a car.  The system consists of two masses. The \emph{sprung mass} is the larger of the two masses, and is about half the mass of the motorcyle and rider. The other mass is the much smaller \emph{unsprung mass}, which consists of the mass of the wheel, tyre and part (approximately half) of the suspension system. The two masses are connected by two passive elements: a spring and a damper, as well as an active element: a linear force actuator. The unsprung mass is connected to the ground via a spring representing the tyre (sometimes there is also a damper included in the model of the tyre).
\begin{figure}
\begin{center}
\includegraphics[width=0.65\linewidth]{../figures/active-suspension-nodamper}
\caption{Active suspension model. The heights $h_1(t)$, $h_2(t)$ and $h_g(t)$ are measured with respect to a stationary frame of reference. The vehicle is moving to the right.}
\label{fig:quarter}
\end{center}
\end{figure}

The reference height of the road surface is $h_g = h_0$. When the vehicle is travelling on a horizontal road of this height and the system is in equilibrium, the height of the two masses will be $h_1=h_{1,0}$ and $h_2 = h_{2,0}$, respectively. Introduce deviations from these reference heights
\begin{align*}
h_1(t) &= h_{1,0} + z_1(t)\\
h_2(t) &= h_{2,0} + z_2(t)\\
h_g(t) &= h_{0} + w(t)
\end{align*}

A slightly more complex model is discussed \href{http://ctms.engin.umich.edu/CTMS/index.php?example=Suspension&section=ControlStateSpace}{here}. That model also includes a damping in the tyre. You are welcome to study the example.

\subsection*{Determine the state space model}
\label{sec-2-1}
There are four forces acting on the sprung mass
\begin{center}
\begin{tikzpicture}
\node (M1) [draw, align=center, minimum width=3.5cm,minimum height=2cm] {Body mass};
\draw[->, thick] (M1.center) -- node[left, near end] {$m_1g$} ++(0, -3cm);
\draw[<-, thick] (M1.south) ++(-1cm, 0) -- node[left, near end] {$F_s$} ++ (0, -3cm);
\draw[<-, thick] (M1.south) ++(1cm, 0) -- node[left, near end] {$F_d$} ++ (0, -3cm);
\draw[<-, thick] (M1.south) ++(0.2cm, 0) -- node[right, near end] {$u$} ++ (0, -1.76cm);
\end{tikzpicture}
\end{center}
The equation of motion in the vertical direction becomes
\begin{equation}
 \begin{split}
 m_1 \ddot{z}_1 &= \sum_i F_i = -m_1g + \underbrace{m_1g -k_1(z_1-z_2)}_{F_s} + \underbrace{\big(-b_1(\dot{z}_1 - \dot{z}_2) \big) }_{F_d} + u  = -k_1(z_1 - z_2) - b_1(\dot{z}_1 - \dot{z}_2) + u\\
                &= -k_1z_1 -b_1\dot{z}_1 + k_1z_2 + b_1\dot{z}_2 + u.
 \end{split}
 \label{eq:eom1}
 \end{equation}
On the unsprung mass, there are five forces acting:
\begin{center}
\begin{tikzpicture}
\node (M2) [draw, align=center, minimum width=3.5cm,minimum height=2cm] {Suspension mass};
\draw[->, thick] (M2.center) -- node[left, near end] {$m_2g$} ++(0, -3cm);
\draw[<-, thick] (M2.north) ++(-1cm, 0) -- node[left, near end] {$F_s$} ++ (0, 3cm);
\draw[<-, thick] (M2.north) ++(1cm, 0) -- node[left, near end] {$F_d$} ++ (0, 3cm);
\draw[<-, thick] (M2.north) ++(0cm, 0) -- node[right, near end] {$u$} ++ (0, 1.76cm);
\draw[<-, thick] (M2.south) ++(0.2cm, 0) -- node[right, near end] {$F_t$} ++ (0, -3.76cm);
\end{tikzpicture}
\end{center}
The equation of motion in the vertical direction becomes
\begin{equation}
\begin{split}
m_2\ddot{z}_2 &= -m2_g - \underbrace{\big(m_1g -k_1(z_1-z_2)\big)}_{F_s}
 - \underbrace{\big(- b_1(\dot{z}_1-\dot{z}_2)\big)}_{F_d}
 - \underbrace{\big( (m_1 + m_2)g - k_2(z_2 - w) \big)}_{F_t} - u\\
               &= (k_1)z_1 + b_1\dot{z}_1 - (k_1+k_2)z_2 - b_1\dot{z}_2 + k_2w - u
 \end{split}
 \end{equation}

Use the state-vector
\[ x = \bbm x_1\\x_2\\x_3\\x_4 \ebm = \bbm z_1\\ \dot{z}_1 \\ z_2\\ \dot{z}_2 \ebm \]
and let the velocity of the sprung mass $y(t) = \dot{z}_1(t)$ be the output of the system.
\textbf{Set up the continous-time state-space model}
\begin{equation*}
\begin{aligned}
\dot{x}(t) &= Ax(t) + B_u u(t) + B_w w(t)\\
y(t) &= C x(t)
\end{aligned}
\end{equation*}
Note that there are two input signals: The active suspension force $u(t)$ and the disturbance from the road $w(t)$.

\subsection*{Simulate step-responses}
\label{sec-2-2}
Implement the model in matlab. Use the following values for the parameters
\begin{center}
\begin{tabular}{l}
$m1 = 140$\\
$m2 = 14$\\
$k1 = 4.6\cdot{}10^4$\\
$k2 = 3.0\cdot{}10^5$\\
$b1 = 10^3$\\
\end{tabular}
\end{center}
Here is some code to help you
\begin{verbatim}
m1 = 140;
m2 = 14;
k1 = 4.6e4;
k2 = 3.0e5;
b1 = 1e3;

A =   % Your code here

Bu = [0
     1/m1
     0
     -1/m2 ];
Bw = [ 0
      0
      0
      k2/m2];
C =   % Your code here
D=[0];
sys_uy=ss(A,Bu,C,D); % System with only u(t) as input
sys_wy=ss(A,Bw,C,D); % System with only w(t) as input

% Step responses
figure(1)
clf
subplot(121)
stepplot(1000*sys_uy);
title('Response from u (step 1kN)')
xlabel('Time [s]')
ylabel('y [m/s]')
subplot(122)
stepplot(0.1*sys_wy);
title('Response from w (step 0.1m)')
xlabel('Time [s]')
ylabel('y [m/s]')
\end{verbatim}

\subsection*{Sample the system}
\label{sec-2-3}
\begin{enumerate}
\item The system is quite oscillative, as the step-responses show. Plot the poles of the continuos-time system using \texttt{pzmap}
\begin{verbatim}
figure(2)
pzmap(sys_uy)
\end{verbatim}
Choose a sampling period $h$, such that $\omega_0h = 0.8$, where $\omega_0$ is the natural frequency (in radians per second) of the fastest poles.
\item Sample the system numerically using \texttt{c2d} in matlab:
\begin{verbatim}
h = % Your code here
sys_uy_d  = c2d(sys_uy, h); % Zero-order-hold sampling
sys_wy_d  = c2d(sys_wy, h); % Zero-order-hold sampling
\end{verbatim}
\end{enumerate}

\subsection*{Determine a state feedback}
\label{sec-2-4}
\begin{enumerate}
\item First determine the desired poles. The system is fourth order, so we need to choose four poles for the closed-loop system. Assume we want the closed-loop system to have more or less the same speed as the two fastest open-loop poles (same distance from the origin), but more damped.  Determine the four desired closed-loop continuous-time poles, and then translate them to discrete time:
\begin{verbatim}
p_c = [ ] % Your four desired closed-loop poles in continuous-time here
p_d = exp(p_c*h) % The corresponding four discrete-time poles
\end{verbatim}
\item Determine the feedback gain vector \(L\), and form the closed-loop system. Matlab will happily do the calculations for you:
\begin{verbatim}
[Phi, Gamma_u, C, D] = ssdata(sys_uy_d) % Get the matrices
[Phi, Gamma_w, C, D] = ssdata(sys_wy_d)
L = place(Phi, Gamma_u, p_d)
sys_wy_d_closed = ss(Phi-Gamma_u*L, Gamma_w, C, D, h); % Closed-loop system from w to y
\end{verbatim}
\end{enumerate}

\subsection*{Simulate the closed-loop response}
\label{sec-2-5}
Check the performance of your closed-loop system. Let the disturbance (road profile) look as below
\begin{center}
\begin{tikzpicture}
\begin{axis} [
   width = 12cm, height = 4cm,
   xlabel = {$t$ [s]},
   ylabel = {$w(t) [m]$},
   xmin = -0.5, xmax = 10,
   ymin = -0.5, ymax = 0.5,
   ]
   \draw[thick] (axis cs: -0.5,0) -- (axis cs: 0,0) -- (axis cs: 0,0.3) -- (axis cs: 2,0.3) -- (axis cs: 2,-0.3) -- (axis cs: 4,-0.3) -- (axis cs: 4, 0) -- (axis cs: 10,0);
   \end{axis}
   \end{tikzpicture}
   \end{center}

In matlab:
\begin{verbatim}
T = ( 0:ceil(10/h) )*h; % Discrete time-vector from 0 to 10 seconds
w = zeros(size(T));
ind_before_2 = find(T < 2);
w(ind_before_2) = 0.3;
ind_between_2_and_4 = intersect( find(T>2), find(T<4) );
w(ind_between_2_and_4) = -0.3;

[y, Tsim, x] = lsim(sys_wy_d_closed, w, T);
[yo, Tsim, xo] = lsim(sys_wy_d, w, T); % Simulate system without feedback

figure(3)
set(gcf, 'position', [100, 100, 900, 700])
for i=1:4
    subplot(5,1,i)
    stairs(T, x(:,i), 'color', [0, 0.447, 0.741])
    hold on
    stairs(T, xo(:,i), 'color', [0.85, 0.325, 0.098])
    ylabel(sprintf('state %d', i))
    xlabel('Time [s]')
end
legend('Closed-loop response', 'Open-loop response')
subplot(5,1,5)
stairs(T, -L*x', 'color', [0, 0.447, 0.741])
ylabel('Control signal [N]')
\end{verbatim}

\textbf{Comment on the figures!} For instance: How do the closed-loop system response compare to the open-loop response? What was the maximum active suspension force (\(\max u(t)\))?

\section*{Solutions}
\label{sec-3}

\subsection*{An observer for the harmonic oscillator model}
\label{sec-3-1}
\begin{enumerate}
\item The eigenvalues are given by the roots of \(\det (zI - \Phi)\). Writing \(\cos\omega h = c\) and \(\sin\omega h = s\) for simplicity, we get
\begin{equation*}
\begin{aligned}
\det (zI - \Phi) &= \det \left( \bbm z & 0\\0 & z\ebm - \bbm c & \frac{s}{\omega}\\-\omega s & c\ebm \right) = \det \bbm z-c & -\frac{s}{\omega}\\ \omega s & z-c\ebm \\
&= (z-c)^2 + s^2
\end{aligned}
\end{equation}
with roots on the unit circle:
\[ z = c \pm is = \cos\omega h \pm i \sin\omega h.\]
Using the relationship \(z = \mexp{sh}\) between the s-plane and the z-plane we get for the continous-time poles \(s=\pm i\omega\)
\[ z = \mexp{\pm i\omega h} = \cos\omega h \pm i\sin\omega h \]
using Euler's formula.
\item The observability matrix becomes
\[ W_c = \bbm C\\C\Phi \ebm = \bbm 1 & 0\\ c & \frac{s}{\omega},\] so
\[ \det W_c = \frac{1}{\omega} \sin\omega h \]
which is zero for \(\omega h = k\pi, \; k=1,2,\ldots\). So observability is lost for
\[ h = \frac{k\pi}{\omega}, \; k=1,2\ldots. \]
\item With \(\omega=1\) and \(h=\frac{\pi}{6}\) we get \(\cos\omega h = \sqrt{3}/2\) and \(\sin\omega h = 1/2\). This gives
\end{enumerate}
\[ \Phi = \frac{1}{2} \bbm \sqrt{3} & 1\\-1 & \sqrt{3} \ebm\].
The characteristic polynomial of the observer becomes
\begin{equation*}
\begin{aligned}
\det \big(zI - (\Phi - KC)\) &= \det  \left( \bbm z & 0\\0 & z\ebm - \frac{1}{2} \bbm \sqrt{3} - 2k_1 & 1\\-1-2k_2 & \sqrt{3}\ebm\\
&= \det \bbm z-\frac{\sqrt{3}-2k_1}{2} & -\frac{1}{2}\\\frac{1+2k_2}{2} & z - \frac{\sqrt{3}}{2} \ebm\\
&= (z-\frac{\sqrt{3}-2k_1}{2})(z - \frac{\sqrt{3}}{2}) + \frac{1+2k_2}{4}\\
&= z^2 - (\sqrt{3}-k_1)z + \frac{1}{4}\big( \sqrt{3}(\sqrt{3}-2k_1) + 1 + 2k_2\big)\\
&= z^2 - (\sqrt{3}-k_1)z + \frac{1}{4}\big(-2\sqrt{3}k_1 + 2k_2 + 4\big)
\end{aligned}
\end{equation*}
Setting coefficient equal to the coefficients of the desired characteristic polynomial \(z^2\) gies
\begin{align*}
\sqrt{3}-k_1 &= 0 \quad \Rightarrow \quad k_1 = \sqrt{3}\\
-2\sqrt{3}k_1 + 2k_2 + 4 &= 0 \quad \Rightarrow \quad k_2 = 3-2 = 1
\end{align*}

\subsection*{Active suspension}
\label{sec-3-2}
\subsubsection*{State space model}
\label{sec-3-2-1}
With the state vector
 \[ x = \bbm x_1\\x_2\\x_3\\x_4 \ebm = \bbm z_1\\ \dot{z}_1 \\ z_2\\ \dot{z}_2 \ebm \]
 we can write the four first-order differential equations of the state space model
 \begin{align*}
  \dot{x}_1 &= \dot{z}_1 = x_2\\
  \dot{x}_2 &= \ddot{z}_1 = \frac{1}{m_1}\Big(-k_1z_1 -b_1\dot{z}_1 + k_1z_2 + b_1\dot{z}_2 + u\Big)\\
            &= -\frac{k_1}{m_1}x_1 - \frac{b_1}{m_1}x_2 + \frac{k_1}{m_1}x_3 + \frac{b_1}{m_2}x_4 + \frac{1}{m_1} u\\
  \dot{x}_3 &= \dot{z}_2 = x_4\\
  \dot{x}_4 &= \ddot{z}_2 = \frac{1}{m_2} \Big(k_1z_1 + b_1\dot{z}_1 - (k_1+k_2)z_2 - b_1\dot{z}_2 + k_2w - u\Big)\\
            &= \frac{k_1}{m_2} x_1 + \frac{b_1}{m_2} x_2 - \frac{k_1+k_2}{m_2}x_3 + -\frac{b_1}{m_2}x_4 + \frac{k_2}{m_2}w - \frac{1}{m_2}u.
\end{align*}
In state-space form, this can be written
\begin{align*}
\dot{x} &= \bbm 0 & 1 & 0 & 0\\
-\frac{k_1}{m_1} & -\frac{b_1}{m_1} & \frac{k_1}{m_1} & \frac{b_1}{m_1}\\
0 & 0 & 0 & 1\\
\frac{k_1}{m_2} & \frac{b_1}{m_2} & -\frac{k_1+k_2}{m_2} & -\frac{b_1}{m_2}\ebm
\bbm x_1\\x_2\\x_3\\x_4 \ebm + \bbm 0\\0\\0\\\frac{k_2}{m_2} \ebm w + \bbm 0\\\frac{1}{m_1}\\0\\-\frac{1}{m_2} \ebm u \\
y &= \bbm 0 & 1 & 0 & 0 \ebm x.
\end{align*}

\subsubsection*{step-responses}
\label{sec-3-2-2}
The figure below shows the step-responses of both the continuous- and the sampled systems.
\begin{center}
\includegraphics[width=0.6\linewidth]{active-susp-plant-response}
\end{center}

\subsubsection*{Sampling the system}
\label{sec-3-2-3}
\begin{enumerate}
\item The pole-zero map below shows that the fast poles have a distance of \(\omega = 156\) rad/s to the origin. The rule-of-thumb (chapter 2.9 in the textbook) tells us that we should have \(\omega h \approx 0.2 -- 0.6\). For instance,
\[ h = \frac{0.6}{156} \approx \unit{0.004}{\second}. \]
\item Sampling the system is straightforward
\begin{verbatim}
h = 0.004;
sys_uy_d = c2d(sys_uy, h); % The system from input u to y
sys_wy_d = c2d(sys_wy, h); % From input w to y
\end{verbatim}
\end{enumerate}
\subsubsection*{State feedback}
\label{sec-3-2-4}
\begin{enumerate}
\item Desired closed-loop poles. The idea is to choose the poles to be equally fast, but more damped than the fast poles of the plant. For instance we can choose the set of four poles
\[ p_{1,2} = -\zeta_1\omega_n \pm i \sqrt{1 - \zeta_1^2}\omega_n,  \quad
               p_{3,4} = -\zeta_2\omega_n \pm i \sqrt{1 - \zeta_2^2}\omega_n \]
with natural frequency \(\omega_n = 156\), and damping ratio \(\zeta_1 = 0.8\) and \(\zeta_2 = 0.6\).
\item The feedback vector is calculated by Matlab and gives
$\backslash$[ L = \bbm l$_{\text{1}}$ \& l$_{\text{2}}$ \& l$_{\text{3}}$ \& l$_{\text{4}}$ \ebm = \bbm 1.89$\cdot$ 10$^{\text{6}}$ \& 3.85 $\cdot$ 10$^{\text{4}}$ \& -3.23$\cdot$ 10$^{\text{5}}$ \& 6.20 $\cdot$ 10$^{\text{2}\ebm}$.
\end{enumerate}

\subsubsection*{Simulations}
\label{sec-3-2-5}
With the state feedback proposed, the response is as shown in the figure below.
\begin{center}
\includegraphics[width=\linewidth]{../matlab/active-suspension-sim-crop}
\end{center}
We can see that the closed-loop response of \(z_1\) and \(\dot{z}_1\) are both very well damped, and has much smaller amplitude than the open-loop system. The control signal shows quite large peak (30-50 kN) at the onset of the disturbances.

\subsubsection*{Choosing the closed-loop poles too slow.}
\label{sec-3-2-6}
There is a potential problem with choosing the closed-loop poles (much) slower than the open-loop poles in this exercise. Slow poles in discrete-time means close to 1. The reason is that state feedback does not change the numerator in the pulse transfer function from input to output.  So, if the open-loop pulse transfer function from disturbance to output signal is
\[ H_w(z) = C (zI-\Phi)^{-1} \Gamma_w = \frac{\beta(z)}{\alpha(z)},\]
then the closed-loop transfer function will be
\[ H_c(z) = C \big(zI -(\Phi-\Gamma_u L)\big)^{-1}\Gamma_w = \frac{\beta(z)}{\alpha_c(z)}.\]
The denominator is obtained by design (choice of pole placement) to have the roots (desired closed-loop poles) \(p_{d,1}\),  \(p_{d,2}\),  \(p_{d,3}\),  \(p_{d,4}\), so
\[ H_c(z) = \frac{\beta(z)}{(z-p_{d,1})(z-p_{d,2})(z-p_{d,3})(z-p_{d,4})}.\]
The static gain becomes
\[ H_c(1) = \frac{\beta(1)}{(1-p_{d,1})(1-p_{d,2})(1-p_{d,3})(1-p_{d,4})},\]
which can be much larger than the open-loop static gain \(H_w(1)\), if the closed-loop poles are much closer to 1 than the open-loop poles.
% Emacs 24.5.1 (Org mode 8.2.10)
\end{document}


\subsection{The equation of exchange}

As there’s only so much stuff out there, an increase in the amount of money moving around with cause inflation.

This can be shown as:

\(MV=PQ\)

The amount of money (M) multiplied by the velocity at which money moves (V) must be equal to the average price (P) multiplied by the quantity of stuff (Q). This isn’t a theory, it’s an accounting identity.


\documentclass[12pt]{article}

\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{graphicx}

% collectivised from: https://www.overleaf.com/learn/latex/Theorems_and_proofs#Theorem_styles
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
%
\begin{document}
%Plan
%   1. Introduction
%       Original problem: US graphs and edge coloration with \omega = 2.
%       Known for delta 2. we know delta is at most 5. Concept of direction.
%   2. On a grid
%       "what we will do here: ... ". RK: if not all on a grid are US, all US are on a grid. Thus any result on on a grid graph is true for US.
%       2.1 On a grid - definition.
%       2.2 Additional concepts: Type 1/2 diagonals, order on the diagonals.
%       2.3 Algorithm
%       2.4 Complexity
%   3. Applications
%       3.1 US graphs: chromatic index of 4
%       3.2 angles & directions
\section{Introduction}
The original problem is to study the chromatic index of triangle-free \textit{unit square intersection graphs},
which are graphs that are obtained for a family of unit squares.
Each square is represented by a vertex in a graph, and each edge represent the fact that two squares are intersecting. \\
We already know that when the maximum degree $\Delta$ is $2$, there may exists graphs of type 2, for instance any odd cycle. We can also observe that
when two unit squares intersects, there is a corner of each inside the other; from this observation follows that there cannot be
a triangle-free unit square graph with $\Delta \ge 5$. \\
In what follows, we provide a proof that there cannot be a graph of type 2 when $\Delta = 4$. The proof will be done by introducing a new way to
represent the graphs by using a grid; and we will call them \textit{on a grid} graphs.

\section{Graphs on-a-grid}
We present in this section a proof that unit square graphs are also \textit{on a grid} graphs.
\subsection{On a grid}
\begin{definition}[On a grid]
    A graph is said \textit{on a grid} if:
    \begin{itemize}
        \item All the edges are either parallels or perpendicular.
        \item All the edges are of integer lengths.
        \item No edge is overlapping or containing an other edge in more than one point.
    \end{itemize}
\end{definition}

Instead of using the usual directions of the cartesian plane, we will rotate all the edges by $\tfrac{\pi}{4}$ as it will be more convenient later.
The graph represented in Fig.1. is \textit{on a grid}.

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.2]{tex_images/on_a_grid_g1.png}
    \caption{$G_1$ is on a grid.}
\end{figure}

\begin{remark}
    $G_1$ has exactly $10$ edges.
\end{remark}

\subsection{Additional concepts}

\begin{definition}[Direction of intersection]
    Let $a, b$ be two unit squares. We say that $a$ intersects $b$ in UR direction (resp. UL, DL, DR) if the up-right (resp up-left, down-left, down-right) corner
    of $a$ is inside $b$.
\end{definition}

\begin{figure}[h]
    \centering
    \includegraphics[scale = 0.3]{tex_images/same_diagonals.png}
    \caption{Illustration of direction of intersections.}
\end{figure}

For instance, in Fig. 2, $D$ intersect $F$ in direction DR, $G$ in direction UR and $A$ in direction UL. Conversely, $A$ intersect $D$ in direction DR.

\begin{lemma}
    If $a$ intersect both $b$ and $c$ in the same direction, then $a, b$ and $c$ forms a triangle.
\end{lemma}

\begin{proof}
    Notice that they would all share a common point in a certain corner of $a$.
\end{proof}

\begin{definition}[Diagonals]
    Let $a$ and $b$ be two squares. They are said to be on the same \textit{Type 1 diagonal} (resp. Type 2) if you can find a sequence $\{s_1, ... s_k\}$ of squares such that:
    \begin{itemize}
        \item $s_1 = a$
        \item $s_k = b$
        \item $\forall i \in \{1, .. , k-1\}$, $s_i$ intersects $s_{i+1}$ in UL or DR (resp. UR or DL) direction.
    \end{itemize}
    A diagonal is a set of points (possibly trivial) that are on the same diagonal.
\end{definition}

\begin{remark}
    We will denote the diagonal as follows : $D:= \{d_1, ... , d_k\}$. In this case $d_1$ is the highest square of the diagonal, meaning that $d_1$ intersect $d_2$ in DR direction in the case of a type 1 diagonal, and so on.
\end{remark}

In Fig. 2 we can denote the following diagonals:\\
Type 1: $\{(A, D, F), (E), (I), (G, H)\}$\\
Type 2: $\{(A), (D,G), (F, E, I, H)\}$\\

\begin{lemma}
    Let $D$, $E$ be two diagonals of the same type. If we can find $d \in D$; $e \in E$ such that $d$ intersect $e$ in some direction X, then: \\\
    $\forall d' \in D$, $\forall e' \in E$, either $e'\cap d' = \emptyset$ or $d'$ intersect $e'$ in direction X.
\end{lemma}

\begin{proof}
    Without loss of generality, let $D:=\{d_1, ... d_k\}$ and $E:= \{e_1, ... e_l\}$ be two distinct diagonals of Type 1.
    Suppose $d_1$ intersect $e_1$ in direction DL. \\
    Let $(i,j)$ be the smallest couple different from $(1,1)$ such that $d_i \cap e_j \ne \emptyset$. Observe that as $D$ and $E$ are Type 1, the only possibility is that
    $d_i$ intersect $e_j$ in direction UR or DL.
\end{proof}

We can now use the previous lemma to define a partial order on our diagonals.

\begin{definition}[Order on diagonals]
    Let $D_1$, $D_2$ two diagonals of Type 1 (resp Type 2). We say that $D_1$ is \textit{directly higher} than $D_2$, or $D_1 >_d D_2$ if:
    $\exists d_1 \in D_1, \exists d_2 \in D_2$ such that $d_1$ intersects $d_2$ in DL (resp. UR) direction. \\ \\
    We say that $D_1$ is higher than $D_2$, or $D_1 > D_2$ if we can find a sequence of diagonals $\{s_1, ... , s_k\}$ such that:
    \begin{itemize}
        \item $s_1 = D_1$
        \item $s_k = D_2$
        \item $\forall i \in \{1, ..., k-1\}, s_i >_d s_{i+1}$
    \end{itemize}
\end{definition}

%% TODO: explain why we cant have D >_d E and E >_d D at the same time

\begin{remark}
    Note that $>_d$ is not an order as it is not transitive.
\end{remark}

\subsection{From unit squares to the grid}

We present here an algorithm to obtain a on a grid graph given a family of unit squares.\\
Start by identifying all the diagonals: to do so,

\section{Some applications}
\subsection{Edge coloration}

One can easily see that any on a grid graph has a chromatic index of at most $4$. As every triangle-free unit square graph is also on a grid,
it follows that no graph of type 2 can exist for these if $\Delta = 4$.

\begin{theorem}
    Let $G$ be a unit square graph, with $\Delta = 4$ and $\omega = 2$. Then $\chi'(G) = 4$.
\end{theorem}

\begin{proof}
    It is sufficient to show it is true for all graphs that are on a grid. \\
    Let $G$ be on a grid. Delete for a moment all the edges that correspond to type 1 diagonals. There subsits only paths.
    As all paths can be colored using only two colors, assign color 1 or 2 to all the remaining edges. \\
    Do the same thing for the type 2 diagonals with colors 3 and 4. \\
    As all the edges of $G$ are either on a type 1 or a type 2 diagonal, all the edges are assigned to a color. If two edges are on the same type of diagonals, either they
    have different colors or they are not adjacent. If two edges are on different type of diagonals, they have different colors. Therefore, this coloration is acceptable.
\end{proof}

\subsection{Directions in cycles}

\end{document}


\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{geometry}
\usepackage{enumerate}
\usepackage{natbib}
\usepackage{float}%稳定图片位置
\usepackage{graphicx}%画图
\usepackage[english]{babel}
\usepackage{a4wide}
\usepackage{indentfirst}%缩进
\usepackage{enumerate}%加序号
\usepackage{multirow}%合并行

\begin{document}
\newpage
\section{Problem 1}
\subsection{(a)}
$$I_c=I_s \exp(\frac{q V_{BE}}{KT}-1)(1+\frac{V_{CE}}{V_A})=10^{-16}\exp(\frac{0.7}{0.0259}-1)(1+\frac{V_{CE}}{100})=5.47\cdot10^{-5}*(1+0.01*V_{OUT})$$
$$V_{OUT}=V_{CC}-R_c*I_c=3-5000I_c$$
$$V_{OUT}=2.72(V)$$
$$I_c=\frac{3-2.9}{5000}=5.6\cdot10^{-5}(A)$$
$$gm=\frac{q\cdot I_c}{KT}=\frac{5.6\cdot10^{-5}}{0.0259}=2.162\cdot10^{-3}$$
$$r_0=\frac{V_A}{I_c}=\frac{100}{2.07\cdot 10^{-5}}=1.79\cdot10^{6}(\Omega)$$
$$A_v=-gm(R_c||r_0)=-2.162\cdot10^{-3}\cdot\frac{5000*1.79\cdot10^{6}}{5000+1.79\cdot10^{6}}=-10.78$$
\subsection{(b)}
\begin{figure}[H]
\centering
\includegraphics[scale=0.25]{P1.png}
\end{figure}
$$A_v=\frac{18}{-1.7}=-10.6$$
The slope is about -10.6, which is a little bigger than calculated one in (a)
\subsection{(c)}
\begin{figure}[H]
\centering
\includegraphics[scale=0.25]{P2.png}
\end{figure}
$$|A_v|=|\frac{(2.8-2.9)}{0.69-0.7}|\approx10$$
The value is very close to part (b) and (a) but the absolute value is a bit smaller.
\subsection{(d)}
\begin{figure}[H]
\centering
\includegraphics[scale=0.25]{P3.png}
\end{figure}
$$|A_v|=|\frac{(2.96-2.9)}{0.65-0.7}|\approx47.2$$
The value is much more greater than calculated one in previous part, I think it's because the amplitude is so big that the input signal can't be considered as a small signal any more. As a result, the derivative for $V_{BE}$ can't be applied any more gm has changed.
\end{document}