\documentclass{article}
\usepackage{eecstex}
\usepackage{pgfplots}

\title{EE 123 HW 02}
\author{Bryan Ngo}
\date{2022-01-29}

\begin{document}

\maketitle

\setcounter{section}{2}

\section{}

\begin{equation}
    a^n u[n] \iff \frac{1}{1 - ae^{-j \omega}}, \ |a| < 1
\end{equation}

\subsection{}

\begin{equation}
    x[n] = -b^n u[-n - 1] =
    \begin{cases}
        -b^n & n \leqslant -1 \\
        0 & n \geqslant 0
    \end{cases}
\end{equation}
Using the definition of the DTFT,
\begin{align}
    X(e^{j \omega}) &= \sum_{k \in \Z} -b^k u[-k - 1] e^{-j \omega k} \\
    &= -\sum_{k \leqslant -1} b^k e^{-j \omega k}
\end{align}
Letting \(k' = -k\),
\begin{align}
    X(e^{j \omega}) &= \sum_{k' \geqslant 1} -b^{-k'} e^{j \omega k'} \\
    &= \sum_{k \geqslant 0} -(b^{-1} e^{j \omega})^k - 1 \\
    &= 1 - \frac{1}{1 - b e^{j \omega}} \\
    &= \frac{\cancel{1} - b e^{j \omega} - \cancel{1}}{1 - b e^{j \omega}} \cdot \frac{-b e^{-j \omega}}{-b e^{-j \omega}} \\
    &= \frac{1}{1 - b e^{-j \omega}}
\end{align}
where \(|b^{-1}| < 1 \implies |b| > 1\).

\subsection{}

\begin{align}
    Y(e^{j \omega}) &= 2e^{-j \omega} \frac{1}{1 - (-2) e^{-j \omega}} \\
    \overset{\mathcal{F}^{-1}}{\implies} y[n] &= 2 (-(-2)^{n - 1} u[-(n - 1) - 1]) \\
    &= (-2)^n u[-n]
\end{align}

\newpage
\section{}

\begin{equation}
    H(z) = \frac{1 - z^{-1}}{1 - 0.25z^{-2}} = \frac{1 - z^{-1}}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1})}
\end{equation}

\subsection{}

Using the \(z\)-transform multiplication property,
\begin{equation}
    Y(z) = H(z) X(z) = \frac{\cancel{1 - z^{-1}}}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1}) \cancel{(1 - z^{-1})}} = \frac{1}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1})}
\end{equation}
Then, using partial fraction decomposition,
\begin{align}
    Y(z) &= \frac{1}{(1 - 0.5z^{-1}) (1 + 0.5z^{-1})} = \frac{A}{1 - 0.5z^{-1}} + \frac{B}{1 + 0.5z^{-1}} \\
    &= 1 = A(1 + 0.5z^{-1}) + B(1 - 0.5z^{-1}) \\
\end{align}
Letting \(z = -0.5\), we get \(B = \frac{1}{2}\).
Letting \(z = 0.5\), we get \(A = \frac{1}{2}\).
Then,
\begin{align}
    Y(z) &= \frac{1}{2} \frac{1}{1 - 0.5z^{-1}} + \frac{1}{2} \frac{1}{1 + 0.5z^{-1}} \\
    \overset{\mathcal{Z}^{-1}}{\implies} y[n] &= \frac{1}{2} \left(\frac{1}{2}\right)^n u[n] + \frac{1}{2} \left(-\frac{1}{2}\right)^n u[n]
\end{align}

\subsection{}

\begin{equation}
    y[n] = \delta[n] - \delta[n - 1] \overset{\mathcal{Z}}{\implies} Y(z) = 1 - z^{-1} = H(z) X(z)
\end{equation}
meaning that \(X(z) = 1 - 0.25z^{-2} = (1 - 0.5z^{-1}) (1 + 0.5z^{-1})\).
By definition of the \(z\)-transform,
\begin{equation}
    x[n] = \delta[n] - \frac{1}{4} \delta[n - 2]
\end{equation}

\subsection{}

Treating the input as the real part of \(z = e^{j 0.5 \pi}\),
\begin{equation}
    H(e^{j 0.5 \pi}) = \frac{1 - e^{-j 0.5 \pi}}{1 - 0.25e^{-j\pi}} = 0.8 \sqrt{2} e^{j \frac{\pi}{4}}
\end{equation}
Meaning that the final output is
\begin{equation}
    y[n] = 0.8 \sqrt{2} \cos\left(0.5 \pi n + \frac{\pi}{4}\right)
\end{equation}

\newpage
\section{}

\begin{align}
    x[n] &= -\frac{1}{3} \left(\frac{1}{2}\right)^n u[n] - \frac{4}{3} 2^n u[-n - 1] \\
    Y(z) &= \frac{1 - z^{-2}}{\left(1 - \frac{1}{2} z^{-1}\right) (1 - 2z^{-1})}
\end{align}

\subsection{}

\begin{equation}
    X(z) = -\frac{1}{3} \frac{1}{1 - \frac{1}{2} z^{-1}} + \frac{4}{3} \frac{1}{1 - 2z^{-1}}
\end{equation}

\subsection{}

\begin{equation}
    R_y: \frac{1}{2} < |z| < 2
\end{equation}

\subsection{}

Simplifiying \(X(z)\),
\begin{align}
    X(z) &= \frac{1}{3} \frac{-(1 - 2z^{-1}) + 4 \left(1 - \frac{1}{2} z^{-1}\right)}{\left(1 - \frac{1}{2} z^{-1}\right) (1 - 2z^{-1})} \\
    &= \frac{1}{3} \frac{-1 + \cancel{2z^{-1}} + 4 - \cancel{2z^{-1}}}{\left(1 - \frac{1}{2} z^{-1}\right) (1 - 2z^{-1})} \\
    &= \frac{1}{\left(1 - \frac{1}{2} z^{-1}\right) (1 - 2z^{-1})} \\
    \implies Y(z) &= (1 - z^{-2}) X(z) = X(z) - z^{-2} X(z) \\
    \overset{\mathcal{Z}^{-1}}{\implies} y[n] &= x[n] - x[n - 2]
\end{align}

\subsection{}

\begin{equation}
    H(z) = \frac{Y(z)}{X(z)} = 1 - z^{-2} \overset{\mathcal{Z}^{-1}}{\implies} h[n] = \delta[n] - \delta[n - 2]
\end{equation}

\newpage
\section{}

\begin{align}
    X(z) &= \frac{z^{-2}}{1 - 2.3z^{-1} + 1.6z^{-2} - 0.3z^{-3}} = \frac{2.04}{1 + 0.3z^{-1}} - \frac{3.47}{1 - z^{-1}} + \frac{1.43}{(1 - z^{-1})^2} \\
    \overset{\mathcal{Z}^{-1}}{\implies} x[n] &= (-0.3)^n u[n] - 3.47 u[n] + 1.43 (n + 1) u[n + 1]
\end{align}

\newpage
\section{}

\begin{enumerate}
    \item System A, causal, stable, ROC: \(|z| > 0.9\)
    \item System B, non-causal, stable, ROC: \(|z| < 1.111\)
    \item System A, non-causal, unstable, ROC: \(|z| < 0.9\)
\end{enumerate}

\newpage
\section{}

\begin{equation}
    Z(e^{j \omega}) = \frac{1}{2\pi} \int_{-\pi}^\pi X(e^{j \theta}) Y(e^{j (\omega - \theta)}) \, d\theta
\end{equation}

\subsection{}

\begin{align}
    Y(e^{j \omega}) &= \pi \sum_{k = -\infty}^\infty \delta(\omega - \pi + 2\pi k) + \delta(\omega + \pi + 2\pi k) \\
    X(e^{j \omega}) \ast Y(e^{j \omega}) &= \frac{1}{2} \int_{-\pi}^\pi X(e^{j \theta}) \sum_{k \in \Z} \delta((\omega - \theta) - \pi + 2\pi k) + \delta((\omega - \theta) + \pi + 2\pi k) \, d\theta \\
    &= \frac{1}{2} \sum_{k \in \Z} \int_{-\pi}^\pi X(e^{j \omega}) (\delta(\omega - \theta - \pi + 2\pi k) + \delta(\omega + \theta + \pi + 2\pi k)) \, d\theta \\
    &= \frac{1}{2} \sum_{k \in \Z} (X(e^{j (\omega - \pi + 2\pi k)}) + X(e^{j (\omega + \pi + 2\pi k)}))
\end{align}
\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            xlabel={\(\frac{\omega}{\pi}\)}, ylabel={\(Z(e^{j \omega})\)},
            title={DTFT of Product},
            axis lines=middle,
        ]
        \addplot[color=blue] table[
            col sep=comma,
            x=index, y=8a
        ]{q8.csv};
        \end{axis}
    \end{tikzpicture}
\end{center}

\subsection{}

\begin{align}
    Y(e^{j \omega}) &= \pi \sum_{k = -\infty}^\infty \delta\left(\omega - \frac{\pi}{2} + 2\pi k\right) + \delta\left(\omega + \frac{\pi}{2} + 2\pi k\right) \\
    X(e^{j \omega}) \ast Y(e^{j \omega}) &= \frac{1}{2} \sum_{k \in \Z} \left(X\left(e^{j \left(\omega - \frac{\pi}{2} + 2\pi k\right)}\right) + X\left(e^{j \left(\omega + \frac{\pi}{2} + 2\pi k\right)}\right)\right)
\end{align}
\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            xlabel={\(\frac{\omega}{\pi}\)}, ylabel={\(Z(e^{j \omega})\)},
            title={DTFT of Product},
            axis lines=middle,
        ]
        \addplot[color=blue] table[
            col sep=comma,
            x=index, y=8b
        ]{q8.csv};
        \end{axis}
    \end{tikzpicture}
\end{center}

\subsection{}

\begin{align}
    Y(e^{j \omega}) &= \pi \sum_{k = -\infty}^\infty \delta\left(\omega - \frac{\pi}{4} + 2\pi k\right) + \delta\left(\omega + \frac{\pi}{4} + 2\pi k\right) + \delta\left(\omega - \frac{3\pi}{4} + 2\pi k\right) + \delta\left(\omega + \frac{3\pi}{4} + 2\pi k\right) \\
    X(e^{j \omega}) \ast Y(e^{j \omega}) &= \frac{1}{2} \sum_{k \in \Z} \left(X\left(e^{j \left(\omega - \frac{\pi}{2} + 2\pi k\right)}\right) + X\left(e^{j \left(\omega + \frac{\pi}{2} + 2\pi k\right)}\right)\right)
\end{align}
\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            xlabel={\(\frac{\omega}{\pi}\)}, ylabel={\(Z(e^{j \omega})\)},
            title={DTFT of Product},
            axis lines=middle,
        ]
        \addplot[color=blue] table[
            col sep=comma,
            x=index, y=8c
        ]{q8c.csv};
        \end{axis}
    \end{tikzpicture}
\end{center}

\subsection{}

\begin{align}
    Y(e^{j \omega}) &= \pi \sum_{k = -\infty}^\infty \cancelto{1}{e^{j \frac{\pi}{2}}} \delta(\omega - \pi + 2\pi k) + \cancelto{-1}{e^{-j \frac{\pi}{2}}} \delta(\omega + \pi + 2\pi k) \\
    X(e^{j \omega}) \ast Y(e^{j \omega}) &= \frac{1}{2} \sum_{k \in \Z} (X(e^{j (\omega - \pi + 2\pi k)}) - X(e^{j (\omega + \pi + 2\pi k)}))
\end{align}
\begin{center}
    \begin{tikzpicture}
        \begin{axis}[
            xlabel={\(\frac{\omega}{\pi}\)}, ylabel={\(Z(e^{j \omega})\)},
            title={DTFT of Product},
            axis lines=middle,
        ]
        \addplot[color=blue] table[
            col sep=comma,
            x=index, y=8d
        ]{q8.csv};
        \end{axis}
    \end{tikzpicture}
\end{center}

\newpage
\section{}

\begin{equation}
    H(e^{j \omega}) =
    \begin{cases}
        j & \omega \in (-\pi, 0) \\
        0 & \omega = 0 \\
        -j & \omega \in (0, \pi)
    \end{cases}
\end{equation}

\subsection{}

From Table 2.1 of O\&S, the symmetry properties of the DTFT imply that the Hilbert filter impulse response is purely \emph{real and odd}.

\subsection{}

\begin{align}
    X(e^{j \omega}) &= \pi (\delta(\omega - \omega_0) + \delta(\omega + \omega_0)) \\
    Y(e^{j \omega}) &= -j \pi (\delta(\omega - \omega_0) - \delta(\omega + \omega_0)) \\
    \overset{\mathcal{F}^{-1}}{\implies} y[n] &= \sin(\omega_0 n)
\end{align}

\subsection{}

\begin{align}
    Y(e^{j \omega}) &= H(e^{j \omega})^2 X(e^{j \omega}) =
    \begin{cases}
        -X(e^{j \omega}) & \omega \in (-\pi, 0) \\
        0 & \omega = 0 \\
        -X(e^{j \omega}) & \omega \in (0, \pi)
    \end{cases} \\
    &= -X(e^{j \omega}) \overset{\mathcal{F}^{-1}}{\implies} y[n] = -x[n]
\end{align}

\subsection{}

\begin{center}
    \includegraphics[width=0.6\textwidth]{q9d.png}
\end{center}
where \(\mathcal{H}\) is the Hilbert transform.

\end{document}


%\section{Stabilization and Weak Formulation}
\label{app:stab}

This appendix details the weak formulation of the Navier Stokes
equations instantiated in the software GRINS, and provides a
derivation of the $\tau$ stabilization terms shown in
Equation~\ref{eq:tau}.

In brief, our process is the following:

\begin{itemize}
 \item Cast Navier Stokes + Boussinesq equations into weak form
 \item Prepare as an operator $L\,{\bf c}={\bf f}$
 \item Calculate Fr\'echet derivative
 \item Separate into differential (P) and constant (Z) components,
       $L'[{\bf c}] = P + Z$
 \item Choose stabilization operator such that $S = -P^*$
 \item Then stabilization has form, $a_h({\bf c},{\bf \phi}) = a({\bf c},{\bf \phi}) + \langle
       L{\bf c},S{\bf \phi} \rangle_\tau$
\end{itemize}

This is essentially the least-squares stabilization proposed by Hughes
and extended to natural convection by Becker and Braack.

%
% start the real work
%

\section{Weak Formulation of the Equations of Interest}

