\documentclass [12pt] {article}
\usepackage{color}
\usepackage{listings}
\lstset{language=C++}
\definecolor{darkgray}{rgb}{0.95,0.95,0.95}
\lstset{numbers=left, numberstyle=\tiny, stepnumber=2, numbersep=5pt}
\lstset{keywordstyle=\color{red}\bfseries\emph}
\usepackage{verbatim}
\usepackage{amsmath}
\usepackage{graphicx}
\begin {document}

\title {CAAM 420 Daily Notes}
\author {Chris Nguyen}
\date {Dec 2, 2013}
\maketitle

\section{A control problem}
Since we are done with the major portion of the class, let us explore an example problem that requires a least-squares solution. Here, we introduce a mass-spring system which we can turn into a control problem (a quick Google search will give you the gist of what a control problem is).

\begin{figure}[!h]
\centering
\includegraphics[scale=0.75]{spring.png} 
\caption{Mass-spring system}
\end{figure}

Let:
\begin{align}
p &= \text{momentum of mass}
\\
m\frac{dx}{dt}&=p
\\
\frac{dp}{dt}&=-kx(t)+f
\end{align}

Our task is to choose $f(t), 0 \leq t \leq 1$, so that :
\begin{equation}
 |x(1)-x_{tgt}| \leq \epsilon
\end{equation}

Amongst all $\{f(t), 0 \leq t \leq 1\}$ that does this job, we want to find the one that minimizes:
\begin{equation}
 \int_{0}^{1}f^{2}(t)dt
\end{equation}

Note that this is a contrained problem. To solve the unconstrained problem, find $f$ that minimizes:
\begin{equation}
 |x(t)-x_{tgt}|^{2} + \lambda \int_{0}^{1}f^{2}(t)dt
\end{equation}
which involes the use of Lagrange multiplier theory

\section{Lagrange Multiplier Theory}
There is a $\lambda=\lambda(\epsilon)$ so that the minimizer of $J_{\lambda}(f)$ solves the control problem (with $|x(1)-x_{tgt}|=\epsilon$).
\\
Concentrate on minimizing $J_{\lambda}$:
\begin{align}
m\frac{dx}{dt}=p
\\
\frac{dp}{dt}=-kx+f
\end{align}
where $x(0)=p(0)=0$, which turns this into an initial value problem.

\section{Discretization via Euler's Method}
\begin{align}
\dfrac{dx(t)}{dt}\approx \dfrac{x(t+\Delta t)-x(t)}{\Delta t}
\end{align}
Choose $\Delta t=\frac{1}{N}$.
\\
Define:
\begin{align}
x_{i} \approx \dfrac{x(i\Delta t+\Delta t)-x(i\Delta t)}{\Delta t} = \dfrac{x_{i+1}-x{i}}{\Delta t}. 
\end{align}
Similarly, $p_{i} \approx p(i\Delta t)$ and $\dfrac{dp}{dt}(i \Delta t) \approx \dfrac{p_{i+1}-p_{i}}{\Delta t}$.
\\
Note by this convention: $f_{i}=f(i \Delta t)$.
\\
Putting it all together:
\begin{align}
m\dfrac{x_{i+1}-x{i}}{\Delta t}=p_{i}
\\
\dfrac{p_{i+1}-p_{i}}{\Delta t}=-kx_{i}+f_{i}
\end{align}
This is the discrete version of the mass-spring system. 
\\

An equivalent system is:
\begin{align}
x_{i+1}-x{i} -\dfrac{\Delta t}{m}p_{i}=0
\\
p_{i+1}-p_{i}+{\Delta t}kx_{i}=\Delta tf_{i}
\end{align}
where i=0,1,...,N.
\\
Turning this into a linear algebra problem:
\[ U^{2n+2} = \left( \begin{array}{c}
x_{0} \\
p_{0} \\
x_{1} \\
p_{1} \\
.\\
.\\
.\\
x_{N} \\
p_{N} \\
\end{array} \right)\] 
with:
\begin{align}
D_{2i+2j}&=(0...-1 \hspace{1mm} -\frac{\Delta t}{m} \hspace{1mm} 1 \hspace{1mm} 0....0) 
\\
D_{2i+3j}&=(0...\Delta tk \hspace{1mm} -1 \hspace{1mm} 0 \hspace{1mm} 1 \hspace{1mm} 0,...0)
\end{align}
Terms in the middle are at the 2i, 2i+1, 2i+2, and 2i+3 positions respectively.
\\
Note that 
\begin{align}
D_{0j}&=(1 \hspace{1mm} 0 \hspace{1mm} ... 0) \\
D_{1j}&=(0 \hspace{1mm} 1 \hspace{1mm} 0 ...0)
\end{align}

The system discretized with the Euler method is:
\[ DU = \left( \begin{array}{c}
0 \\
0 \\
.\\
.\\
.\\
\Delta f_{0}\\
0\\
\Delta t\\
0\\
.\\
.\\
.\\
\Delta tf_{n-1}
\end{array} \right) \] 
\\
where:
\begin{align}
x_{N} = BU \approx x(1) \\
B = (0 \hspace{1mm}... 0 \hspace{1mm} 1 \hspace{1mm} 0)\\
\end{align}
\[ f = \left( \begin{array}{c}
f_{0}\\
f_{1}\\
.\\
.\\
.\\
f_{N-1}
\end{array} \right) \] 

Mass-spring system: $DU=Cf$
\\
We must find f so that :
\begin{align}
J(f)  &=\frac{1}{2}\{|BU-x_{tgt}|^{2} + \lambda^{2}\Delta t \Sigma f_i \}\\
      &=\frac{1}{2}\{|BD^{-1}Cf-x_{tgt}|^{2} + \lambda^{2}\Delta tf \}
\end{align}



\end{document}