We begin with the incompressible Navier-Stokes equations with Boussinesq
buoyancy,
\begin{align}
 \nabla \cdot {\bf u} &= \, 0 \label{eq_cont}\\
 \frac{\partial {\bf u}}{\partial t} + {\bf u} \cdot \nabla {\bf u} &= -\frac{1}{\rho}
 \nabla p + \nu \nabla^2 {\bf u} + g \frac{T'}{T_0} \label{eq_mom}\\
 \rho c_p \frac{\partial T}{\partial t} + {\bf u} \cdot \nabla T &= \nabla
 \cdot (k \nabla T) \label{eq_energy}
\end{align}
e.g. the continuity, momentum and energy equations, respectively. Our
state vector is ${\bf c} =  \left[p,{\bf u},T \right]$. To cast these into
weak form we multiply by appropriate test
functions ${\bf \phi} = \left[q,{\bf v},w \right] \in H^1_0(\Omega)$ and
integrate over the domain, $\Omega \in \mathbb{R}^n$. Our system of
equations now appears as,
\begin{align}
  \bigintsss_\Omega q \nabla \cdot {\bf u} \, dx &= 0 \\
 \bigintsss_\Omega \dot {\bf u} \cdot {\bf v} \, dx +
 \bigintsss_\Omega  ({\bf u} \cdot \nabla) \, {\bf u} \cdot {\bf v} \, dx &=
 \bigintsss_\Omega \frac{p}{\rho} \nabla \cdot {\bf v} \, dx -
 \bigintsss_\Omega \nu \, \nabla {\bf u} \cdot \nabla {\bf v}
 \,dx + \bigintsss_\Omega g \frac{T'}{T_0} \cdot {\bf v} \, dx \\
 \rho c_p \bigintsss_\Omega \dot T \cdot w \, dx + \bigintsss_\Omega ({\bf u}
 \cdot \nabla) T \cdot w \, dx  &= -\bigintsss_\Omega (k \nabla T) \cdot
 \nabla w \, dx
\end{align}
%
where an ``over-dot'' denotes time differentiation, e.g. $\dot {\bf u} =
\frac{\partial {\bf u}}{\partial t}$. Note that both the pressure term as well
as the viscous term were integrated by parts to reduce the required
order of the solution on those state variables.

The inner product is abbreviated by the shorthand notation $({\bf u},{\bf v}) =
\bigintsss_\Omega {\bf u}\cdot {\bf v}\, dx $, giving our equations the form,
\begin{align}
 (\nabla \cdot {\bf u}, q) &= 0 \\
 (\dot {\bf u},{\bf v}) + ({\bf u} \cdot \nabla {\bf u}, {\bf v}) -
 (p,\nabla \cdot {\bf v}) + (\nu \, \nabla
 {\bf u}, \nabla {\bf v}) &= (g \frac{T'}{T_0},{\bf v}) \\
 \rho c_p (\dot T,w) + ({\bf u} \cdot \nabla T,w) + (k \nabla T,\nabla w) &= 0.
\end{align}
%
This defines our weak form operator, $ a({\bf c},{\bf \phi})$. Our full equations will
also include a stabilization term such that,
\begin{equation}
 a_h({\bf c},{\bf \phi}) = a({\bf c},{\bf \phi}) +  \langle L\,{\bf c},S{\bf \phi} \rangle_\tau.
\end{equation}
%
The subsequent section will define the operators L and S, so that we
might then fully define the stabilization term $\langle L\,{\bf c},S{\bf \phi}
\rangle_\tau$.

%
% section
%
\section{The Stabilization Operators, L and S}

To form the stabilization terms,

\begin{equation}
 \langle L\,{\bf c},S{\bf \phi} \rangle_\tau
\end{equation}

we must define the operators L and S. The operator L is simply the PDEs
in Equations \ref{eq_cont} - \ref{eq_energy} written in operator form. S is
defined as the negative adjoint of the differential terms in L, e.g.
\begin{align}
 L'[{\bf c}] = P + Z \\
 S = -P^*.
\end{align}
Where P are the differential terms, and Z the constant terms.

Our objective is now to construct the adjoint operator of L. This is
accomplished using the Fr\'echet derivative, which defines the
functional derivative on L. In general this is accomplished by taking
the first variation of a function $\Pi({\bf u})$ around a base state, ${\bf u}$,
\begin{equation}
 \delta\, \Pi({\bf u}) = \lim_{\epsilon \to 0} \frac{\Pi({\bf
  u}+\epsilon \, \hat {\bf u}) -
  \Pi({\bf u})}{\epsilon} =
  \frac{\partial \Pi({\bf u} +\epsilon \, \hat {\bf u})}{\partial \epsilon}
  \bigg|_{\epsilon = 0}
\end{equation}
$\forall \hat {\bf u}, \epsilon > 0$ with ${\bf u} + \epsilon \, \hat {\bf u} \in
H^1_0(\Omega)$. This is recognizable as the G\^{a}teaux
derivative of the functional.

We now consider the first variation of state for the momentum equation
term by term. The convective term is,
\begin{align}
 \frac{\partial}{\partial \epsilon} ({\bf u} + \epsilon \, \hat {\bf u}) &\cdot \nabla
  ({\bf u} + \epsilon \hat {\bf u}) \\
 = \lim_{\epsilon \to 0} \, \hat {\bf u} &\cdot \nabla ({\bf u} + \epsilon \,\hat {\bf u}) \\
 = \hat {\bf u} & \cdot \nabla {\bf u} \\
 = - {\bf u} &\cdot \nabla \hat {\bf u}
\end{align}
and the viscous term is,
\begin{align}
 \frac{\partial}{\partial \epsilon} \nabla^2 ({\bf u} + \epsilon \, \hat {\bf u}) \\
 = \nabla^2 \hat {\bf u}
\end{align}
while the buoyancy term is,
\begin{align}
 \delta \left(-g \frac{T'}{T_0}\right) &= \delta \left( -g
 \frac{T-T_0}{T_0} \right) \\
 &= -g \frac{\partial}{\partial \epsilon} \left( \frac{T-T_0+\epsilon
 \hat T}{T_0} \right) \\
 &= -g \left( \frac{\hat T}{T_0} \right)
\end{align}
%
%
%Lagrangian is therefore, $\mathcal{L}$
and thus the full adjoint equation for momentum appears as,
\begin{align}
 - {\bf u} &\cdot \nabla \hat {\bf u} - \nabla^2 \hat {\bf u} = -\frac{1}{\rho} \nabla p.
\label{eq_adjmom}
\end{align}
%
The continuity equation is straightforward,
\begin{align}
 \frac{\partial}{\partial \epsilon} \nabla \cdot ({\bf u} + \epsilon \,
 \hat {\bf u}) &= 0, \\
\nabla \cdot \hat {\bf u} &= 0.
\label{eq_adjcont}
\end{align}
%
Finally, consider the convective term of the energy equation,
\begin{align}
 \frac{\partial}{\partial \epsilon} {\bf u} \cdot \nabla (T + \epsilon
 \, \hat T)
 = {\bf u} \cdot \nabla \hat T
\end{align}
and the thermal diffusion term,
\begin{align}
 \frac{\partial}{\partial \epsilon} \cdot (-k \nabla (T + \epsilon \hat
 T)) = \nabla \cdot (-k \nabla \hat T).
\end{align}
The full adjoint energy equation is therefore,
\begin{align}
 {\bf u} \cdot \nabla \hat T + \nabla \cdot (k \nabla \hat T) = 0.
\label{eq_adjen}
\end{align}

We are now in a position to define the matrices L and S. L comes
directly from the PDEs in Equations \ref{eq_cont} - \ref{eq_energy} and is
defined as thus,

\begin{equation}
\renewcommand\arraystretch{2}
 L =
  \begin{pmatrix}
    0 & \nabla \cdot () & 0   \\
    \nabla \,() & {\bf u} \cdot \nabla() - \nu \nabla^2() & -g \frac{()}{T_0}  \\
    0 & 0 & {\bf u} \cdot \nabla() - \nabla \cdot (k \nabla() \,)
  \end{pmatrix}.
\end{equation}
%
While the S matrix is constructed from Equations~\ref{eq_adjmom},
\ref{eq_adjcont}, and \ref{eq_adjen}, and must be,
\begin{equation}
\renewcommand\arraystretch{2}
 S = -P^* =
  \begin{pmatrix}
    0 & \nabla \cdot () & 0   \\
    \nabla \,() & {\bf u} \cdot \nabla() + \nu \nabla^2() &  -g \frac{()}{T_0}  \\
    0 & 0 & {\bf u} \cdot \nabla() + \nabla \cdot k \nabla()
  \end{pmatrix}.
\end{equation}

%
% tau!
%
\section{Tau Stabilization Terms}

Finally, we may now form the $\tau$ stabilization terms,
\begin{equation}
 \langle L\, {\bf c},S{\bf \phi} \rangle_\tau.
\end{equation}
Where the operator $ \langle \cdot,\cdot \rangle_\tau. $ is shorthand
and denotes
\begin{equation}
 \langle {\bf u},{\bf v} \rangle_\tau = \sum_K \tau_K ({\bf u},{\bf v})_K.
\end{equation}
Where $K$ denotes the FEM cells. Now, through what Becker and Braack
contemptibly referred to as ``elementary calculus'', we arrive at our
stabilization terms,
\begin{align*}
 \langle L\,{\bf c},S{\bf \phi} \rangle_\tau = \sum_K \{ \quad &\tau_p (\nabla \cdot {\bf u},
 \nabla \cdot {\bf v}) \\
 +\quad &\tau_u \,(\nabla p + {\bf u} \cdot \nabla {\bf u} - \nu
 \nabla^2 {\bf u} - g \frac{T'}{T_0},
 \nabla q) \\
 +\quad &\tau_u \, (\nabla p + {\bf u} \cdot \nabla {\bf u} - \nu \nabla^2 {\bf u}- g \frac{T'}{T_0},
 \nabla {\bf u} \cdot \nabla {\bf v} + \nu \nabla^2 {\bf v}) \\
 +\quad &\tau_T \, ({\bf u} \cdot T - \nabla \cdot (k \nabla T), \nabla {\bf u} \cdot \nabla
 w + \nabla \cdot (k \nabla w)) \quad \}.
\end{align*}


\documentclass{amsproc}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[cmtip,all]{xy}

\copyrightinfo{2016}{Todd D. Vance}

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{xca}[theorem]{Exercise}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

\numberwithin{equation}{section}

\begin{document}
\title{A Geometric Algebra Primer}
\author[T. D. Vance]{Todd D. Vance}
%\address{15 Lilac Dr \\ Moorefield, WV 26836}
%\email{tdvance@gmail.com}
\date{\today}

\begin{abstract}
  A brief introduction to Geometric Algebra with an emphasis on algorithms.
\end{abstract}

\maketitle{}

\newcommand{\term}[1]{\emph{#1}}

\newcommand{\ga}{\ensuremath{\mathop{\mathrm{GA}}}}

\section{definitions}

\begin{definition}[Geometric Algebra]
  The \term{geometric algebra} $\ga(n)$ of \term{ambient rank} $n$ is
  the quotient algebra $\mathbf{R}\{[1], [2], \dots, [n]\}/I$, where
  $\mathbf{R}\{[1], [2], \dots, [n]\}$ is the free (unital,
  associative, noncommutative) algebra over the real field
  $\mathbf{R}$ generated by noncommuting elements $[1], [2], \dots,
  [n]$, and $I$ is the (two-sided) ideal of $\mathbf{R}\{[1], [2],
  \dots, [n]\}$ generated by the set of elements of the form $[i][i] -
  1$ and of the form $[i][j] - [j][i]$ when $i\ne{j}$.
\end{definition}

The multiplication operator in $\ga(n)$ is called the \term{geometric
  product} and is written by juxtaposition: $ab$ is the product of $a$
and $b$, in that order.  An (equivalence class of the) element of
$\ga(n)$ of the form $[i_1][i_2]\cdots[i_m]$ is abbreviated
$[i_1i_2\cdots{i}_m]$ and is called a \term{basis blade}.  As a
special case, the empty basis blade $[]$ is defined to be the
multiplicative identity $1$.

\begin{example}
A commonly-used geometric algebra in graphics applications is $\ga[3]$
of ambient rank $3$.  The algebra is generated by the elements $[1]$,
$[2]$, and $[3]$.  Clearly $[1][1] = [] = 1$, $[1][2]=-[2][1]$, and so
on.  From this one finds that $\ga(3)$ is an eight-dimensional vector
space with basis $\{[], [1], [2], [3], [12], [13], [23], [123]\}$.  A
typical element of $\ga(3)$ is then equal to $s[] + a[1] + b[2] + c[3]
+ A[23] + B[13] + C[12] + S[123]$ where $s, a, b, c, A, B, C,$ and $S$
are real numbers.

We consider elements of $\ga(3)$ of the form $a[1]+b[2]+c[3]$ to be
vectors (or rank one elements) and this three-dimensional vector space
is the geometric entity $\ga(3)$ models.  Elements of the form $s[]$,
also just written $s$, are scalars (or rank zero elements), so in a
geometric algebra, one can add a scalar to a vector.  Elements of the
form $A[23] + B[13] + C[12]$ are bivectors (rank two elements), which
model oriented plane regions with an area magnitude.

Just as a vector has direction and magnitude, and one considers two
vectors having the same direction and magnitude to be equal even if
they have different locations in three-space, a bivector has a
containing plane, one of two orientations on that plane, and an area,
so two planar regions having the same area, contained in parallel or
equal planes, and given the same orientation (which may be thought of
as clockwise versus counterclockwise) are considered to be the same
bivector.

Elements of the form $S[123]$ are considered volume elements (rank
three elements), also called pseudoscalars because they have one
degree of freedom in three-dimensional space.  A volume element only
has magnitude and orientation (positive or negative, which may be
thought of as being a right-handed or left-handed coordinate system).

Addition of two elements expressed in the linear combination form
mentioned above is done by combining like terms.  If $x = 4 + 3[1] +
4[2] + 5[12]$ and $y = 3 + 2[1] + 3[2] + 4[12]$, then
$x+y = 7 +5[1] +7[2] + 9[12]$.

Multiplication works like polynomial multiplication, except without
commutativity, and using the rules of converting products of blades
into the standard ones $[]=1$, $[1]$, $[2]$, $[12]$, $[3]$, $[13]$,
$[23]$, and $[123]$.  So, using the same $x$ and $y$ as above, to find
$xy$, one multiplies every term of $x$ by every term of $y$, then
reduces and combines like terms:
\begin{alignat*}{4}
  xy &=&&12 + 8[1] + 12[2] +16[12]\\
  && +~ & 9[1] + 6[1][1] + 9[1][2] + 12[1][12]\\
  && +~ & 12[2] + 8[2][1] + 12[2][2] + 16[2][12]\\
  && +~ & 15[12] + 10[12][1] + 15[12][2] + 20[12][12]\\
  &=&&12 + 8[1] + 12[2] + 16[12]\\
  && +~ &9[1] + 6 + 9[12] + 12[2]\\
  && +~ & 12[2] - 8[12] + 12 - 16[1]\\
  && +~ & 15[12] - 10[2] + 15[1] - 20\\
  &=&& 10 + 16[1] + 26[2] + 32[12]
\end{alignat*}
\end{example}

\subsection{Standard Basis Blades}

Generalizing from the example, we see that swapping adjacent unequal
indices of a basis blade changes its sign and deleting pairs of
adjacent, equal indices does not change the element.  Thus, all basis
blades in $\ga(n)$ are either plus or minus a \term{standard} basis
blade $[i_1i_2\cdots{i}_m]$ ($m \le n$) in which the indices are in
increasing order and there are no duplicate indices.  In this case,
the \term{rank} of the basis blade is $m$.  Any element of $\ga(n)$
can be written uniquely (up to ordering of terms) as a linear
combination of standard basis blades (including $[]$, the rank-zero
empty basis blade equal to $1$ in the algebra), and the rank of that
element is the maximum rank among the basis blades in the linear
combination.  The rank of the $0$ element is defined to be $-\infty$.
Thus, $\ga(n)$ is an algebra filtered by rank.

A nonzero element of $\ga(n)$ that is a linear combination of standard
basis blades of the same rank $r$ is said to be \term{purely} of rank
$r$.  Rank 0 elements (that is, pure rank 0 elements along with the 0
element) are called \term{scalars}.  Pure rank 1 elements (along with
0) are called \term{vectors}.  Pure rank two elements (along with 0)
are called \term{bivectors}, and so on.  All elements are called
\term{multivectors}. When the ambient rank is $n$, rank $n$ elements
(along with 0) are called \term{pseudoscalars}, rank $n-1$ elements
(along with 0) are called \term{pseudovectors}, and so on.

The algebra $\ga(n)$ is generated, as a vector space, by the standard
basis blades $[]$, $[1]$, $[2]$, $\dots$, $[n]$, $[12]$, $\dots$
$[123\dots{n}]$, of which there are $2^n$, so as a real vector
space, $\ga(n)$ has dimension $2^n$.

In addition to the geometric product, other products are defined in
$\ga(n)$.  The \term{inner product} is the symmetric component of the
geometric product: $a\cdot{b} = \frac{ab+ba}{2}$.  The \term{outer
  product} is the antisymmetric component of the geometric product:
$a\wedge{b}=\frac{ab-ba}{2}$.  As the names imply,
$a\cdot{b}=b\cdot{a}$, and $a\wedge{b} = -b\wedge{a}$.  Then, $ab =
a\cdot{b} + a\wedge{b}$.

\subsection{Additional Operations}

Note that for vectors, $a\cdot{b}$ is exactly the standard dot
product, using $\{[1], [2], \dots, [n]\}$ as the standard ordered
basis.  For vectors in $\ga(3)$, the wedge product has the same
magnitude as the cross product, but is a bivector (pseudovector)
rather than a vector.  Also, the wedge product is defined in any
number of dimensions, not just three, and for non-vector elements as
well.

The \emph{standard pseudoscalar} $I$ of $\ga(n)$ is defined to be the
rank-$n$ standard basis blade $[123\dots{n}]$.  Then, $I^2 = II$ must
either be $-1$ or $1$, so $I^4=1$ regardless of $n$.  In particular,
the subalgebra of $\ga(2)$ generated by $[]$ and $I$ is isomorphic to
the complex number field.  In fact $I^2=-1$ in $\ga(2)$ and the
isomorphism maps $1$ to $[]$ and $\imath$ to $I$.  In addition,
$\ga(3)$ contains a subalgebra isomorphic to the quanternion algebra.
This subalgebra is generated by $[]$, $i=[23]$, $j=[13]$, and
$k=[12]$, with $[]$ maping to 1 and $i$, $j$, and $k$ mapping to the
same-named elements of the quaternion ring.

The \term{norm} $|a|$ of an element $a\in\ga(n)$ is defined to be the
square root of the sum of the squares of the coefficients of the
standard basis blades making up the linear combination.  Note for
vectors this reduces to the usual norm for vectors.

The \term{reversion} $\tilde{a}$ of an element $a\in \ga(n)$ is formed
from $a$ by taking the linear combination of standard basis blades
composing $a$, and then reversing the order of multiplication of the
algebra generators in each term: $[i_{j_1}][i_{j_2}]\cdots[i_{j_m}]$
$\rightarrow$ $[i_{j_m}][i_{j_{m-1}}]\cdots[i_{j_1}]$.  Equivalently,
each term of $a$ of pure rank $r$, where $r$ is congruent to $2 $ or
$3$ modulo $4$, is negated.

The \term{grade projection} $\mathrm{proj}_k(a)$ of an element $a\in \ga(n)$ is
formed from $a$ by deleting all terms of pure rank not equal to $k$.

The \term{left inverse} of $a\in \ga(n)$ is an element $b$ satisfying
$ba=1=[]$ and the \term{right inverse} $c$ likewise satisfies $ac=1$.
We use $a^{-1}$ to represent an element that is both the left and right
inverse of $a$.  If $a{\tilde{a}}$ is a nonzero scalar, then
$\frac{a}{a{\tilde{a}}}$ is well-defined by dividing each coefficient of
$a$ by the scalar denominator.  In such a case, $a$ does have a
two-sided inverse and $a^{-1} = \frac{a}{a{\tilde{a}}}$.

The \term{dual} of an element $a$ of $\ga(n)$ is $aI^{-1}$.  Note that
$I^{-1}$ exists and is equal to $I^3$, which is either $I$ or $-I$.
Note that the dual of a scalar is a psuedoscalar, the dual of a vector
is a pseudovector, and so on.  The double dual of $a$ is either $a$ or
$-a$.

Note that in $\ga(3)$, $a\wedge{b}I^{-1}$ is a vector, and is equal to
the vector space cross product $a\times{b}$.  Thus, we define a
\term{generalized cross product} on any $\ga(n)$ to be
$a\times{b}=a\wedge{b}I^{-1}$, the dual of the wedge product.  In
dimensions other than 3, the cross product of vectors is no longer a
vector.  However, in $n$ dimensions, one can take the dual of the
wedge product of $n-1$ vectors to give a vector which geometrically is
similar to the cross product in three dimensions.

The \term{exponential} of $a\in{\ga}(n)$ is computed as follows.  If
$a=0$, $e^0=1$ by definition.  Otherwise, let $\theta=|a|$ and
$b=a/\theta$.  Then use DeMoivre's formula with $b$ taking the role of
the imaginary unit: $e^a = \cos\theta + b\sin\theta$.  The inverse of
this operation, a geometric algebraic logarithm, is difficult and
multivalued, even more so than with complex numbers.

The main use for the exponential is in computing a \term{rotor}.  If
$v$ and $w$ are linearly-independent unit vectors (that is,
$|v|=|w|=1$) in the $n$-dimensional vector space whose basis is the
rank-one standard blades, then $vw$ is a bivector that represents an
oriented plane in the $n$-dimensional space.  A rotation about the
origin in the direction from $v$ to $w$ along an angle $theta$ is then
modeled by the \term{rotor} $r$ in $\ga(n)$ that is $r =
e^{\frac12vw\theta}$.  Then if $a$ is any element (vector or
otherwise) of $\ga(n)$, its rotation is then $ra{\tilde{r}}$.  If $a$
is a vector, so is $ra{\tilde{r}}$, and this is an ordinary vector
rotation.  If $a$ is a bivector representing an oriented plane,
$ra{\tilde{r}}$ is the rotation of the plane.  And so on.

The \term{meet} of two elements $a$ and $b$ in $\ga(n)$ is defined by
$aI^{-1}b$, or the product of the dual of $a$ with $b$.

\section{Algorithms}
\newcommand{\n}{\ensuremath{\mathop{\mathrm{N}}}} An apparent way to
represent a standard basis blade $a=[i_1i_2\dots{i}_m]$ is via the
integer $\n(a)$ defined to be $\sum_{k=1}^{m}2^{i_k}$.  Then, the
product $ab$ of $a=[i_1i_2\dots{i}_m]$ and $b=[j_1j_2\dots{j}_r]$
can be computed as follows:

\begin{enumerate}
\item If $m=0$, let $c$ be the multivector $b$ and return $c$
\item If $r=0$, let $c$ be the multivector $a$ and return $c$
\item Let $c$ be the blade for which $\n(c)$ is the bitwise exclusive
  or of $\n(a)$ and $\n(b)$.
\item Let $s$ be 1.
\item Let $p$ be the maximum of $\n(a)$ and $\n(b)$.
\item Let $d$ be $m$
\item Let $e$ be $1$
\item while $e\le{p}$, do the following:
  \begin{enumerate}
  \item Compute the bitwise and of $e$ and $\n(a)$.
  \item If the result of the bitwise and is nonzero, then replace $d$ with $d-1$.
  \item If $d$ is odd, Compute the bitwise and of $e$ and $\n(b)$.
  \item If $d$ is odd and the result of the bitwise and is nonzero
    then replace $s$ with $-s$.
  \item Replace $e$ with $2e$.
  \end{enumerate}
\item Let $c$ be the multivector that is the real coefficient $s$
  multiplied by the blade given by $c$, and return $c$.
\end{enumerate}

A standard basis blade is simply a nonnegative integer in this
representation.  A choice needs to be made to represent a multivector,
a real linear combination of these blades.

The \term{dense} representation of a multivector in $\ga(n)$ is an
array $A$ of dimension $2^n$, thus having elements $A_0$, $A_1$, and
so on up to $A_{2^n-1}$.  Then, a multivector $\sum_{i=1}^{l}c_ib_i$,
where the $c_i$ are real numbrers and the $b_i$ are standard basis
blades in $\ga(n)$, is represented by the array $A$ in which for
$1\le{i}\le{l}$, $A_{\n(b_i)} = c_i$, and all other elements of $A$
are zero.

The dense representation requires little computation, but uses
$O(2^n)$ memory per element of $\ga(n)$, so it is useful for low
dimensionality, such as in representing the commonly-used $\ga(3)$.

For larger dimensions, a \term{sparse} representation is needed.  Let
$D$ be a \term{dictionary}, algorithmically represented by a hash
table in most cases, but mathematically works like the array: for any
nonnegative integer $i$, $D_i$ is a real number.  For most $i$, this
real number is zero and thus $i$ has no entry in the hash table.  Only
when $D_i$ is nonzero is there an entry in the hash table with key $i$
and value $D_i$.

Then, a multivector $\sum_{i=1}^{l}c_ib_i$, where the $c_i$ are real
numbrers and the $b_i$ are standard basis blades in $\ga(n)$, is
represented by the dictionary $D$ in which for $1\le{i}\le{l}$,
$D_{\n(b_i)} = c_i$, and no other entries are present in $D$ (so that
the dictionary returns the default value of 0 for those).

The sparse representation requires a small amount of computation for
hashing and, sometimes, rebuilding the table, but only requires $O(l)$
memory for an element of $\ga(n)$ having $l$ nonzero terms.  Thus, the
sparse representation is most useful for large $n$ when many elements
are such that most standard basis blades have a zero coefficient.

In both cases, the addition procedure is evident and involves adding
the values from one array or dictionary to the same-indexed values of
the other.

The geometric product, however, requires an all-to-all mapping of
array or dictionary elements.  We illustrate the algorithm for the
array case, with the dictionary case being nearly identical, just
iterating over keys in the hash table instead of over all integers in
the range from $0$ to $2^{n-1}$.

Suppose $A$ and $B$ are arrays representing multivectors in $\ga(n)$.
We compute a new array $C$ with $2^n$ entries representing the
geometric product of the multivectors $A$ and $B$.

\begin{enumerate}
\item Initialize $C$ to $C_0=C_1=\cdots=c_{2^{n-1}}=0$.
\item For each $i$ from 0 to $2^{n-1}$ such that the coefficient $A_i$
  is nonzero
  \begin{enumerate}
  \item For each $j$ from 0 to $2^{n-1}$ such that the coefficient
    $B_j$ is nonzero
    \begin{enumerate}
      \item Let $k$ be the integer that is the result of multiplying
        together the blades represented by $i$ and $j$, and let $s$ be
        the coefficient, $1$ or $-1$, of the result.
      \item Let $C_k$ be $C_k + A_iB_js$, an ordinary sum and product
        of real numbers.
    \end{enumerate}
  \end{enumerate}
  \item Return the multivector $C$.
\end{enumerate}

\bibliographystyle{amsplain}

\end{document}


% !TEX root = lectures.tex
\section{Oscillations}
\bigskip

\subsection{Harmonic Oscillator}

The harmonic oscillator is omnipresent in physics. Although students think of this as being related to springs, it, or an equivalent mathematical representation, appears in just about any problem where a mode is sitting near its potential energy minimum. At that point, $\partial_x V(x)=0$, and the first non-zero term (aside from a constant) in the potential energy is that of a harmonic oscillator. In a solid, sound modes (phonons) are built on a picture of coupled harmonic oscillators, and in relativistic field theory the fundamental interactions are also built on coupled oscillators positioned infinitesimally close to one another in space. The phenomena of a resonance of an oscillator driven at a fixed frequency plays out repeatedly in atomic, nuclear and high-energy physics, when quantum mechanically the evolution of a state oscillates according to $e^{-iEt}$ and exciting discrete quantum states has very similar mathematics as exciting discrete states of an oscillator.

The potential energy for a single particle as a function of its position $x$ can be written as a Taylor expansion about some point $x_0$
\begin{equation}
V(x)=V(x_0)+(x-x_0)\left.\partial_xV(x)\right|_{x_0}+\frac{1}{2}(x-x_0)^2\left.\partial_x^2V(x)\right|_{x_0}
+\frac{1}{3!}\left.\partial_x^3V(x)\right|_{x_0}+\cdots
\end{equation}
If the position $x_0$ is at the minimum of the resonance, the first two non-zero terms of the potential are
\begin{eqnarray}
V(x)&\approx& V(x_0)+\frac{1}{2}(x-x_0)^2\left.\partial_x^2V(x)\right|_{x_0},\\
\nonumber
&=&V(x_0)+\frac{1}{2}k(x-x_0)^2,~~~~k\equiv \left.\partial_x^2V(x)\right|_{x_0},\\
\nonumber
F&=&-\partial_xV(x)=-k(x-x_0).
\end{eqnarray}

Put into Newton's 2nd law (assuming $x_0=0$),
\begin{eqnarray}
m\ddot{x}&=&-kx,\\
x&=&A\cos(\omega_0 t-\phi),~~~\omega_0=\sqrt{k/m}.
\end{eqnarray}
Here $A$ and $\phi$ are arbitrary. Equivalently, one could have written this as $A\cos(\omega_0 t)+B\sin(\omega_0 t)$, or as the real part of $Ae^{i\omega_0 t}$. In this last case $A$ could be an arbitrary complex constant. Thus, there are 2 arbitrary constants (either $A$ and $B$ or $A$ and $\phi$, or the real and imaginary part of one complex constant. This is the expectation for a second order differential equation, and also agrees with the physical expectation that if you know a particle's initial velocity and position you should be able to define its future motion, and that those two arbitrary conditions should translate to two arbitrary constants.

A key feature of harmonic motion is that the system repeats itself after a time $T=1/f$, where $f$ is the frequency, and $\omega=2\pi f$ is the angular frequency. The period of the motion is independent of the amplitude. However, this independence is only exact when one can neglect higher terms of the potential, $x^3, x^4\cdots$. Once can neglect these terms for sufficiently small amplitudes, and for larger amplitudes the motion is no longer purely sinusoidal, and even though the motion repeats itself, the time for repeating the motion is no longer independent of the amplitude.

One can also calculate the velocity and the kinetic energy as a function of time,
\begin{eqnarray}
\dot{x}&=&-\omega_0A\sin(\omega_0 t-\phi),\\
\nonumber
T&=&\frac{1}{2}m\dot{x}^2=\frac{m\omega_0^2A^2}{2}\sin^2(\omega_0t-\phi),\\
\nonumber
&=&\frac{k}{2}A^2\sin^2(\omega_0t-\phi).
\end{eqnarray}
The total energy is then
\begin{equation}
E=T+U=\frac{1}{2}m\dot{x}^2+\frac{1}{2}kx^2=\frac{1}{2}kA^2.
\end{equation}
The total energy then goes as the square of the amplitude.

\example
A pendulum is an example of a harmonic oscillator. By expanding the kinetic and potential energies for small angles find the frequency for a pendulum of length $L$ with all the mass $m$ centered at the end by writing the eq.s of motion in the form of a harmonic oscillator.

{\bf Solution:} The potential energy and kinetic energies are (for $x$ being the displacement)
\begin{eqnarray*}
U&=&mgL(1-\cos\theta)\approx mgL\frac{x^2}{2L^2},\\
T&=&\frac{1}{2}mL^2\dot{\theta}^2\approx \frac{m}{2}\dot{x}^2.
\end{eqnarray*}
For small $x$ Newton's 2nd law becomes
\[
m\ddot{x}=-\frac{mg}{L}x,
\]
and the spring constant would appear to be $k=mg/L$, which makes the frequency equal to $\omega_0=\sqrt{g/L}$. Note that the frequency is independent of the mass.

\exampleend

\subsection{Damped Oscillators}

In this chapter we consider only the case where the damping force is proportional to the velocity. This is counter to dragging friction, where the force is proportional in strength to the normal force and independent of velocity, and is also inconsistent with wind resistance, where the magnitude of the drag force is proportional the square of the velocity. Rolling resistance does seem to be mainly proportional to the velocity. However, the main motivation for considering damping forces proportional to the velocity is that the math is more friendly. This is because the differential equation is linear, i.e. each term is of order $x$, $\dot{x}$, $\ddot{x}\cdots$, or even terms with no mention of $x$, and there are no terms such as $x^2$ or $x\ddot{x}$. The equations of motion for a spring with damping force $-b\dot{x}$ are
\begin{equation}
m\ddot{x}+b\dot{x}+kx=0.
\end{equation}
Just to make the solution a bit less messy, we rewrite this equation as
\begin{equation}
\label{eq:dampeddiffyq}
\ddot{x}+2\beta\dot{x}+\omega_0^2x=0,~~~~\beta\equiv b/2m,~\omega_0\equiv\sqrt{k/m}.
\end{equation}
Both $\beta$ and $\omega$ have dimensions of inverse time. To find solutions (see appendix C in the text) you must make an educated guess at the form of the solution. To do this, first realize that the solution will need an arbitrary normalization $A$ because the equation is linear. Secondly, realize that if the form is
\begin{equation}
x=Ae^{rt}
\end{equation}
that each derivative simply brings out an extra power of $r$. This means that the $Ae^{rt}$ factors out and one can simply solve for an equation for $r$. Plugging this form into Eq. (\ref{eq:dampeddiffyq}),
\begin{equation}
r^2+2\beta r+\omega_0^2=0.
\end{equation}
Because this is a quadratic equation there will be two solutions,
\begin{equation}
r=-\beta\pm\sqrt{\beta^2-\omega_0^2}.
\end{equation}
We refer to the two solutions as $r_1$ and $r_2$ corresponding to the $+$ and $-$ roots. As expected, there should be two arbitrary constants involved in the solution,
\begin{equation}
x=A_1e^{r_1t}+A_2e^{r_2t},
\end{equation}
where the coefficients $A_1$ and $A_2$ are determined by initial conditions.

The roots listed above, $\sqrt{\omega_0^2-\beta_0^2}$, will be imaginary if the damping  is small and $\beta<\omega_0$. In that case, $r$ is complex and the factor $e{rt}$ will have some oscillatory behavior. If the roots are real, there will only be exponentially decaying solutions. There are three cases:
\begin{enumerate}\itemsep 0pt
\item Underdamped: $\beta<\omega_0$
\begin{eqnarray}
x&=&A_1e^{-\beta t}e^{i\omega't}+A_2e^{-\beta t}e^{-i\omega't},~~\omega'\equiv\sqrt{\omega_0^2-\beta^2}\\
\nonumber
&=&(A_1+A_2)e^{-\beta t}\cos\omega't+i(A_1-A_2)e^{-\beta t}\sin\omega't.
\end{eqnarray}
Here we have made use of the identity $e^{i\omega't}=\cos\omega't+i\sin\omega't$. Because the constants are arbitrary, and because the real and imaginary parts are both solutions individually, we can simply consider the real part of the solution alone:
\begin{eqnarray}
\label{eq:homogsolution}
x&=&B_1e^{-\beta t}\cos\omega't+B_2e^{-\beta t}\sin\omega't,\\
\nonumber
\omega'&\equiv&\sqrt{\omega_0^2-\beta^2}.
\end{eqnarray}

\item Critical dampling: $\beta=\omega_0$\\
In this case the two terms involving $r_1$ and $r_2$ are identical because $\omega'=0$. Because we need to arbitrary constants, there needs to be another solution. This is found by simply guessing, or by taking the limit of $\omega'\rightarrow 0$ from the underdamped solution. The solution is then
\begin{equation}
\label{eq:criticallydamped}
x=Ae^{-\beta t}+Bte^{-\beta t}.
\end{equation}
The critically damped solution is interesting because the solution approaches zero quickly, but does not oscillate. For a problem with zero initial velocity, the solution never crosses zero. This is a good choice for designing shock absorbers or swinging doors.
\item Overdamped: $\beta>\omega_0$
\begin{eqnarray}
x&=&A_1e^{-(\beta+\sqrt{\beta^2-\omega_0^2})t}+A_2e^{-(\beta-\sqrt{\beta^2-\omega_0^2})t}
\end{eqnarray}
This solution will also never pass the origin more than once, and then only if the initial velocity is strong and initially toward zero.
\end{enumerate}

\example
Given $b$, $m$ and $\omega_0$, find $x(t)$ for a particle whose initial position is $x=0$ and has initial velocity $v_0$ (assuming an underdamped solution).

{\bf Solution:} The solution is of the form,
\begin{eqnarray*}
x&=&e^{-\beta t}\left[A_1\cos(\omega' t)+A_2\sin\omega't\right],\\
\dot{x}&=&-\beta x+\omega'e^{-\beta t}\left[-A_1\sin\omega't+A_2\cos\omega't\right].\\
\omega'&\equiv&\sqrt{\omega_0^2-\beta^2},~~~\beta\equiv b/2m.
\end{eqnarray*}
From the initial conditions, $A_1=0$ because $x(0)=0$ and $\omega'A_2=v_0$. So
\[
x=\frac{v_0}{\omega'}e^{-\beta t}\sin\omega't.
\]
\exampleend

\subsection{Sinusoidally Driven Oscillators}

Here, we consider the force
\begin{equation}
F=-kx-b\dot{x}+F_0\cos\omega t,
\end{equation}
which leads to the differential equation
\begin{equation}
\label{eq:drivenosc}
\ddot{x}+2\beta\dot{x}+\omega_0^2x=(F_0/m)\cos\omega t.
\end{equation}
Consider a single solution with no arbitrary constants, which we will call a {\it particular solution}, $x_p(t)$. It should be emphasized that this is {\bf A} particular solution, because there exists an infinite number of such solutions because the general solution should have two arbitrary constants. Now consider solutions to the same equation without the driving term, which include two arbitrary constants. These are called either {\it homogenous solutions} or {\it complementary solutions}, and were given in the previous section, e.g. Eq. (\ref{eq:homogsolution}) for the underdamped case. The homogenous solution already incorporates the two arbitrary constants, so any sum of a homogenous solution and a particular solution will represent the {\it general solution} of the equation. The general solution incorporates the two arbitrary constants $A$ and $B$ to accommodate the two initial conditions. One could have picked a different particular solution, i.e. the original particular solution plus any homogenous solution with the arbitrary constants $A_p$ and $B_p$ chosen at will. When one adds in the homogenous solution, which has adjustable constants with arbitrary constants $A'$ and $B'$, to the new particular solution, one can get the same general solution by simply adjusting the new constants such that $A'+A_p=A$ and $B'+B_p=B$. Thus, the choice of $A_p$ and $B_p$ are irrelevant, and when choosing the particular solution it is best to make the simplest choice possible.

To find a particular solution, one first guesses at the form,
\begin{equation}
\label{eq:partform}
x_p(t)=D\cos(\omega t-\delta),
\end{equation}
and rewrite the differential equation as
\begin{equation}
D\left\{-\omega^2\cos(\omega t-\delta)-2\beta\omega\sin(\omega t-\delta)+\omega_0^2\cos(\omega t-\delta)\right\}=\frac{F_0}{m}\cos(\omega t).
\end{equation}
One can now use angle addition formulas to get
\begin{eqnarray}
D\left\{(-\omega^2\cos\delta+2\beta\omega\sin\delta+\omega_0^2\cos\delta)\cos(\omega t)\right.\hspace*{36pt}&&\\
\nonumber
\left.+(-\omega^2\sin\delta-2\beta\omega\cos\delta+\omega_0^2\sin\delta)\sin(\omega t)\right\}
&=&\frac{F_0}{m}\cos(\omega t).
\end{eqnarray}
Both the $\cos$ and $\sin$ terms need to equate if the expression is to hold at all times. Thus, this becomes two equations
\begin{eqnarray}
D\left\{-\omega^2\cos\delta+2\beta\omega\sin\delta+\omega_0^2\cos\delta\right\}&=&\frac{F_0}{m}\\
\nonumber
-\omega^2\sin\delta-2\beta\omega\cos\delta+\omega_0^2\sin\delta&=&0.
\end{eqnarray}
After dividing by $\cos\delta$, the lower expression leads to
\begin{equation}
\tan\delta=\frac{2\beta\omega}{\omega_0^2-\omega^2}.
\end{equation}
Using the identities $\tan^2+1=\csc^2$ and $\sin^2+\cos\^2=1$, one can also express $\sin\delta$ and $\cos\delta$,
\begin{eqnarray}
\sin\delta&=&\frac{2\beta\omega}{\sqrt{(\omega_0^2-\omega^2)^2+4\omega^2\beta^2}},\\
\nonumber
\cos\delta&=&\frac{(\omega_0^2-\omega^2)}{\sqrt{(\omega_0^2-\omega^2)^2+4\omega^2\beta^2}}
\end{eqnarray}
Inserting the expressions for $\cos\delta$ and $\sin\delta$ into the expression for $D$,
\begin{equation}
\label{eq:Ddrive}
D=\frac{F_0/m}{\sqrt{(\omega_0^2-\omega^2)^2+4\omega^2\beta^2}}.
\end{equation}

For a given initial condition, e.g. initial displacement and velocity, one must add the homogenous solution then solve for the two arbitrary constants. However, because the homogenous solutions decay with time as $e^{-\beta t}$, the particular solution is all that remains at large times, and is therefore the steady state solution. Because the arbitrary constants are all in the homogenous solution, all memory of the initial conditions are lost at large times, $t>>1/\beta$.

The amplitude of the motion, $D$, is linearly proportional to the driving force ($F_0/m$), but also depends on the driving frequency $\omega$. For small $\beta$ the maximum will occur at $\omega=\omega_0$. This is referred to as a resonance. In the limit $\beta\rightarrow 0$ the amplitude at resonance approaches infinity.

\subsection{Alternative Derivation for Driven Oscillators}

Here, we derive the same expressions as in Eq.s (\ref{eq:partform}-\ref{eq:Ddrive}) but express the driving forces as
\begin{eqnarray}
F(t)&=&F_0e^{i\omega t},
\end{eqnarray}
rather than as $F_0\cos\omega t$. The real part of $F$ is the same as before. For the differential equation,
\begin{eqnarray}
\label{eq:compdrive}
\ddot{x}+2\beta\dot{x}+\omega_0^2x&=&\frac{F_0}{m}e^{i\omega t},
\end{eqnarray}
one can treat $x(t)$ as an imaginary function. Because the operations $d^2/dt^2$ and $d/dt$ are real and thus do not mix the real and imaginary parts of $x(t)$, Eq. (\ref{eq:compdrive}) is effectively 2 equations. Because $e^{\omega t}=\cos\omega t+i\sin\omega t$, the real part of the solution for $x(t)$ gives the solution for a driving force $F_0\cos\omega t$, and the imaginary part of $x$ corresponds to the case where the driving force is $F_0\sin\omega t$. It is rather easy to solve for the complex $x$ in this case, and by taking the real part of the solution, one finds the answer for the $\cos\omega t$ driving force.

We assume a simple form for the particular solution
\begin{equation}
x_p=De^{i\omega t},
\end{equation}
where $D$ is a complex constant.

From Eq. (\ref{eq:compdrive}) one inserts the form for $x_p$ above to get
\begin{eqnarray}
D\left\{-\omega^2+2i\beta\omega+\omega_0^2\right\}e^{i\omega t}=(F_0/m)e^{i\omega t},\\
\nonumber
D=\frac{F_0/m}{(\omega_0^2-\omega^2)+2i\beta\omega}.
\end{eqnarray}
The norm and phase for $D=|D|e^{-i\delta}$ can be read by inspection,
\begin{equation}
|D|=\frac{F_0/m}{\sqrt{(\omega_0^2-\omega^2)^2+4\beta^2\omega^2}},~~~~\tan\delta=\frac{2\beta\omega}{\omega_0^2-\omega^2}.
\end{equation}
This is the same expression for $\delta$ as before. One then finds $x_p(t)$,
\begin{eqnarray}
\label{eq:fastdriven1}
x_p(t)&=&\Re\frac{(F_0/m)e^{i\omega t-i\delta}}{\sqrt{(\omega_0^2-\omega^2)^2+4\beta^2\omega^2}}\\
\nonumber
&=&\frac{(F_0/m)\cos(\omega t-\delta)}{\sqrt{(\omega_0^2-\omega^2)^2+4\beta^2\omega^2}}.
\end{eqnarray}
This is the same answer as before.
If one wished to solve for the case where $F(t)= F_0\sin\omega t$, the imaginary part of the solution would work
\begin{eqnarray}
\label{eq:fastdriven2}
x_p(t)&=&\Im\frac{(F_0/m)e^{i\omega t-i\delta}}{\sqrt{(\omega_0^2-\omega^2)^2+4\beta^2\omega^2}}\\
\nonumber
&=&\frac{(F_0/m)\sin(\omega t-\delta)}{\sqrt{(\omega_0^2-\omega^2)^2+4\beta^2\omega^2}}.
\end{eqnarray}

\example
Consider the damped and driven harmonic oscillator worked out above. Given $F_0, m,\beta$ and $\omega_0$, solve for the complete solution $x(t)$ for the case where $F=F_0\sin\omega t$ with initial conditions $x(t=0)=0$ and $v(t=0)=0$. Assume the underdamped case.

{\bf Solution:}
The general solution including the arbitrary constants includes both the homogenous and particular solutions,
\begin{eqnarray*}
x(t)&=&\frac{F_0}{m}\frac{\sin(\omega t-\delta)}{\sqrt{(\omega_0^2-\omega^2)^2+4\beta^2\omega^2}}
+A\cos\omega't e^{-\beta t}+B\sin\omega't e^{-\beta t}.
\end{eqnarray*}
The quantities $\delta$ and $\omega'$ are given earlier in the section, $\omega'=\sqrt{\omega_0^2-\beta^2}, \delta=\tan^{-1}(2\beta\omega/(\omega_0^2-\omega^2)$. Here, solving the problem means finding the arbitrary constants $A$ and $B$. Satisfying the initial conditions for the initial position and velocity:
\begin{eqnarray*}
x(t=0)=0&=&-\eta\sin\delta+A,\\
v(t=0)=0&=&\omega\eta\cos\delta-\beta A+\omega'B,\\
\eta&\equiv&\frac{F_0}{m}\frac{1}{\sqrt{(\omega_0^2-\omega^2)^2+4\beta^2\omega^2}}.
\end{eqnarray*}
The problem is now reduced to 2 equations and 2 unknowns, $A$ and $B$. The solution is
\begin{eqnarray}
A&=& \eta\sin\delta ,~~~B=\frac{-\omega\eta\cos\delta+\beta\eta\sin\delta}{\omega'}.
\end{eqnarray}

\exampleend

\subsection{Resonance Widths; the $Q$ factor}

From the previous two sections, the particular solution for a driving force, $F=F_0\cos\omega t$, is
\begin{eqnarray}
x_p(t)&=&\frac{F_0/m}{\sqrt{(\omega_0^2-\omega^2)^2+4\omega^2\beta^2}}\cos(\omega_t-\delta),\\
\nonumber
\delta&=&\tan^{-1}\left(\frac{2\beta\omega}{\omega_0^2-\omega^2}\right).
\end{eqnarray}
If one fixes the driving frequency $\omega$ and adjusts the fundamental frequency $\omega_0=\sqrt{k/m}$, the maximum amplitude occurs when $\omega_0=\omega$ because that is when the term from the denominator $(\omega_0^2-\omega^2)^2+4\omega^2\beta^2$ is at a minimum. This is akin to dialing into a radio station. However, if one fixes $\omega_0$ and adjusts the driving frequency one minimize with respect to $\omega$, e.g. set
\begin{equation}
\frac{d}{d\omega}\left[(\omega_0^2-\omega^2)^2+4\omega^2\beta^2\right]=0,
\end{equation}
and one finds that the maximum amplitude occurs when $\omega=\sqrt{\omega_0^2-2\beta^2}$. If $\beta$ is small relative to $\omega_0$, one can simply state that the maximum amplitude is
\begin{equation}
x_{\rm max}\approx\frac{F_0}{2m\beta \omega_0}.
\end{equation}
\begin{figure}
\centerline{\includegraphics[width=0.32\textwidth]{figs/qfactor}}
\caption{\label{fig:qfactor}
The maximum amplitude squared of the steady-state motion of a sinusoidally driven harmonic oscillator is shown as a function of the driving frequency $\omega$. This peaks near the fundamental frequency $\omega_0$ and the full-width-half-maximum, $FWHM$, is given by the damping, $2\beta$.}
\end{figure}
Figure \ref{fig:qfactor} displays the maximum amplitude squared as a function of $\omega$, and  one can see the peak at $\omega\approx\omega_0$. The squared amplitude is usually more the quantity of interest than the amplitude because the power being absorbed by the oscillator is proportional to the square of the amplitude, not the amplitude. The width of the peak is quantified by the full-width-half-maximum, sometimes called $FWHM$ and can be found by finding the frequency difference, $\omega-\omega_0$, such that the maximum response falls by a factor of two,
\begin{eqnarray}
\frac{4\omega^2\beta^2}{(\omega_0^2-\omega^2)^2+4\omega^2\beta^2}=\frac{1}{2}.
\end{eqnarray}
For small damping this occurs when $\omega=\omega_0\pm \beta$, so the $FWHM\approx 2\beta$. For the purposes of tuning to a specific frequency, one wants the width to be as small as possible. The ratio of $\omega_0$ to $FWHM$ is known as the {\it quality} factor, or $Q$ factor,
\begin{equation}
Q\equiv \frac{\omega_0}{2\beta}.
\end{equation}

\subsection{Principal of Superposition and Periodic Forces (Fourier Transforms)}

If one has several driving forces, $F(t)=\sum_n F_n(t)$, one can find the particular solution to each $F_n$, $x_{pn}(t)$, and the particular solution for the entire driving force is
\begin{equation}
x_p(t)=\sum_nx_{pn}(t).
\end{equation}
This is known as the principal of superposition. It only applies when the homogenous equation is linear. If there were an anharmonic term such as $x^3$ in the homogenous equation, then when one summed various solutions, $x=(\sum_n x_n)^2$, one would get cross terms. Superposition is especially useful when $F(t)$ can be written as a sum of sinusoidal terms, because the solutions for each sinusoidal term is analytic, and are given in the previous two subsections.

Driving forces are often periodic, even when they are not sinusoidal. Periodicity implies that for some time $\tau$
\begin{eqnarray}
F(t+\tau)=F(t).
\end{eqnarray}
One example of a non-sinusoidal periodic force is a square wave. Many components in electric circuits are non-linear, e.g. diodes, which makes many wave forms non-sinusoidal even when the circuits are being driven by purely sinusoidal sources.

For the sinusoidal example studied in the previous subsections the period is $\tau=2\pi/\omega$. However, higher harmonics can also satisfy the periodicity requirement. In general, any force that satisfies the periodicity requirement can be expressed as a sum over harmonics,
\begin{equation}
F(t)=\frac{f_0}{2}+\sum_{n>0} f_n\cos(2n\pi t/\tau)+g_n\sin(2n\pi t/\tau).
\end{equation}
From the previous subsection, one can write down the answer for $x_{pn}(t)$, by substituting $f_n/m$ or $g_n/m$ for $F_0/m$ into Eq.s (\ref{eq:fastdriven1}) or (\ref{eq:fastdriven2}) respectively. By writing each factor $2n\pi t/\tau$ as $n\omega t$, with $\omega\equiv 2\pi/\tau$,
\begin{equation}
\label{eq:fourierdef1}
F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t).
\end{equation}
The solutions for $x(t)$ then come from replacing $\omega$ with $n\omega$ for each term in the particular solution in Eq.s (\ref{eq:partform}-\ref{eq:Ddrive}),
\begin{eqnarray}
x_p(t)&=&\frac{f_0}{2k}+\sum_{n>0} \alpha_n\cos(n\omega t-\delta_n)+\beta_n\sin(n\omega t-\delta_n),\\
\nonumber
\alpha_n&=&\frac{f_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\
\nonumber
\beta_n&=&\frac{g_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\
\nonumber
\delta_n&=&\tan^{-1}\left(\frac{2\beta n\omega}{\omega_0^2-n^2\omega^2}\right).
\end{eqnarray}
Because the forces have been applied for a long time, any non-zero damping eliminates the homogenous parts of the solution, so one need only consider the particular solution for each $n$.

The problem will considered solved if one can find expressions for the coefficients $f_n$ and $g_n$, even though the solutions are expressed as an infinite sum. The coefficients can be extracted from the function $F(t)$ by
\begin{eqnarray}
\label{eq:fourierdef2}
f_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\cos(2n\pi t/\tau),\\
\nonumber
g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\sin(2n\pi t/\tau).
\end{eqnarray}

To check the consistency of these expressions and to verify Eq. (\ref{eq:fourierdef2}), one can insert the expansion of $F(t)$ in Eq. (\ref{eq:fourierdef1}) into the expression for the coefficients in Eq. (\ref{eq:fourierdef2}) and see whether
\begin{eqnarray}
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~\left\{
\frac{f_0}{2}+\sum_{m>0}f_m\cos(m\omega t)+g_m\sin(m\omega t)
\right\}\cos(n\omega t).
\end{eqnarray}
Immediately, one can throw away all the terms with $g_m$ because they convolute an even and an odd function. The term with $f_0/2$ disappears because $\cos(n\omega t)$ is equally positive and negative over the interval and will integrate to zero. For all the terms $f_m\cos(m\omega t)$ appearing in the sum, one can use angle addition formulas to see that $\cos(m\omega t)\cos(n\omega t)=(1/2)(\cos[(m+n)\omega t]+\cos[(m-n)\omega t]$. This will integrate to zero unless $m=n$. In that case the $m=n$ term gives
\begin{equation}
\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2},
\end{equation}
and
\begin{eqnarray}
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\
\nonumber
&=&f_n~\checkmark.
\end{eqnarray}
The same method can be used to check for the consistency of $g_n$.

\example
Consider the driving force:
\begin{equation}
F(t)=At/\tau,~~-\tau/2<t<\tau/2,~~~F(t+\tau)=F(t).
\end{equation}
Find the Fourier coefficients $f_n$ and $g_n$ for all $n$ using Eq. (\ref{eq:fourierdef2}).

{\bf Solution:} Only the odd coefficients enter by symmetry, i.e. $f_n=0$. One can find $g_n$ integrating by parts,
\begin{eqnarray}
\label{eq:fouriersolution}
g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2}dt~\sin(n\omega t) \frac{At}{\tau}\\
\nonumber
u&=&t,~dv=\sin(n\omega t)dt,~v=-\cos(n\omega t)/(n\omega),\\
\nonumber
g_n&=&\frac{-2A}{n\omega \tau^2}\int_{-\tau/2}^{\tau/2}dt~\cos(n\omega t)
+\left.2A\frac{-t\cos(n\omega t)}{n\omega\tau^2}\right|_{-\tau/2}^{\tau/2}.
\end{eqnarray}
The first term is zero because $\cos(n\omega t)$ will be equally positive and negative over the interval. Using the fact that $\omega\tau=2\pi$,
\begin{eqnarray}
g_n&=&-\frac{2A}{2n\pi}\cos(n\omega\tau/2)\\
\nonumber
&=&-\frac{A}{n\pi}\cos(n\pi)\\
\nonumber
&=&\frac{A}{n\pi}(-1)^{n+1}.
\end{eqnarray}
The true function is compared to the expansion in Fig. \ref{fig:triangle} where the sum is cut off at finite $n$.
\begin{figure}
\centerline{\includegraphics[width=0.6\textwidth]{figs/triangle}}
\caption{\label{fig:triangle}
The periodic function $F(t)=t/\tau, |t|<\tau/2$ (black) is compared to the Fourier expansion described in Eq. (\ref{eq:fouriersolution}) with 10 terms (red) or 100 terms (green).}
\end{figure}

\exampleend

\subsection{Response to Transient Force}

Consider a particle at rest in the bottom of an underdamped harmonic oscillator, that then feels a sudden impulse, or change in momentum, $I=F\Delta t$ at $t=0$. This increases the velocity immediately by an amount $v_0=I/m$ while not changing the position. One can then solve the trajectory by solving Eq. (\ref{eq:homogsolution}) with initial conditions $v_0=I/m$ and $x_0=0$. This gives
\begin{equation}
x(t)=\frac{I}{m\omega'}e^{-\beta t}\sin\omega't, ~~t>0.
\end{equation}
Here, $\omega'=\sqrt{\omega_0^2-\beta^2}$. For an impulse $I_i$ that occurs at time $t_i$ the trajectory would be
\begin{equation}
x(t)=\frac{I_i}{m\omega'}e^{-\beta (t-t_i)}\sin[\omega'(t-t_i)] \Theta(t-t_i),
\end{equation}
where $\Theta(t-t_i)$ is a step function, i.e. $\Theta(x)$ is zero for $x<0$ and unity for $x>0$. If there were several impulses linear superposition tells us that we can sum over each contribution,
\begin{equation}
x(t)=\sum_i\frac{I_i}{m\omega'}e^{-\beta(t-t_i)}\sin[\omega'(t-t_i)]\Theta(t-t_i)
\end{equation}

Now one can consider a series of impulses at times separated by $\Delta t$, where each impulse is given by $F_i\Delta t$. The sum above now becomes an integral,
\begin{eqnarray}\label{eq:Greeny}
x(t)&=&\int_{-\infty}^\infty dt'~F(t')\frac{e^{-\beta(t-t')}\sin[\omega'(t-t')]}{m\omega'}\Theta(t-t')\\
\nonumber
&=&\int_{-\infty}^\infty dt'~F(t')G(t-t'),\\
\nonumber
G(\Delta t)&=&\frac{e^{-\beta\Delta t}\sin[\omega' \Delta t]}{m\omega'}\Theta(\Delta t)
\end{eqnarray}
The quantity $e^{-\beta(t-t')}\sin[\omega'(t-t')]/m\omega'\Theta(t-t')$ is called a Green's function, $G(t-t')$. It describes the response at $t$ due to a force applied at a time $t'$, and is a function of $t-t'$. The step function ensures that the response does not occur before the force is applied. One should remember that the form for $G$ would change if the oscillator were either critically- or over-damped.

When performing the integral in Eq. (\ref{eq:Greeny}) one can use angle addition formulas to factor out the part with the $t'$ dependence in the integrand,
\begin{eqnarray}
\label{eq:Greeny2}
x(t)&=&\frac{1}{m\omega'}e^{-\beta t}\left[I_c(t)\sin(\omega't)-I_s(t)\cos(\omega't)\right],\\
\nonumber
I_c(t)&\equiv&\int_{-\infty}^t dt'~F(t')e^{\beta t'}\cos(\omega't'),\\
\nonumber
I_s(t)&\equiv&\int_{-\infty}^t dt'~F(t')e^{\beta t'}\sin(\omega't').
\end{eqnarray}
If the time $t$ is beyond any time at which the force acts, $F(t'>t)=0$, the coefficients $I_c$ and $I_s$ become independent of $t$.

\example
Consider an undamped oscillator ($\beta\rightarrow 0$), with characteristic frequency $\omega_0$ and mass $m$, that is at rest until it feels a force described by a Gaussian form,
\begin{eqnarray*}
F(t)&=&F_0 \exp\left\{\frac{-t^2}{2\tau^2}\right\}.
\end{eqnarray*}
For large times ($t>>\tau$), where the force has died off, find $x(t)$.\\
{\bf Solution:} Solve for the coefficients $I_c$ and $I_s$ in Eq. (\ref{eq:Greeny2}). Because the Gaussian is an even function, $I_s=0$, and one need only solve for $I_c$,
\begin{eqnarray*}
I_c&=&F_0\int_{-\infty}^\infty dt'~e^{-t^{\prime 2}/(2\tau^2)}\cos(\omega_0 t')\\
&=&\Re F_0 \int_{-\infty}^\infty dt'~e^{-t^{\prime 2}/(2\tau^2)}e^{i\omega_0 t'}\\
&=&\Re F_0 \int_{-\infty}^\infty dt'~e^{-(t'-i\omega_0\tau^2)^2/(2\tau^2)}e^{-\omega_0^2\tau^2/2}\\
&=&F_0\tau \sqrt{2\pi} e^{-\omega_0^2\tau^2/2}.
\end{eqnarray*}
The third step involved completing the square, and the final step used the fact that the integral
\begin{eqnarray*}
\int_{-\infty}^\infty dx~e^{-x^2/2}&=&\sqrt{2\pi}.
\end{eqnarray*}
To see that this integral is true, consider the square of the integral, which you can change to polar coordinates,
\begin{eqnarray*}
I&=&\int_{-\infty}^\infty dx~e^{-x^2/2}\\
I^2&=&\int_{-\infty}^\infty dxdy~e^{-(x^2+y^2)/2}\\
&=&2\pi\int_0^\infty rdr~e^{-r^2/2}\\
&=&2\pi.
\end{eqnarray*}
Finally, the expression for $x$ from Eq. (\ref{eq:Greeny2}) is
\begin{eqnarray*}
x(t>>\tau)&=&\frac{F_0\tau}{m\omega_0} \sqrt{2\pi} e^{-\omega_0^2\tau^2/2}\sin(\omega_0t).
\end{eqnarray*}

\exampleend

\subsection{Solving Equations of Motion Numerically}
%If one has a known force $F(t)$, and initial conditions $x(t=0)=x_0$ and $v(t=0)=v_0$, one can solve for the equations of motion numerically. First, one must choose a small time step $\Delta t$, smaller than any characteristic time scale of the problem. One can then define a mesh $x_n$, where $n=0$ so some maximum number of steps $N$. We will defines these values as
\begin{eqnarray}
x_n=x(n\Delta t).
\end{eqnarray}
Assume that one knows $x_n$ for all $i<\le j$. One can express the velocities and accelerations in Newton's equations of motion for a mass $m$ as:

\begin{eqnarray}
v_n&=&\frac{x_{n+1}-x_{n-1}}{2\Delta t},\\
\nonumber
a_n&=&\frac{v_{n+1/2}-v_{n-1/2}}{\Delta t}\\
\nonumber
&=&\frac{x_{n+1}-2x_n+x_{n-1}}{(\Delta t)^2}.
\end{eqnarray}
The equations of motion at $t_n=n\Delta t$ become
\begin{eqnarray}
F(x_n)&=&ma_n.
\end{eqnarray}
If one knows $x_{n-1}$ and $x_n$ the only unknown in the equation is $x_{n+1}$. One can solve for it, then move onto the next $n$. Note that to proceed one needs to know $x$ at two points. This can be tricky depending on how the initial conditions are specified.

\example
Write a numerical program to solve the evolution of a particle of mass $m$ feeling a spring force, $-kx$ and a drag force, $-bv$. Assume there is also some external force, $F(t)=F_0\sin\omega t$. Let the initial conditions be $x(t=0)=0$ and $v(t=0)=v_0$.

{\bf Solution:} The differential equation,
\begin{eqnarray*}
m\ddot{x}+b\dot{x}+kx&=&0,\\
\end{eqnarray*}
becomes
\begin{eqnarray*}
\frac{m}{(\Delta t)^2}\left(x_{n+1}-2x_n+x_{n-1}\right)+\frac{b}{2\Delta t}\left(x_{n+1}-x_{n-1}\right)+kx_n&=&F(n\Delta t).
\end{eqnarray*}
Solving for $x_{n+1}$,
\begin{eqnarray*}
\left\{\frac{m}{(\Delta t)^2}+\frac{b}{2\Delta t}\right\}x_{n+1}&=&\left[\frac{2m}{(\Delta t)^2}-k\right]x_n+F(n\Delta t)
+\left[-\frac{m}{(\Delta t)^2}+\frac{b}{2\Delta t}\right]x_{n-1},\\
x_{n+1}&=&\frac{\left[\frac{2m}{(\Delta t)^2}-k\right]x_n+F(n\Delta t)
+\left[-\frac{m}{(\Delta t)^2}+\frac{b}{2\Delta t}\right]x_{n-1}}{\frac{m}{(\Delta t)^2}+\frac{b}{2\Delta t}}.
\end{eqnarray*}
In order to iterate forward to find $x_{n+1}$, one must know $x_{n-1}$ and $x_n$. However, to get started, one only knows one value of $x$, along with the velocity being zero. To get $x$ at two time steps, one must can use the above two pieces of information,
\begin{eqnarray*}
v_0&=&\frac{x_1-x_{-1}}{2\Delta t},\\
-bv_0-kx_0&=&m\frac{x_1-2x_0+x_{-1}}{\Delta t^2},
\end{eqnarray*}
then combine the equations to eliminate $x_{-1}$ to solve for $x_1$. The fact that $x_0=0$ makes the algebra simpler,
\begin{eqnarray*}
x_1&=&v_0\Delta t-\frac{bv_0\Delta t^2}{2m}.
\end{eqnarray*}

The program might read:
{\tt\begin{verbatim}
double F(double t){
   double F0=????,omega=????;
   return F0*sin(omega*t);
}
void main(){
   const int Ntsteps=???;
   double x[Ntsteps+1],dt=???,k=???,m=???,b=???,v0=???;
   x[0] = 0.0;
   x[1] = v0*dt-0.5*b*v0/m;
   for(int it=1;it<Ntsteps;it=it+1){
      x[it+1]=( (2.0*m/(dt*dt)) -k)*x[it] + F(it*dt)
      + (0.5*b/dt)*x[it-1] ) / ( (m/(dt*dt) + 0.5*b/dt );
   }
}
\end{verbatim}}
Question marks would be replaced by the given parameters of the problem.

\exampleend

\subsection{Exercises}

\begin{enumerate}

\item A floating body of uniform cross-sectional area $A$ and of mass density $\rho$ and at equilibrium displaces a volume $V$. Show that the period of small oscillations about the equilibrium position is given by
\[
\tau=2\pi\sqrt{V/gA}
\]

\item Show that the critically damped solution, Eq. (\ref{eq:criticallydamped}), is indeed the solution to the differential equation.

\item Consider an over-damped harmonic oscillator with a mass of $m=2$ kg, a damping factor $b=20$ Ns/m, and a spring constant $k=32$ N/m. If the initial position is $x=0.125$ m, and if the initial velocity is $-2.0$ m/s, find and graph the motion as a function of time. Graphically, find the time at which the mass crosses the origin.

\item Consider a particle of mass $m$ moving in a one-dimensional potential,
\[
V(x)=-k\frac{x^2}{2}+\alpha\frac{x^4}{4}.
\]
\begin{enumerate}
\item What is the angular frequency for small vibrations about the minimum of the potential? What is the effective spring constant?
\item If you add a small force $F=F_0\cos(\omega t-\phi)$, and if the particle is initially at the minimum with zero initial velocity, find its position as a function of time.
\item If there is a small drag force $-bv$, repeat (b).
\end{enumerate}

\item Consider the periodic force, $F(t+\tau)=F(t)$,
\[
F(t)=\left\{\begin{array}{rl}
-A,&-\tau/2<t<0\\
+A,&0<t<\tau/2
\end{array}\right.
\]
Find the coefficients $f_n$ and $g_n$ defined in Eq. (\ref{eq:fourierdef2}).

\item A ``delta'' function is a function that is zero everywhere except where the argument is zero. At this point the function is infinite so that the area under the curve is unity. The delta function obeys the relations
\begin{eqnarray*}
\int_a^b dt'~ \delta(t'-t_0)&=&1,\\
\int_a^b dt'~ f(t')\delta(t'-t_0)&=&f(t_0),
\end{eqnarray*}
as long as the time $t_0$ lies between the limits $a$ and $b$. Otherwise, the integrals are zero.
\begin{enumerate}
\item Show that the following function
\[
\left.\frac{1}{\pi}\frac{\Lambda}{\Lambda^2+x^2}\right|_{\Lambda\rightarrow 0}=\delta(x).
\]
i.e. show that it is zero everywhere except the origin and that it integrates to unity.
\item A step function, $\Theta(t)$, a.k.a. the ``Theta'' function or the Heaviside function, is zero for negative arguments and is unity for positive arguments. Show that
\[
\frac{d}{dx}\Theta(x-x_0)=\delta(x-x_0).
\]
\item Using the definition of Fourier coefficients in Eq.s (\ref{eq:fourierdef1}) and (\ref{eq:fourierdef2}), show that
\[
\delta(t-t_0)=-\frac{1}{\tau}+\frac{2}{\tau}\sum_{n=0}^{\infty}\cos(\omega_n(t-t_0)),~~~\omega_n=2n\pi/\tau.
\]
\end{enumerate}

\item Consider the complex function in the interval $-\tau/2<t<\tau/2$,
\[
f(t)=-\frac{1}{\tau}+\frac{2}{\tau}\sum_{n=0}^\infty e^{in\omega(t-t_0)}, ~~~\omega=2\pi/\tau.
\]
\begin{enumerate}
\item Using the fact that if one integrates over the interval, $-\tau/2<t<\tau/2$, that $\int dt ~e^{in\omega t}=0$ for $n\ne 0$, show that
\[
\int dt f(t)=1.
\]
\item Using the fact that $\sum_n x^n=1/(1-x)$, show that
\[
f(t)=-\frac{1}{\tau}+\frac{2/\tau}{1-e^{i\omega(t-t_0)}}.
\]
\item From the expression in (b), show that the real part of $f(t)$ obeys
\[
\Re f(t)=0,~~{\rm for}~t\ne t_0
\]
This shows that $\Re f$ is a delta function and validates the result of the previous problem.
\end{enumerate}

\item A particle of mass $m$ in an undamped harmonic oscillator with angular frequency $\omega_0$ is at rest in the bottom of the well, when it experiences a force
\[
F(t)=\left\{\begin{array}{rl}
0,&t<0\\
G,&0<t<\tau\\
0,&t>\tau\end{array}
\right.
\]
Find $x(t)$ for $t>\tau$ using Eq. (\ref{eq:Greeny2}).

\item Consider a particle of mass $m$ in a harmonic oscillator with angular frequency $\omega_0$ and no damping. It experiences an external force,
\[
F(t)=f_0\Theta(t)e^{-\gamma t}.
\]
A ``Theta'' function is a step function, and is zero for negative arguments and unity for positive arguments.
\begin{enumerate}
\item Find a particular solution, $x_p(t)$, assuming it is proportional to $e^{-\gamma t}$.
\item For a particle initially at rest at the origin at $t=0$, find $x(t)$ by adding in the homogenous solutions and matching the BC, determine the arbitrary constants.
\item Use Eq. (\ref{eq:Greeny}) or Eq. (\ref{eq:Greeny2}) to find $x(t)$. Check that you get the same result as (b).
\end{enumerate}

\end{enumerate}


\documentclass[a4paper]{article}

\input{temp}

\begin{document}

\title{Metric and Topological spaces}
\date{Easter 2016}

\maketitle

\newpage

\tableofcontents

\newpage

\section{Introduction}
Suppose $\left(x_n\right)$ is a sequence of real numbers. $\left(x_n\right)$ converges to $x\in \R$ if for every $\varepsilon>0$, there exists some $N$ such that $|x_n-x|<\varepsilon$ whenever $n>N$. We know that a function $f:\R \to \R$ is \emph{continuous} if $\left(f\left(x_n\right)\right)\to f\left(x\right)$ whenever $\left(x_n\right) \to x$. But what does it mean for a sequence $\left(x_n\right)$ to converge if $x_n\in X \neq \R$?

\begin{eg}
Let
\begin{equation*}
\begin{aligned}
X=\left\{A\in M_{n\times n} \left(\R\right) | A^T =A\right\}
\end{aligned}
\end{equation*}
and let $f\left(A\right)$ be the largest eigenvalue of $A$. Is $f$ continuous?
\end{eg}

\begin{eg}
Let
\begin{equation*}
\begin{aligned}
&X=\left\{f:\left[0,1\right] \to \R | f  \text{ is continuous} \right\} \\
&F\left(f\right) = f\left(\frac{1}{2}\right)
\end{aligned}
\end{equation*}
\end{eg}
Is $F$ continuous?

\begin{thm} (Intermediate value theorem)\\
If $f:\left[0,1\right]\to \R$ is continuous and $f\left(0\right)\left<0, f\left(1\right)\right>0$, then $\exists x \in \left[0,1\right]$ with $f\left(x\right)=0$.
\end{thm}

\begin{thm} (Maximum value theorem)\\
If $f:\left[0,1\right] \to \R$ is continuous, then $\exists x \in \left[0,1\right]$ such that $f\left(x\right) \geq f\left(y\right)$ for all $y\in\left[0,1\right]$.
\end{thm}

These are both theorems about $\left[0,1\right]$. However, they might not be true if we change to another domain. For example, neither of these theorems hold for $\left[0,1\right] \cap \Q$.

\begin{eg}
Let
\begin{equation*}
\begin{aligned}
f\left(x\right) = x^2-\frac{1}{2}
\end{aligned}
\end{equation*}
Then $f\left(0\right)\left<0, f\left(1\right)\right>0$, but there is no $x\in\left[0,1\right] \cap \Q$ such that $f\left(x\right) = 0$.
\end{eg}

\newpage
\section{Metric spaces}
Suppose $\left(\mathbf{v}_n\right) = \left(\left(x_n,y_n\right)\right)$ is a sequence in $\R^2$. What should it mean for $\left(\mathbf{v}_n\right)$ to converge to $\mathbf{v} = \left(x,y\right)$?\\
A natural thought would be that the sequence ocnverges to $\left(x,y\right)$ if $\left(x_n\right) \to x$ and $\left(y_n\right) \to y$. That is then equivalent to
\begin{equation*}
\begin{aligned}
&\left(x_n-x\right)^2 + \left(y_n-y\right)^2 \to 0 \iff
&|\mathbf{v}_n-\mathbf{v}| \to 0.
\end{aligned}
\end{equation*}

\begin{defi} (Metric space)\\
A \emph{metric space} is a pair $\left(X,d\right)$ where $X$ is a set and $d:X\times X \to \R$, called the \emph{metric}, or \emph{distance function}, that satisfies the following properties:
\begin{equation*}
\begin{aligned}
&\bullet d\left(x,y\right) \geq 0 \forall x,y\in X;\\
&\bullet d\left(x,y\right) = 0 \iff x=y;\\
&\bullet d\left(x,y\right) = d\left(y,x\right);\\
&\bullet d\left(x,z\right) \leq d\left(x,y\right) + d\left(y,z\right).
\end{aligned}
\end{equation*}
\end{defi}

\begin{eg}(Euclidean metric)\\
Let $X=\R^n$, $d\left(\mathbf{x},\mathbf{y}\right) = |\mathbf{x}-\mathbf{y}|$, where
\begin{equation*}
\begin{aligned}
|\mathbf{v}| = \left(\sum_{i=1}^n v_i^2\right)^\frac{1}{2}
\end{aligned}
\end{equation*}
is the \emph{Euclidean metric} on $\R^n$. Note that this satisfies the triangle inequality.
\end{eg}

\begin{eg} (Metric subspace)\\
Suppose $\left(X,d_X\right)$ is a metric space and $Y\subset X$. Then $\left(Y,d_Y\right)$ is a metric space, where $d_Y\left(y_1,y_2\right) = d_X\left(y_1,y_2\right)$, i.e. $d_Y=d_X |_{Y\times Y}$.\\
We say $\left(Y,d_Y\right)$ is a \emph{subspace} of $\left(X,d_X\right)$, or just say $Y$ is a subspace of $X$.
\end{eg}

\begin{eg}
Consider
\begin{equation*}
\begin{aligned}
\left\{A \in M_{n\times n} \left(\R\right) | A^T = A \right\} \subset \R^{n^2}.
\end{aligned}
\end{equation*}
\end{eg}

\begin{defi} (Convergence)\\
If $\left(X,d\right)$ is a metric space and $\left(x_n\right)$ is a sequence in $X$, we say $\left(x_n\right)$ converges to $x$ if for every $\varepsilon >0$ there exists $N$ such that $d\left(x_n,x\right) < \varepsilon$ whenever $n>N$.
\end{defi}

\begin{prop}
Suppose $\left(x_n\right)$ is a sequence in a metric space $\left(X,d\right)$ that $\left(x_n\right) \to x$ and $\left(x_n\right) \to y$. Then $x=y$.
\begin{proof}
Given $\varepsilon>0$, pick $N_1,N_2$ with
\begin{equation*}
\begin{aligned}
&n>N_1 \implies d\left(x_n,x\right) < \frac{\varepsilon}{2},\\
&n>N_2 \implies d\left(x_n,y\right) < \frac{\varepsilon}{2}
\end{aligned}
\end{equation*}
Then if $n>\max\left\{N_1,N_2\right\}$,
\begin{equation*}
\begin{aligned}
0\leq d\left(x,y\right)\leq d\left(x,x_n\right) + d\left(x_n,y\right) = d\left(x,x_n\right) + d\left(y,x_n\right) < \frac{\varepsilon}{2} + \frac{\varepsilon}{2} = \varepsilon.
\end{aligned}
\end{equation*}
Since $\varepsilon$ is arbitrary, $d\left(x,y\right)=0$. So $x=y$.
\end{proof}
\end{prop}

\begin{defi} (Continuity)\\
If $\left(X,d_X\right)$ and $\left(Y,d_Y\right)$ are metric spaces, then $f:X\to Y$ is \emph{continuous} if $\left(f\left(x_n\right)\right) \to f\left(x\right)$ whenever $\left(x_n\right) \to x$.
\end{defi}

\begin{prop}
If $\left(X,d_X\right), \left(Y,d_Y\right)$ and $\left(Z,d_Z\right)$ are metric spaces, and $f:X\to Y$ and $g:Y\to Z$ are both continuous, then $g \circ f:X\to Z$ is also continuous.
\begin{proof}
Suppose $\left(x_n\right) \to x$ in $X$. Since $f$ is continuous,
\begin{equation*}
\begin{aligned}
\left(f\left(x_n\right)\right) \to f\left(x\right)
\end{aligned}
\end{equation*}
in $Y$. Since $g$ is also continuous,
\begin{equation*}
\begin{aligned}
\left(g\left(f\left(x_n\right)\right)\right) \to g\left(f\left(x\right)\right)
\end{aligned}
\end{equation*}
in $Z$, i.e.
\begin{equation*}
\begin{aligned}
\left(g\circ f\left(x_n\right)\right) \to g\circ f\left(x\right).
\end{aligned}
\end{equation*}
So $g\circ f$ is continuous.
\end{proof}
\end{prop}

\begin{eg} (Discrete metric)\\
Let $X$ be any set, and let
\begin{equation*}
\begin{aligned}
d\left(x,y\right) = \left\{
\begin{array}{ll}
1 & x\neq y\\
0 & x=y
\end{array}
\right.
\end{aligned}
\end{equation*}
This is a metric space.
\end{eg}

\begin{eg}
Let $X=\R^2$, $\mathbf{x}=\left(x_1,x_2\right)$, $\mathbf{x}'=\left(x_1',x_2'\right)$, and
\begin{equation*}
\begin{aligned}
d\left(\mathbf{x},\mathbf{x}'\right) = |x_1-x_1'| + |x_2-x_2'|.
\end{aligned}
\end{equation*}
Triangle inequality follows by:
\begin{equation*}
\begin{aligned}
d\left(x,z\right) &= |x_1-z_1| + |x_2-x_2| \\
&\leq |x_1-y_1| + |y_1-z_1| + |x_2 - y_2| + |y_2 - z_2| \\
&= d\left(x,y\right) + d\left(y,z\right).
\end{aligned}
\end{equation*}
\end{eg}

\begin{eg} (British Railway metric)\\
Let $X=\R^2$, and
\begin{equation*}
\begin{aligned}
d\left(\mathbf{x},\mathbf{y}\right) = \left\{
\begin{array}{ll}
|\mathbf{x}-\mathbf{y}| &  \mathbf{x}=k\mathbf{y}\\
|\mathbf{x}| + |\mathbf{y}| & \text{ otherwise}
\end{array}
\right.
\end{aligned}
\end{equation*}
(Unless you, your destination and London are collinear, you always have to take a train to London first and transfer there.)
\end{eg}

\begin{defi}
If $V$ is a real vector space, a \emph{norm} on $V$ is a map $||\cdot|| : V \to \R$ satisfying
\begin{equation*}
\begin{aligned}
&\bullet ||\mathbf{v}|| \geq 0 \forall \mathbf{v}\in V;\\
&\bullet ||\mathbf{v}|| = 0 \iff \mathbf{v}=\mathbf{0} \in V;\\
&\bullet ||\lambda \mathbf{v}|| = |\lambda| ||\mathbf{v}||, \lambda \in \R, \mathbf{v} \in V;\\
&\bullet ||\mathbf{v}+\mathbf{w}|| \leq ||\mathbf{v}|| + ||\mathbf{w}||.
\end{aligned}
\end{equation*}
\end{defi}

\begin{eg}
Let $V = \R^n$,
\begin{equation*}
\begin{aligned}
||\mathbf{v}|| = \sum_{i=1}^n |v_i|
\end{aligned}
\end{equation*}
(this is called the Manhattan norm).
\end{eg}

\begin{lemma}
If $||\cdot||$ is a norm on $V$, then
\begin{equation*}
\begin{aligned}
d\left(\mathbf{x},\mathbf{y}\right) = ||\mathbf{x}-\mathbf{y}||
\end{aligned}
\end{equation*}
defines a metric on $V$.
\begin{proof}
Firstly
\begin{equation*}
\begin{aligned}
d\left(\mathbf{x},\mathbf{y}\right) = ||\mathbf{x}-\mathbf{y}|| \geq 0
\end{aligned}
\end{equation*}
by our definition of norm. The second holds by
\begin{equation*}
\begin{aligned}
d\left(\mathbf{x},\mathbf{y}\right) = 0 &\iff ||\mathbf{x}-\mathbf{y}|| = 0\\
&\iff \mathbf{x}-\mathbf{y}=0\\
&\iff \mathbf{x} = \mathbf{y}.
\end{aligned}
\end{equation*}
For the third condition,
\begin{equation*}
\begin{aligned}
d\left(\mathbf{y}-\mathbf{x}\right) &= ||\mathbf{y}-\mathbf{x}|| \\
&= ||\left(-1\right)\left(\mathbf{x}-\mathbf{y}\right)||\\
&= |-1| ||\mathbf{x}-\mathbf{y}||\\
&= d\left(\mathbf{x},\mathbf{y}\right)
\end{aligned}
\end{equation*}
Lastly
\begin{equation*}
\begin{aligned}
d\left(\mathbf{x},\mathbf{y}\right) + d\left(\mathbf{y},\mathbf{z}\right) &= ||\mathbf{x}-\mathbf{y}|| + ||\mathbf{y}-\mathbf{z}||\\
&\geq \mathbf{x}-\mathbf{z}\\
&= d\left(\mathbf{x},\mathbf{z}\right)
\end{aligned}
\end{equation*}
\end{proof}
\end{lemma}

The Manhattan metric on $\R^2$ is induced by the Manhattan norm (exercise).

\begin{defi}
Let $V$ be a real vector space. An \emph{inner product} on $V$ is a map $\left<\cdot, \cdot\right>: V\times V \to \R$, satisfying
\begin{equation*}
\begin{aligned}
&\bullet \left<\mathbf{v},\mathbf{v}\right> \geq 0 \forall \mathbf{v}\in V;\\
&\bullet \left<\mathbf{v},\mathbf{v}\right> = 0 \iff \mathbf{v}=\mathbf{0};\\
&\bullet \left<\mathbf{v},\mathbf{w}\right> = \left<\mathbf{w},\mathbf{v}\right>;\\
&\bullet \left<\mathbf{v},\mathbf{w_1}+\lambda \mathbf{w_2}\right> = \left<\mathbf{v},\mathbf{w_1}\right> + \lambda\left<\mathbf{v},\mathbf{w_2}\right>.
\end{aligned}
\end{equation*}
\end{defi}

The standard inner product on $\R^n$ is given by
\begin{equation*}
\begin{aligned}
\left<\mathbf{v},\mathbf{w}\right> = \mathbf{v}\cdot\mathbf{w}=\sum_{i=1}^n v_i w_i
\end{aligned}
\end{equation*}

\begin{thm} (Cauchy-Schwartz inequality)\\
If $\left<\cdot,\cdot\right>$ is an inner product on $V$, then
\begin{equation*}
\begin{aligned}
\left<\mathbf{v},\mathbf{w}\right>^2 \leq \left<\mathbf{v},\mathbf{v}\right>\left<\mathbf{w},\mathbf{w}\right>.
\end{aligned}
\end{equation*}
\begin{proof}
Consider $\left<\mathbf{v}+\lambda\mathbf{w},\mathbf{v}+\lambda\mathbf{w}\right>\geq 0$ by definition. So
\begin{equation*}
\begin{aligned}
\left<\mathbf{v},\mathbf{v}\right> + 2\lambda\left<\mathbf{v},\mathbf{w}\right>+\lambda^2\left<\mathbf{w},\mathbf{w}\right> \geq 0
\end{aligned}
\end{equation*}
Now if $ax^2 + bx + c\geq 0$ for all $x\in \R$, then $ax^2+bx+c=0$ has at most one real root. So $b^2-4ac \leq 0$.\\
Now we've just seen $a\lambda^2+b\lambda+c\geq 0$ for all $\lambda\in\R$, where $a=\left<\mathbf{w},\mathbf{w}\right>$, $b=2\left<\mathbf{v},\mathbf{w}\right>$, $c=\left<\mathbf{v},\mathbf{v}\right>$. So
\begin{equation*}
\begin{aligned}
4\left<\mathbf{v},\mathbf{w}\right>^2 \leq 4\left<\mathbf{w},\mathbf{w}\right>\left<\mathbf{v},\mathbf{v}\right>
\end{aligned}
\end{equation*}
which is the desired result.
\end{proof}
\end{thm}

\begin{coro}
If $\left<,\right>$ is an inner product on $V$, then $||\mathbf{v}|| = \left(\left<\mathbf{v},\mathbf{v}\right>\right)^{\frac{1}{2}}$ is a norm on $V$.
For the proof we just need to verify all the conditions again. Cauchy-Schwartz inequality is required for verifying the fourth condition.
\end{coro}

Another exercise: The norm on $\R^n$ induced by the standard inner product is Euclidean length:
\begin{equation*}
\begin{aligned}
||\mathbf{v}|| = |\mathbf{v}| = \left(\sum_{i=1}^n v_i^2\right)^\frac{1}{2}
\end{aligned}
\end{equation*}
The metric induced by the norm is the Euclidean norm.\\
And another exercise: is the Manhattan norm induced by an inner product on $\R^n$?

\begin{eg}
Let $V=\R^n$.\\
1)
\begin{equation*}
\begin{aligned}
||\mathbf{v}||_1=\sum_{i=1}^n |v_i|
\end{aligned}
\end{equation*}
The Manhattan norm;\\
2)
\begin{equation*}
\begin{aligned}
||\mathbf{v}||_2 = \left(\sum_{i=1}^n v_i^2\right)^\frac{1}{2}
\end{aligned}
\end{equation*}
The Euclidean norm;\\
3)
\begin{equation*}
\begin{aligned}
||\mathbf{v}||_\infty = \max_{1\leq i \leq n |v_i|}
\end{aligned}
\end{equation*}
(In example sheet:
\begin{equation*}
\begin{aligned}
||\mathbf{v}||_p = \left(\sum_{i=1}^n |v_i|^p \right)^\frac{1}{p}
\end{aligned}
\end{equation*}
is a norm for all $1\leq p < \infty$.)
\end{eg}

\begin{eg}
Let
\begin{equation*}
\begin{aligned}
V=C\left[0,1\right] := \left\{ f:\left[0,1\right] \to \R | f \text{ is continuous} \right\}
\end{aligned}
\end{equation*}
where
\begin{equation*}
\begin{aligned}
&\left(\lambda f\right)\left(x\right) = \lambda f\left(x\right),\\
&\left(f+g\right) \left(x\right) = f\left(x\right) + g\left(x\right)
\end{aligned}
\end{equation*}
\end{eg}
1)
\begin{equation*}
\begin{aligned}
||f||_1 = \int_0^1 |f\left(x\right)| dx
\end{aligned}
\end{equation*}
2)
\begin{equation*}
\begin{aligned}
||f||_2 = \left(\int_0^1 f\left(x\right)^2\right)^\frac{1}{2} dx
\end{aligned}
\end{equation*}
3)
\begin{equation*}
\begin{aligned}
||f||_\infty = \max_{x \in \left[0,1\right]} |f\left(x\right)|
\end{aligned}
\end{equation*}
This is usually called the 'sup norm'.\\
How do we know that the first two norms satisfy the second condition, i.e. the norm is zero if and only if the function is zero? This is actually a standard result in analysis:

\begin{lemma}
Suppose $f\left[0,1\right]\to\R$ is continuous. If $f \not\cong 0$, then
\begin{equation*}
\begin{aligned}
\int_0^1 |f\left(x\right)|>0
\end{aligned}
\end{equation*}
\begin{proof}
Pick $x_0\in\left[0,1\right]$ with $f\left(x_0\right) \neq 0.$ Since $f$ is continuous, there exists $\delta > 0$ such that
\begin{equation*}
\begin{aligned}
|f\left(x\right) - f\left(x_0\right)| < \frac{|f\left(x_0\right)|}{2}
\end{aligned}
\end{equation*}
whenever $|x-x_0| < \delta$. Then for $|x-x_0|<\delta$, we have
\begin{equation*}
\begin{aligned}
|f\left(x\right)| > |f\left(x_0\right)| - \frac{|f\left(x_0\right)|}{2} \geq \frac{|f\left(x_0\right)|}{2}
\end{aligned}
\end{equation*}
So if we define
\begin{equation*}
\begin{aligned}
g\left(x\right) = \left\{
\begin{array}{ll}
\frac{|f\left(x_0\right)|}{2} & |x-x_0| < \delta\\
0 & \text{  otherwise}
\end{array}
\right.
\end{aligned}
\end{equation*}
Then $|f\left(x\right)| \geq g\left(x\right)$ for all $x\in\left[0,1\right]$.\\
So
\begin{equation*}
\begin{aligned}
\int_0^1 |f\left(x\right)| dx \geq \int_0^1 |g\left(x\right)| dx = 2\delta \frac{|f\left(x_0\right)|}{2} = \delta |f\left(x_0\right)|>0.
\end{aligned}
\end{equation*}
\end{proof}
\end{lemma}

\begin{eg}
\begin{equation*}
\begin{aligned}
f_n\left(x\right) = \left\{
\begin{array}{ll}
1-nx & x\in\left[0,\frac{1}{n}\right]\\
0 & x\in\left[\frac{1}{n},1\right]
\end{array}
\right.
\end{aligned}
\end{equation*}
Then
\begin{equation*}
\begin{aligned}
||f_n||_1 = \int_0^1 |f\left(x\right)| dx = \frac{1}{2}\left(\frac{1}{n}\right)\cdot 1 = \frac{1}{2n} \to 0
\end{aligned}
\end{equation*}
as $n\to \infty$.\\
So $\left(f_n\right) \to 0$ with respect to the metric induced by $|| \cdot ||_1$.\\
On the other hand,
\begin{equation*}
\begin{aligned}
||f_n||_\infty = 1
\end{aligned}
\end{equation*}
regardless of $n$, since $f\left(0\right)=1$.\\
This means that $\left(f_n\right)$ does not converge to 0 as $n\to \infty$ with respect to the metric induced by $||\cdot||_\infty$, i.e. the sup norm.
\end{eg}

Exercise: is it possible to find a sequence that converges with respect to $||\cdot||_1$ on $\R^2$, but not with respect to $||\cdot||_\infty$?

\begin{eg} (The \emph{p-adic} norm)\\
Let $p \in \N$ be a prime number. If $a \in \Z$, let $|a|_p = p^{-k}$, where $p^k | a$, but $p^{k+1} \nmid a$.\\
So
\begin{equation*}
\begin{aligned}
&|0|_p = 0,\\
&|ab|_p = |a|_p |b|_p,\\
&|a+b|_p \leq \max\left\{|a|_p, |b|_p\right\} \leq |a|_p + |b|_p
\end{aligned}
\end{equation*}

If $r=\frac{a}{b} \in \Q$, define
\begin{equation*}
\begin{aligned}
|r|_p  = \frac{|a|_p}{|b|_p}
\end{aligned}
\end{equation*}
Then the \emph{p-adic metric} on $\Q$ is defined by
\begin{equation*}
\begin{aligned}
d_p \left(r,s\right) = |r-s|_p
\end{aligned}
\end{equation*}
\end{eg}

Exercise: 1,2,4,8,16, ... $\to 0$ with respect to $d_2$.

\newpage
\section{Open and Closed Subsets}
Let $\left(X,d\right)$ be a metric space.

\begin{defi}
If $x\in X$ and $r\in \R$ with $r>0$, let
\begin{equation*}
\begin{aligned}
B_r\left(x\right) = \left\{ y\in X | d\left(x,y\right) < r \right\}
\end{aligned}
\end{equation*}
is the \emph{open ball} of radius $r$ with centre $x$,
\begin{equation*}
\begin{aligned}
\bar{B}_r \left(x\right) = \left\{y \in X | d\left(x,y\right) \leq r \right\}
\end{aligned}
\end{equation*}
is the \emph{closed ball} of radius $r$ with centre $x$.
\end{defi}

\begin{eg}
Let $X=\R$ with the usual metric. Then
\begin{equation*}
\begin{aligned}
&B_r\left(a\right) = \left(a-r,a+r\right),\\
&\bar{B}_r\left(a\right) = \left[a-r,a+r\right].
\end{aligned}
\end{equation*}
These are just the open and closed interval respectively.
\end{eg}

\begin{eg}
Let $X=\R^3$, with the Euclidean metric. Then
\begin{equation*}
\begin{aligned}
\bar{B}_1\left(0\right) = \left\{ \mathbf{v}\in \R^3 | |\mathbf{v}| \leq 1\right\}
\end{aligned}
\end{equation*}
which is a sphere with centre 0 and radius 1.
\end{eg}

\begin{eg}
Let $X=\R^2$, with the metric induced by\\ 1) the Manhattan norm, $||\cdot ||_1$;\\
2) the Euclidean norm, $||\cdot ||_2$;\\
3) the sup norm, $||\cdot ||_\infty$.\\
Now consider $\bar{B}_1\left(0\right)$. For the Manhattan norm, this is a square with with centre 0 and edges parallel to the axes(so with edge length 2); for the Euclidean norm this is a disc with centre 0 and radius 1; for the sup norm this is a square with centre 0 but edges making an angle of $\frac{\pi}{4}$ to the axes (so with edge length $\sqrt{2}$).
\end{eg}

\begin{eg}
Let $X=\R^2$, $d$ is induced by an inner product $\left<,\right>$: if $\mathbf{v}=x\mathbf{e}_1+y\mathbf{e}_2$, then
\begin{equation*}
\begin{aligned}
\left<\mathbf{v},\mathbf{v}\right> = ax^2 + 2bxy + cy^2
\end{aligned}
\end{equation*}
Then
\begin{equation*}
\begin{aligned}
B_1\left(0\right) = \left\{\left(x,y\right) | ax^2+2bxy+cy^2 \leq 1\right\}
\end{aligned}
\end{equation*}
where
\begin{equation*}
\begin{aligned}
a=\left<\mathbf{e}_1,\mathbf{e}_1\right>,\\
b=\left<\mathbf{e}_1,\mathbf{e}_2\right>,\\
c=\left<\mathbf{e}_2,\mathbf{e}_2\right>.
\end{aligned}
\end{equation*}
This is an ellipse.\\
So we know that $||\cdot ||_\infty$, $||\cdot ||_1$ are not induced from an inner product on $\R^2$.
\end{eg}

\begin{notation}
If $A\subset X$ is a subset, then $X\backslash A$, or $X-A$, is defined as
\begin{equation*}
\begin{aligned}
X-A = \left\{x\in X | x\not\in A\right\}
\end{aligned}
\end{equation*}
which is called the complement of $A$ (in $X$).
\end{notation}

\begin{defi} (Open and closed subset)\\
If $A\subset X$, we say $A$ is an \emph{open subset} if for every $x\in A$, $\exists r>0$ such that $B_r\left(x\right) \subset A$.\\
If $C\subset X$, we say $C$ is a \emph{closed subset} if $X-C$ is an open subset of $X$.
\end{defi}

\begin{prop}
If $X$ is a metric space, then $B_r\left(x\right)$ is an open subset of $X$, and $\bar{B}_r\left(x\right)$ is a closed subset of $X$.
\begin{proof}
Suppose $b\in B_r\left(a\right)$. Then $d\left(a,b\right) < r$. So $r_0 = r-d\left(a,b\right)>0$. Now if $c\in B_{r_0}\left(b\right)$, then
\begin{equation*}
\begin{aligned}
d\left(a,c\right) \leq d\left(a,b\right)+d\left(b,c\right)<d\left(a,b\right)+r_0=r
\end{aligned}
\end{equation*}
So $c\in B_r\left(a\right)$. Thus $B_{r_0}\left(b\right) \subset B_r\left(a\right)$. So $B_r\left(a\right)$ is open.\\
For the second part, we need to show that
\begin{equation*}
\begin{aligned}
X-\bar{B}_r\left(a\right) = \left\{ x\in X | d\left(x,a\right)>r\right\}
\end{aligned}
\end{equation*}
is open. The proof is analogous to the previous proof.
\end{proof}
\end{prop}

\begin{rem}
Note that $A\subset X$ may be \emph{neither} open nor closed. In fact if we take a random subset from a random metric space $X$, this is most likely the case. For example, consider $X=\R$ with the usual metric. then an obvious example is $\left[0,1\right)$,which is neither open nor closed; $\Q \subset \R$ is a more subtle example.
\end{rem}

\begin{rem}
$A\subset X$ can also be \emph{both} open and closed. Consider
\begin{equation*}
\begin{aligned}
X=\left[-1,1\right]-\left\{0\right\}
\end{aligned}
\end{equation*}
as a subspace of $\R$. Then
\begin{equation*}
\begin{aligned}
A=\left[-1,0\right)=B_1\left(-1\right) \subset X
\end{aligned}
\end{equation*}
is open. On the other hand, this is also a closed ball, since it is also
\begin{equation*}
\begin{aligned}
\bar{B}_{\frac{1}{2}} \left(-\frac{1}{2}\right) \subset X
\end{aligned}
\end{equation*}
So $A$ is both closed and open in $X$.
\end{rem}

\begin{rem}
Note that being open or closed is \emph{not} a property of a space, but a property of a subset of a space.\\
We've seen that $\left[-1,0\right)$ is not a closed subset of $\R$, but it \emph{is} a closed subset of $\left[-1,1\right] - \left\{0\right\}$.
\end{rem}

\begin{defi}
If $\left(X,d\right)$ is a metric space and $x\in X$, then $U$ is an \emph{open neighbourhood} of $x$ if $U\subset X$ is open and $x\in U$.
\end{defi}

\begin{prop}
Suppose sequence $\left(x_n\right) \to x$ and $U$ is an open neighbourhood of $x$. Then there exists $N$ such that $x_n\in U$ for all $n>N$.
\begin{proof}
Since $U\subset X$ is open, $x\in U$, $\exists \varepsilon > 0$ with
\begin{equation*}
\begin{aligned}
B_\varepsilon \left(x\right) \subset U.
\end{aligned}
\end{equation*}
Since $\left(x_n\right) \to x$, $\exists N$ such that $d\left(x_n,x\right) < \varepsilon$ whenever $n>N$. This implies that
\begin{equation*}
\begin{aligned}
x_n \in B_\varepsilon \left(x\right)
\end{aligned}
\end{equation*}
whenever $n>N$. So $x_n\in U$ whenever $n>N$.
\end{proof}
\end{prop}

\begin{defi} (Limit point)\\
If $\left(X,d\right)$ is a metric space and $A \subset X$, we say $x\in X$ is a \emph{limit point} of $A$ if there is a sequence $\left(x_n\right) \to x$ with $x_n \in A$ for all $n$.
\end{defi}

\begin{eg}
If $a\in A$, then $a$ is a limit point of $A$. We can just take a constant sequence with value $a$, which clearly converges to $a$.
\end{eg}

\begin{eg}
Let $X = \R$ with the usual metric, $A=\left(0,1\right)$. Then
\begin{equation*}
\begin{aligned}
\left(\frac{1}{n}\right) \to 0
\end{aligned}
\end{equation*}
and $\frac{1}{n} \in A$ for all $n\geq 1$. So $0$ is a limit point of $A$.
\end{eg}

\begin{prop}
Suppose $C\subset X$ is a closed subset and $x$ is a limit point of $C$. Then $x \in C$.
\begin{proof}
Suppose $\left(x_n\right) \to x$, where $x_n \in C$, but $x\not\in C$.\\
Since $C$ is closed, $U=X-C$ is open. So
\begin{equation*}
\begin{aligned}
x \not\in C \implies X \in U
\end{aligned}
\end{equation*}
So $U$ is an open neighbourhood of $x$.\\
Now $\left(x_n\right)$ converges to $x$ and $U$ is an open neighbourhood. So by the previous proposition, there exists an $N$ such that $x_n \in U$ for all $n>N$. But $x_n \in C$ for all $n$. Contradiction.
\end{proof}
\end{prop}

\begin{thm}
Suppose $f:\left(X,d_X\right) \to \left(Y,d_Y\right)$. Then the following conditions are equivalent:\\
1) $f$ is continuous;\\
2) $f^{-1}\left(U\right)$ is open in $X$ whenever $U$ is open in $Y$;\\
3) $f^{-1}\left(C\right)$ is closed in $X$ whenever $U$ is closed in $Y$.
\end{thm}

\end{document}


\hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{}\section{numpp\+:\+:differentiation\+:\+:symbolic\+:\+:differentiate$<$ Function, Order $>$ Class Template Reference}
\label{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}\index{numpp\+::differentiation\+::symbolic\+::differentiate$<$ Function, Order $>$@{numpp\+::differentiation\+::symbolic\+::differentiate$<$ Function, Order $>$}}

Allows differentiation of N-\/th order.

{\ttfamily \#include $<$functions.\+hpp$>$}

\subsection*{Public Types}
\begin{DoxyCompactItemize}
\item
\mbox{\Hypertarget{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_ac0c973a49c1b2e262edd5345c4f569a7}\label{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate_ac0c973a49c1b2e262edd5345c4f569a7}}
{\footnotesize template$<$std\+::size\+\_\+t Variable, std\+::size\+\_\+t... Variables$>$ }\\using {\bfseries with\+\_\+respect\+\_\+to} = typename \hyperlink{classnumpp_1_1differentiation_1_1symbolic_1_1differentiate}{differentiate}$<$ typename Function\+::template derivative$<$ Variable $>$, Order-\/1 $>$\+::template with\+\_\+respect\+\_\+to$<$ Variables... $>$
\end{DoxyCompactItemize}

\subsection{Detailed Description}
\subsubsection*{template$<$typename Function, std\+::size\+\_\+t Order$>$\newline
class numpp\+::differentiation\+::symbolic\+::differentiate$<$ Function, Order $>$}

Allows differentiation of N-\/th order.

\begin{DoxyTemplParams}{Template Parameters}
{\em Function} & Function which should be differentiated, see /ref numpp\+\_\+differentiation\+\_\+symbolic \char`\"{}tutorial\char`\"{} for more info \\
\hline
\end{DoxyTemplParams}

\begin{DoxyParams}{Parameters}
{\em Order} & order of the differentiation, e.\+g. 3 for 3rd order\\
\hline
\end{DoxyParams}

\begin{DoxyCode}
\textcolor{preprocessor}{#include"numpp/differentiation/symbolic.hpp"}
\end{DoxyCode}

The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item
differentiation/symbolic/functions.\+hpp\end{DoxyCompactItemize}