\section{Physics of  Neutron Stars (NS)}

\begin{frame}
\begin{center}

	{\bf  ANALYTIC EQUATION OF STATE}
\end{center}

\end{frame}

\subsection*{Neutron Stars Overview}
\begin{frame}
\frametitle{Neutron Stars Overview}
\begin{columns}[c]
\begin{column}{0.65\textwidth}
\begin{enumerate}
\scriptsize{
 \item Objects with {\bf most extreme densities ($\rho$)}  and {\bf strongest magnetic field (B)}.

 \quad

 \item  {\bf Energetically favorable} for protons and electrons to form {\bf free neutrons}, generating the {\bf degeneracy pressure}.\\ {\tiny (but core exhibits collective behavior of particles)}
% Free neutrons normally $\beta$ decay in $\sim 15$ minutes, but at sufficient depths in the NS the decay reaction is suppressed as the Fermi energy becomes too high to be populated by the electrons which would be created in the decay.

 \quad

\item Observations of NSs constrain the physics of their {\bf interiors}:
\begin{itemize}\scriptsize{
 \item {\bf low temperatures},
 \item $\rho \gg$ {\bf  nuclear saturation density}. \\{\tiny ($\rho_s \sim 2.7 \times 10^{14}$ g cm$^{-3})$}}
\end{itemize}

  \quad

 \item {\bf Photons emitted} from the NS {\bf surface} are direct probes of their {\bf structure, composition, and magnetic field}.

 \quad

 \item Determining the {\bf EoS} of this {\bf cold ultradense matter} is a {\bf challenge} of high-energy and nuclear astrophysics!

 }

\end{enumerate}
\end{column}
\begin{column}{0.5\textwidth}
 \center{\tiny QCD phase diagram:\\
 \includegraphics[scale=0.2]{figs/phasetran.png}\\
 High-density/low T region is inaccessible to terrestrial \\experiments (Paerels et al, 2009).}
\end{column}
\end{columns}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection*{Neutron Star Radii and Compactness}
\begin{frame}
\frametitle{Neutron Star Radii and Compactness}

\begin{columns}[c]
\begin{column}{0.55\textwidth}

\begin{itemize}
\scriptsize{
\item  {\bf NS EoS} is hard to be obtained from first principles.

\quad

 \item Matter that can only be probed through astrophysical observations of {\bf mass} and {\bf radius} with {\bf sufficient precision}!  \\{\tiny (Lattimer $\&$ Prakash , 2007)}

 \quad

\item Unique map between microscopic {\bf (P-$\rho$)} and macroscopic {\bf(M-R)}.

\quad

\item For instance, $M_{NS}=1.4 M_{\odot}$ gives determination of pressure at $2 \rho_s$.\\ {\tiny (Lattimer $\&$ Prakash , 2011)}
}

\end{itemize}
\end{column}

\begin{column}{0.6\textwidth}
 \center{\includegraphics[scale=0.2]{figs/oz.png}}\\
	{\tiny {\bf Mass-radius relations for a selection of NS EoS}: \\{\bf APR} (Akmal et al., 1998), {\bf MS} (M\"uller \& Serot, 1996), {\bf GS} (Glendenning \& Schaffner-Bielich, 1999), {\bf  ABPR }(Alford et al., 2005),  {\bf BBB} (Brueckner-Hartree-Fock model), {\bf SQM }(Prakash et al., 1995).}
 \end{column}
 \end{columns}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection*{How to Obtain R and M?}
\begin{frame}
\frametitle{Some Initial Quantities to infer (M,R)}

\begin{columns}[c]
\begin{column}{0.6\textwidth}

\begin{enumerate}\scriptsize{
\item Observational appearance of NS affected by {\bf redshift and lensing effects}.

\quad

\item The {\bf redshift} is
$$1+z = |g_{tt}|^{-1/2} = \Big(1 - \frac{2GM}{Rc^2} \Big)^{-1/2}.$$

\item The apparent radius at some distance $D$ is then
$$R_{\infty} = R \Big( 1 - \frac{2GM}{Rc^2}\Big)^{-1/2}.$$

%\item (M-R) relation are given by $R = R_{\infty} (1 + z) -1 ,$
%$M = R_{\infty} c^2 (1 + z)-1= [1 - (1 + z)^{-2} ]/2G.$

\item {\bf Lensing} from a {\bf strong gravitational field} gives an area which  appears to be large by
$$\frac{S_{\infty}}{4\pi R^2} = (1+z)^2.$$

}
\seti
\end{enumerate}
\end{column}
\begin{column}{0.6\textwidth}
\begin{enumerate}\scriptsize{
\conti

%\item The {\bf  Eddington luminosity at infinity } is:
%$L_{E,\infty} = \frac{8\pi m_pc}{(1+X)\sigma_T} \Big (1 - \frac{2GM}{Rc^2} \Big)^{1/2}.$

\item The {\bf  total flux } observed at distance $D$ is
$$F_{\infty} = \sigma_B T^4_{eff,\infty} \Big ( \frac{R}{D} \Big)^2 (1+z)^2.$$

\item  Uncertainties given by:
\begin{itemize}\scriptsize{
 \item {\bf distance} ($R_{\infty} \propto D$),
 \item  {\bf interstellar H absorption},
 \item and {\bf atmospheric composition}. }
\end{itemize}

\quad

\item {\bf Best probes}:
\begin{itemize}\scriptsize{
 \item nearby isolated NS (parallax measurable),
 \item and X-ray binaries in globular clusters.
}\end{itemize}

}
\end{enumerate}
 \end{column}
 \end{columns}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection*{Energy Sources in Neutron Stars}

\begin{frame}
\frametitle{Energy Sources in Neutron Stars:}
\begin{enumerate}
 \item Radiation of Residual Heat in Young NSs.

 \quad

 \item Re-radiation of deposition heat between accretion episodes.

 \quad

 \item Magnetic Field Decay.

 \quad

 \item Particle Bombardment onto Polar Caps.

  \quad

 \item {\bf Thermonuclear Bursts}.

\end{enumerate}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%555

\section{Physics of NS Surface Emission}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{frame}
\begin{center}

	{\bf  OBSERVATIONAL ASTROPHYSICS}
\end{center}

\end{frame}

\subsection*{Observing Neutron Stars and their Surfaces}

\begin{frame}
\frametitle{Observing Neutron Stars and their Surfaces}

\begin{columns}[c]
\begin{column}{0.55\textwidth}
	{\bf \center We probe NSs from:}{\scriptsize
	 \begin{enumerate}
	     \item Dynamics of {\bf binary systems}.
	     \item Structure and energetics of {\bf radio pulse sources}.
	     \item {\bf Spectra and variability} of their high energy radiation.
	     \item {\bf Direct observations} of the {\bf  surface emission} (often hidden from view).
	     	    \end{enumerate}
}
\end{column}
\begin{column}{0.55\textwidth}
{\bf \center We see evidences of NS surface emission from:}
\begin{itemize}\scriptsize{
		 \item {\bf Thermonuclear bursters from (LMXB)}.
		 \item {\bf Accreting sources during quiescence}. {\tiny
		 \item Isolated cooling NS (DINS), central compact objects (CCO).
		 \item Pulsating sources in radio (PSR).
		 \item Accretion powered pulsars (AMSP) and accreting millisecond X-ray pulsars (MSP), Soft gamma-ray repeaters(SGR), anomalous X-ray pulsars (AXP).}}
	  \end{itemize}
	  \end{column}
\end{columns}
 \center{\includegraphics[scale=0.19]{figs/all.png}}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection*{Neutron Star Sources with Surface Emission}
\begin{frame}
\frametitle{Neutron Star Sources with Surface Emission}
\center{ {\bf Surface emission}  detected in many NS sources, with {\bf thermal spectra from optical to X-rays}: }

\begin{columns}[c]
\begin{column}{0.5\textwidth}
 \scriptsize{
 \item {\bf Accreting NS in quiescence:} \\

 \quad

 \begin{itemize}\scriptsize{
 \item  Half of NS accreting from low-mass companion have X-ray transients.

 \quad

  \item {\bf X-rays transients} have several different accretion phases, varying flux level and spectral characteristics.

  \quad

  \item {\bf Outburst luminosity} $\sim 10^{36-38}$ erg s$^{-1}$, same order of their {\bf quiescent luminosity}.}
 \end{itemize}}

\end{column}
\begin{column}{0.65\textwidth}

 \scriptsize{

\item {\bf Accreting Bursting NS (from LMXB):}\\

\quad

\begin{itemize}\scriptsize{

\item 100 of $\sim$ 150 exhibit thermonuclear bursts, with X-ray flux rising $\sim 10-100$ s.

\quad

 \item Due to {\bf unstable burning of He/H}, {\bf accreted} to the NS surface from companion.

 \quad

 \item  {\bf Evolution of the color temperature} in the burst: dip in the {\bf T} rises {\bf photospheric radius expansion} (PRE).

 }

\end{itemize}
}

\end{column}
\end{columns}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection*{Type I X-Ray Bursters and LMXBs  }
\begin{frame}
\frametitle{Type I X-Ray Bursters and LMXBs}

\begin{columns}[c]
\begin{column}{0.6\textwidth}
\begin{enumerate}\scriptsize{
\item {\bf X-ray bursters} (XRB) are periodic and rapid increases in luminosity in the X-ray range.

\quad

\item XRB are composed of {\bf an accreting compact object} (NS) and a {\bf companion}, whose mass categorizes the system:
\begin{itemize}\scriptsize{
 \item High mass ($M > 10 M_{\odot}$), {\bf (HMXB)}.
 \item Low mass ($M < 1 M_{\odot}$), {\bf (LMXB)}.}
\end{itemize}

\quad

\item {\bf Low mass X-ray Bursters} (LMXB) are {\bf thermonuclear} XRB that can put constraints on the NS EoS.

\quad

 \item For instance, observations of {\bf NS during thermonuclear bursts} have led to the {\bf  first constraining measurements of NS radii}: \\9 km $<$ R $<$ 12 km. \\{\tiny (Lattimer $\&$ Brown, 2010)}

}
\end{enumerate}
\end{column}
\begin{column}{0.55\textwidth}

  \center{\includegraphics[scale=0.33]{figs/xx.png}}
\end{column}
\end{columns}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection*{Photospheric Radius Expansion (PRE) Bursts}
\begin{frame}
\frametitle{Photospheric Radius Expansion (PRE)}

\begin{columns}[c]
\begin{column}{0.55\textwidth}

\begin{enumerate}
\scriptsize{
 \item  NS Observations are from the outermost layer of surface, the {\bf photosphere}, in radioactive equilibrium given by a flux
$F=\sigma_B T^4_{eff}.$

 \quad

\item {\bf PRE bursts} are a {\bf bright} subset of TB where  at the so-called {\bf touchdown point} (where the {\bf photosphere} returns to the NS radius), fluxes are close to $L_{Edd} = 4 \pi R^2 \sigma_T T^4_{eff}.$ on the surface.

\quad

\item  $F_{Edd}$ can be related to the {\bf normalization of the burst spectrum} (blackbody normalization, $K$),  which gives the  {\bf emitting area} (R):

$$F_{Edd} = F_{touchdown} = \frac{GMc}{\kappa D^2} \Big ( 1 - \frac{2GM}{Rc^2} \Big)^{1/2},$$
$$ A = \frac{R^2}{D^2f_c^4} \Big( 1 - \frac{2GM}{Rc^2} \Big )^{-1} = f_c  K^{1/4},$$
 $f_c$ the color correction factor.

 }
  \end{enumerate}

\end{column}
\begin{column}{0.7\textwidth}
\begin{center}
\scriptsize{
Debate about {\bf systematic errors} that must be taken\\ into account ({\bf where is the touchdown?}). }
\\{\tiny (Suleimanov et al. 2011a; Guver, Ozel $\&$ Psaltis 2011)}

\quad

\includegraphics[scale=0.45]{figs/pree.png}
\end{center}

\quad
  \end{column}
\end{columns}
   \end{frame}

\begin{frame}
\begin{center}

	{\bf  COMPUTATIONAL SIMULATIONS\\ AND FITTINGS}
\end{center}

\end{frame}

\section{Modeling NS Atmospheres}

\subsection*{Parameters for Modeling Neutron Star Atmospheres}

\begin{frame}
\frametitle{Parameters for Modeling Neutron Star Atmospheres}

\begin{center}

	Detailed {\bf Models of NS atmospheres} shape the {\bf spectrum } and {\bf pattern of radiation} from {\bf crust and core}.

\end{center}

	\begin{itemize}

	\item
Assumptions:
\begin{enumerate}
 \item {\bf Plane-parallel} geometry.
 \item {\bf Radioactive equilibrium}.
 \item {\bf Hydrostatic equilibrium}.
\end{enumerate}
\quad

	 \item The {\bf four parameters} in the models are:
	   \begin{enumerate}
	    \item Magnetic field strengths;
	    \item Chemical Compositions (e.g. H fraction, $X$);
	    \item Temperature at surface, $T_{eff}$;
	    \item Gravitational acceleration at surface, $g$.
	   \end{enumerate}
	\end{itemize}
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection*{Modeling the Spectrum of the  NS Surface Emission}

\begin{frame}
\frametitle{Some Results on Modeling and Fitting Spectra}
\begin{columns}[c]
\begin{column}{0.7\textwidth}
\begin{enumerate}
\scriptsize{
\item Many different {\bf physical conditions}: {\tiny ( Suleimanov et al, 211)}
\begin{itemize}\scriptsize{
 \item 6 different {\bf chemical compositions} (pure H, pure He, solar mix, heavy elements).
 \item 3 values of {\bf surface gravities}.
 \item 20 values of {\bf luminosities} in units $l = L/L_{Edd}$.}
\end{itemize}

\quad

\item {\bf NS spectra} look like blackbody, but shifted to higher temperatures by the {\bf color coefficient factor}:
$$f_c = \frac{T_{BB}}{T_{eff}} = K^{-1/4}A $$

\item Fitting $f_cT_{eff}-l$ to the $K^{-1/4}-F_{\infty}$ on cooling LXRB  at some $D$, gives $$R_{\infty}=R(1+z)=R_{BB} f_c^2.$$

\quad

\item {\bf Others processes considered}: angular redistribution in scattering, electron conduction, {\bf Compton scattering}...
}
\end{enumerate}
\end{column}
\begin{column}{0.5\textwidth}

 \center{\includegraphics[scale=0.23]{figs/atms.png}}\\
 {\tiny Model spectra for four different types of NS, $H_E=4\pi H_E$: non-magnetic cool NS, cool with moderate B, hot bursting with mentalities, strong B with H.}

 \end{column}
 \end{columns}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection*{Some Results on Modeling and Fitting Spectra}

\begin{frame}
\frametitle{Results on Modeling and Fitting NS Spectra}
\begin{columns}[c]
\begin{column}{0.55\textwidth}
 \center{\includegraphics[scale=0.3]{figs/qqq.png}}\\
 {\tiny (Suleimanov et al, 2011)}\\

\end{column}
\begin{column}{0.55\textwidth}
 \center{\includegraphics[scale=0.3]{figs/meu.png}}
  {\tiny (October/2012)}
 \end{column}
 \end{columns}

\end{frame}

\begin{frame}
\begin{center}

	{\bf  OUTLOOK}
\end{center}

\end{frame}


\chapter{Background and Related Work}

\section{Common Terminology}
Before detailing the background relating to ASP \cite{Lifschitz1999}, a list of common terms that will be used throughout can be found in Table \ref{table:4}.

\begin{table}[p!]
\centering
\makeatletter
\@fpsep\textheight
\makeatother
\begin{tabular}{| c | m{0.7\linewidth} |}
\hline
Constant &
\mbox{}\newline
A sequence of characters starting with a lower case character or number. Typically denoted \lstinline!a, b, c, ... p, q, r, ...!. \newline
\\
\hline
Variable &
\mbox{}\newline
A character or sequence of characters starting with an upper case letter, representing some range of possible constants. Typically denoted \lstinline!A, B, C, ... X, Y, Z, ...!.\newline
\\
\hline
Term &
\mbox{}\newline
Either a constant or a variable \newline
\\
\hline
Predicate &
\mbox{}\newline
A character or sequence of characters representing some relation between Constants or Variables. For example, the predicate \lstinline!on, above, below!. \newline
 \\
\hline
Atom &
\mbox{}\newline
A predicate applied to some terms. \lstinline!on(X, Y), above(a, b), p(X), q(Z)! are all examples of atoms.\newline
 \\
\hline
Literal &
\mbox{}\newline
Either an Atom or an Atom preceded by the \lstinline!not! operator, representing Negation By Failure. \newline
\\
\hline
Rule &
\mbox{}\newline
A line of the form \lstinline!head :- body! where \lstinline!head! is an atom and \lstinline!body! is a list of literals.
\newline
 \\
\hline
Program &
\mbox{}\newline
A conjunction of rules \newline
\\
\hline
\end{tabular}
\caption{Common Logic Terms \cite{Muggleton1991}}
\label{table:4}
\clearpage
\end{table}

\section{Answer Set Programming}

\subsection{Negation As Failure}
Negation as failure is an inference rule used in non-monotonic logic programs to derive atoms of the form \lstinline!not p!. This derivation is defined as
\begin{displayquote}
``\lstinline!not p! can be inferred if every possible proof of \lstinline!p! fails.'' \cite{negAsFailure}
\end{displayquote}
In more simple terms, this means that you can assume that \lstinline!not p! holds if you cannot prove \lstinline!p!.
As an example, consider the program \\

\begin{lstlisting}
p :- not q.
q :- r.
\end{lstlisting}
\mbox{}\\
As \lstinline!q! cannot be proven, we can instead prove \lstinline!not q!, which is then used to prove \lstinline!p!.

\subsection{The Stable Model Semantics}

The Stable Model Semantics \cite{KRnotes} provides a natural semantics for both normal and extended logic programs, in which instead of giving individual solutions to queries we define a set of ``Answer Sets'' (Stable Models) of the program. For example, given the program: \\

\begin{lstlisting}
p :- not q.
q :- not p.
\end{lstlisting}
\mbox{}\\
The value of p depends on the value of q, so when you query Prolog for p? this program results in an infinite search, alternately searching for p and q until cancelled. However, using the Stable Model Semantics, this particular program has an answer set for each solution : \lstinline!{p}! and \lstinline!{q}!.

\subsubsection{Grounding}

Before you can solve a logic program using Answer Sets you must first ground it \cite{KRnotes}. A rule is said to be ``ground'' if all of its variables are replaced by every combination of possible constants. Then, to calculate the grounding of a program P you replace each rule in P by every ground instance of that rule. For example, the program \\

\begin{lstlisting}
p(1, 2).
q(X) :- p(X, Y), not q(Y).
\end{lstlisting}
\mbox{}\\
has grounding \\

\begin{lstlisting}
p(1,2).
q(1) :- p(1, 1), not q(1).
q(1) :- p(1, 2), not q(2).
q(2) :- p(2, 1), not q(1).
q(2) :- p(2, 2), not q(2).
\end{lstlisting}
\mbox{}\\
This is calculated as the grounding for this program, because the variables \lstinline{(X, Y)} in the rule \lstinline{q(X) :- p(X, Y), not q(Y).} are replaced by all possible combinations of the constants \lstinline{(1, 2)}. These combinations are, specifically :\\%{

\begin{lstlisting}
{ X = 1, Y = 1 }
{ X = 1, Y = 2 }
{ X = 2, Y = 1 }
{ X = 2, Y = 2 }
\end{lstlisting}

\subsubsection{Safety}

Because of the need for ASP solvers to ground the entire program, they are restricted to safe rules \cite{Cabalar2009}. A rule is safe if every variable in that rule occurs positively in the body of the rule. Some examples of unsafe rules are:

\begin{itemize}
\item \lstinline!p(X) :- q(Y).! Unsafe because the variable \lstinline!X! does not appear in the body.
\item \lstinline!p(Z) :- not q(X, Y), r(X, Y).! Unsafe because the variable \lstinline!Z! does not appear the body of the rule.
\item \lstinline!p(X) :- q(X), not r(Y).! Unsafe because the variable \lstinline!Y! does not appear positively in the body.
\end{itemize}

\pagebreak

\subsubsection{Least Herbrand Models}
For a normal logic program P, the following features are defined as follows \cite{KRnotes} :

\begin{center}
\begin{tabular}{| c | m{0.7\linewidth} |}
\hline
Herbrand Base &
\mbox{}\newline
The set of all ground atoms of a program.\newline
\\
\hline
Herbrand Interpretation &
\mbox{}\newline
An assignment on the Herbrand Base, specifying which ground atoms are true and which are false.\newline \newline
A rule is satisfied by an interpretation if, when all atoms of the body are specified as true in the interpretation, then so is the head of the rule.\newline
\\
\hline
Herbrand Model &
\mbox{}\newline
A Herbrand Interpretation where every rule in the program is satisfied by that interpretation.\newline \newline
A Herbrand Model M is minimal if no subset of M is also a model. For definite logic programs this model is unique and called the Least Herbrand Model, however this does not always hold for normal or extended logic programs.\newline
\\
\hline
\end{tabular}
\end{center}
\mbox{}\\
For example, consider the program P:\\

\begin{lstlisting}
p :- not q.
q :- not p.
\end{lstlisting}
\mbox{}\\
P has the Herbrand Base \lstinline!{p, q}!. \\ \\
Because listing if each atom is true or false is overly verbose, instead we write the Herbrand Interpretation as a set of atoms, only including the ones specified as true. One Herbrand Interpretation of P is \lstinline!{p, q}!, but this interpretation is not a model because neither rules are satisfied by it. \\ \\
The Herbrand Interpretations \lstinline!{p}! and \lstinline!{q}! are both Herbrand Models. \lstinline!{p}! is a model because it satisfies the both rules - the first as \lstinline!not q! holds by NBF and \lstinline!p! is in the model, and the second as \lstinline!(not p)! does not hold so \lstinline!q! is not needed. \lstinline!{q}! is a Herbrand Model for the same reasons, reversed. The first line is satisfied because the body \lstinline!not q! does not hold, and the second line is satisfied as \lstinline!not p! holds, and \lstinline!q! is in the interpretation.

\subsection{Calculating Answer Sets}

\subsubsection{Reduct}

Let P be a ground normal logic program, and X be a set of atoms. The reduct \cite{Law2015} of P, P\textsuperscript{X} is calculated from P by :

\begin{enumerate}
\item Delete any rule from P which contains the negation as failure of an atom in X.
\item Delete any negation as failure atoms from the remaining rules in P.
\end{enumerate}
We then say X is an Answer Set (Stable Model) of P if it is a least Herbrand Model of  P\textsuperscript{X}. For example, if program P is:\\

\begin{lstlisting}
p(1, 2).
q(1) :- p(1, 1), not q(1).
q(1) :- p(1, 2), not q(2).
q(2) :- p(2, 1), not q(1).
q(2) :- p(2, 2), not q(2).
\end{lstlisting}
\mbox{}\\
First, try X = \lstinline!{q(1)}!. The reduct is calculated as : \\

\begin{lstlisting}
p(1, 2).
q(1) :- p(1, 2).
q(2) :- p(2, 2).
\end{lstlisting}
\mbox{}\\
The Least Herbrand Model of this reduct is \lstinline!{p(1, 2), q(1)}!. Therefore X is not an Answer Set of P. \\ \\
Then, when trying X = \lstinline!{p(1,2), q(1)}!, the reduct is:\\

\begin{lstlisting}
p(1, 2).
q(1) :- p(1, 2).
q(2) :- p(2, 2).
\end{lstlisting}
\mbox{}\\
A Least Herbrand Model M(P\textsuperscript{X}) = \{p(1,2), q(1)\}, so X is an Answer Set of P. \\ \\
It is important to note that Answer Sets are not unique and some programs might have no Answer Sets.

\subsubsection{Constraints}

Constraints \cite{ASPnotes} are a way of filtering out unwanted Answer Sets. They are written as rules with an empty head, which is equivalent to $\bot$. Semantically, this means that any model which satisfies the body of the constraint cannot be an Answer Set. For example, the program with constraint : \\

\begin{lstlisting}
p :- not q.
q :- not p.
:- p, not q.
\end{lstlisting}
\mbox{}\\
Has only one Answer Set, \lstinline!{q}!. This is because the Answer Set \lstinline!{p}! fails the constraint, as it contains \lstinline!p! and does not contain \lstinline!q!.

\subsubsection{Aggregates and Choice Rules}

An aggregate \cite{Eiter2008} is a ASP atom with the format $a \: \textsf{op} \: [h_1=w_1, h_2=w_2, \dots, h_n=w_n 	] \: b$, where $a$ and $b$ are bounds on the aggregate, $h_1, h_2, \dots, h_n$ are literals and $w_1, w_2, \dots, w_n$ are weights assigned to those literals. An aggregate is satisfied by an interpretation X if operation \lstinline!op! applied to the multiset of weights of true literals is between the upper and lower bounds $a$ and $b$. \\ \\
This project will be using one application of aggregates, the choice rule. A choice rule has an aggregate using the count operation as the head of the rule, and semantically represents a choice of a number of head atoms, between the upper and lower bound. For example, the choice rule \lstinline!1 { on(A, B), on(B, A) } 1.! represents \lstinline!A! can be on \lstinline!B!, or \lstinline!B! can be on \lstinline!A!, but not both. \\ \\
To calculate the Answer Sets of a program P which contains aggregates by adding an additional step to the construction of the reduct. For each rule with an aggregate:

\begin{enumerate}
\item If the aggregate is not satisfied by X then convert the rule into a constraint by removing the aggregate, replacing it with $\bot$.
\item If the aggregate is satisfied by X then generate one rule for each atom A in the aggregate which is also in X, with A as the head.
\end{enumerate}
\mbox{}\\
For example, consider program P with X = \lstinline!{p, q, r}!:\\

\begin{lstlisting}
1 {p, q} 2 :- r.
r.
\end{lstlisting}
\mbox{}\\
The reduct is then \\

\begin{lstlisting}
p :- r.
q :- r.
r.
\end{lstlisting}

\subsubsection{Optimisation Statements}

An Optimisation Statement \cite{Eiter2008} is an ASP atom of the form $ \#op \: [l_1 = w_1, l_2 = w_2, \dots, l_n = w_n]$, where $\#op$ is either $\#maximise$ or $\#minimise$, and each $l_n$ is a ground literal assigned a weight $w_n$. They allow for an ASP solver to search for optimal Answer Sets which maximise or minimise the sum of the atoms with regards to their weights. For instance, \\

\begin{lstlisting}
p :- not q.
q :- not p.
#minimise [p = 1, q = 2].
\end{lstlisting}
\mbox{}\\
Has one optimal answer set, \lstinline!{p}!, with optimisation 1.

\subsection{ASPAL}

ASPAL \cite{Corapi2012} is an ASP algorithm which computes the solution of an inductive task by encoding it as an ASP program which has the solutions as the Answer Sets of the program.\\ \\
First, we encode the Hypothesis Space by generating a number of Skeleton Rules. Each skeleton rule represents a possible rule in the Hypothesis (with constant terms replaced with variables), together with an identifier. The atom rule(ID, $c_1, \dots, c_n$) represents the choice of skeleton rule with ID and the constant variables replaced by various $c_n$. The goal of the task is to find these rule atoms.\\ \\
These skeleton rules are defined by ``mode declarations'', terms which specify which rules are allowed to appear in the heads of rules, and which are allowed to appear in the bodies. The predicate \lstinline!modeh! specifies the head declaration, while \lstinline!modeb! specifies the body. \\ \\
We next rule out Answer Sets which do not fit the examples by adding a goal rule and a constraint, of the format (where $e_1^+, \dots, e_n^+$ are the positive examples and $e_1^-, \dots, e_n^+-$ are the negative examples) : \\

\begin{lstlisting}[mathescape=true]
goal :- $e_1^+, \dots, e_n^+, \: \textsf{not} \: e_1^-, \dots, \: \textsf{not} \: e_n^-$
:- not goal.
\end{lstlisting}
\mbox{}\\
This rules out any answer set which does not contain all of the positive examples and contains any negative examples. \\ \\
We then make sure the Answer Sets of the program correspond to the optimal solutions of the task by adding an optimisation statement \\

\begin{lstlisting}[mathescape=true]
#minimise [rule(ID, $c_1, \dots, c_n$) = ruleLength, $\dots$].
\end{lstlisting}
\mbox{}\\
where there is a rule predicate for each skeleton rule, weighted by the length of that rule.\\ \\
As an example of the entire ASPAL encoding, consider the program :

\begin{lstlisting}
box(a).				box(b).
colour(red).		colour(blue).
has_colour(a, red).	has_colour(b, blue).
\end{lstlisting}
\mbox{}\\
With mode declarations \\

\begin{lstlisting}
modeh(on_floor(+box)).
modeb(has_colour(+box, #colour)).
modeb(not has_colour(+box, #colour)).
\end{lstlisting}
\mbox{}\\
And examples $E^+$ = \lstinline!{on_floor(a)}! and $E^-$ = \lstinline!{on_floor(b)}!. \\ \\
From these examples, the goal statement is generated. \\

\begin{lstlisting}
goal :- on_floor(a), not on_floor(b).
:- not goal.
\end{lstlisting}
\mbox{}\\
The mode declaration generated the skeleton rules \\

\begin{lstlisting}
on_floor(A) :- box(A), rule(1).
on_floor(A) :- box(A), has_colour(A, C1), rule(2, C1).
on_floor(A) :- box(A), not has_colour(A, C1), rule(3, C1).
\end{lstlisting}
\mbox{}\\
These parts, combined with a choice rule and optimisation statement give the overall encoding:\\

\begin{lstlisting}
has_colour(a, red).
has_colour(b, blue).
box(a).
box(b).
colour(red).
colour(blue).

goal :- on_floor(a), not on_floor(b).
:- not goal.

on_floor(A) :- box(A), rule(1).
on_floor(A) :- box(A), has_colour(A, C1), rule(2, C1).
on_floor(A) :- box(A), not has_colour(A, C1), rule(3, C1).

{rule(1), rule(2, red), rule(2, blue), rule(3, red), rule(3, blue)}.

#minimise[rule(1) = 1, rule(2, red) = 2, rule(2, blue) = 2, rule(3, red) = 2, rule(3, blue) = 2].
\end{lstlisting}
\mbox{}\\
When ran (using the ASP solver clingo \cite{Gebser2007}), the Answer Set of this program contains the atom \lstinline!rule(2, red)!. This rule corresponds to the learned skeleton rule \lstinline!on_floor(A) :- box(A), has_colour(A, red)!, which is stating that a box is on the floor if it is red, which is consistent with the examples.

\subsection{ASP Solvers}

Typically, ASP solvers work in two parts.

\begin{itemize}
\item First, the input program must be converted into the ground finite logic program by a grounder. Typically this step also includes optimisations to help the solver.
\item The ground program is then passed into the solver which calculates the Answer Sets of the program.
\end{itemize}
\mbox{}\\
The main popular ASP solvers are Smodels, DLV and Clasp. Clasp \cite{Gebser2007} is the ASP solver which I will be using to run my learning tasks as part of this project. It consists of three programs : The grounder \textit{gringo}, the ASP solver \textit{clasp} and the utility \textit{clingo} which combines the two.\\ \\
Gringo calculates the ground logic program by replacing the variables in the program by ground terms. The resulting program needs only be an equivalent program (meaning it has the same Answer Sets), to be able to deal with programs with infinite number of Answer Sets.

\section{The Target Language, Haskell}
Haskell \cite{Hudak2007} is a purely functional programming language, featuring a strongly typed static type system and supporting language features such as pattern matching, list comprehension, higher order functions and monads. In this section I will detail the Haskell language features relevant to this project. \\ \\
Functional programming is a programming paradigm that considers the evaluation of a computational function in the same way as a mathematical one. Functional programs are stateless, depending purely on the arguments to the function. By removing side-effects, it can be proven that a call to some function \lstinline!f! will always return the same result as long as the input arguments are the same \cite{Company2008}. Functional programming is also very similar semantically to logic programming, which makes using a form of programming like ASP to learn it more appealing over other paradigms.

\subsection{The Haskell Syntax}
To illustrate the syntax of Haskell programs, I will give an example of a function written in Haskell.

\begin{lstlisting}[language = Haskell]
factorial n
  | n == 0     = 1
  | otherwise = n * factorial (n - 1)
\end{lstlisting}
\mbox{} \\
The first line of the file defines the function name and any arguments it takes. In the above example, there is one argument, \lstinline!n!. \\ \\
Then, every other line starts with a ``guard'' statement. This statement defines when the expression after the \lstinline!=! should be executed. In the example, the guard statement \lstinline! | n == 0! holds when the input is 0, and the \lstinline! | otherwise! statement is a catch-all for all other cases. \\ \\
The other important syntax feature is \lstinline!where! statements, which allows for variable substitution. For example, the program \\

\begin{lstlisting}[language = Haskell]
f x = x * y
	where y = 5
\end{lstlisting}
\mbox{}\\
This program simply multiplies by 5, as the variable \lstinline!y! has value 5 and is substituted in.

\section{Related Work}

\subsection{Inductive Functional Programming}

Inductive Functional Programming (IFP) \cite{IFPnotes} is a specific field of program synthesis, focusing on the generation of Functional programs. Traditionally, there have been two approaches to IFP \cite{Katayama2012}. The analytical approach performs pattern matching on the given examples, usually performing a two-step process of first generalising the examples and then folding this generalisation into a recursive program. The "generate and test" search approach works by generating an infinite stream of candidate programs and then testing these candidates to see if they correctly model the examples. \\ \\
Each approach has its own advantages and disadvantages. The analytical approach, while fast, can be very limited in its target language and the types of programs it can generate, typically being limited to reasoning about data structures such as lists or trees. On the other hand, the search based approach is a lot less restricted but has worse performance due to the potentially huge search space. This issue is minimised by various optimisations performed on the generated programs, typically using a subset of the examples as an initial starting point.

\subsection{Conditional Constructor Systems}

Programs are represented in a functional style as a \textit{term rewriting system} \cite{Kitzelmann2006}, i.e a set of rules of the form $l \rightarrow r$. The LHS of the rule, $l$, has the format $F(a_1, \dots, a_n)$ where $F$ is a user-defined function and $a_1$ to $a_n$ are variables or pre-defined data type functions(constructors). In addition, rules must be \textit{bound}, meaning that all variables that appear on the right hand side of a rule must also appear on the left hand side.\\ \\
We can also extend these rules with conditionals, which must be met if the given rule is to be applied. Conditionals are of the form $l \rightarrow r \Leftarrow v_1 = u_1, \dots, v_n = u_n$, where each $v_n = u_n$ is an \textit{equality constraint} which has to hold for the rule to be applied. \\ \\
Using this definition we can begin to learn TRS. We take the sets of positive and negative examples ($E^+$ and $E^-$), written as sets of input/output examples in the form of unconditional re-write rules, and a \textit{background knowledge} $BK$ which is a set of additional re-write used to help computation. \\ \\
The goal of the learning task is then to a finite set of rewrite rules $R$ such that:

\begin{itemize}
\item $R \cup BK \models E^+$ (covers all of the positive examples).
\item $R \cup BK \not \models E^-$ (covers none of the negative examples).
\end{itemize}
Because the target domain of this task is often very large, two extra constraints are added to the type of rule we are allowed to learn.\\ \\
Restriction Bias is similar to the language bias typically found in ILP systems, and restricts the format of the learned rules and conditionals, for example to avoid mutual recursion. \\ \\
Preference Bias introduces an idea of optimisation to the task such that the learned rules are optimal while also satisfying the examples. Some such optimisations are preference to shorter right hand sides or preference to as few rules as possible.

\subsection{Overview of current tools}

Here I will discuss some modern program synthesis systems, giving some context to the field.

\subsubsection{MagicHaskeller}
MagicHaskeller \cite{Katayama2012} is based on the generate and test approach to IFP, and works by generating a stream of progressively more complicated programs and then testing them against the given specification. This search is exhaustive and performed in a breadth-first manner. It is made more efficient through smart restrictions of target programs based on the type of the input examples, and through heavy use of in built functions, both linear and higher order. \\ \\
MagicHaskeller has the advantage of being easy to use as you only have to give the specification of the desired function as an argument, which is typically no more than a few lines of code in the target language. The tool also has a particularly large component library of built-in Haskell primitives which the tool uses where possible.\\ \\
However, MagicHaskeller does not have the ability to compute large programs, due to the performance cost of exhaustive breadth-first search. This problem, however, is typical of the generate and test approach.

\begin{figure}[h!]
\centering
\includegraphics[width=\textwidth]{C7/magichaskeller.png}
\caption{The MagicHaskeller UI}
\label{fig:magichaskeller}
\end{figure}

\subsubsection{Igor II}
Igor II \cite{Kitzelmann2006} is based on the analytical approach to IFP and is specialised towards learning recursive programs. It works by first calculating the \textit{least-general generalisation} of the examples, which extracts terms which are common between the examples and terms which are uncommon are represented as variables. If this initial hypothesis is incomplete (i.e not a correct functional program) then four refinement operators are applied to attempt to complete it:
\begin{enumerate}
\item Partition the examples into two subsets and generate a new, more specific least general generalisation for each subset. This partition is calculated using pattern matching on the variables from the lhs of the initial hypothesis.
\item If the rhs of the initial hypothesis has a function as its root element then each unbound argument of this function is treated as a subproblem, and new functions are introduced for each argument.
\item The rhs of the initial hypothesis may be replaced by a recursive call to a user-defined function, where the arguments of this call are newly introduced functions.
\item If the examples match certain properties then a higher order function may be introduced, and synthesising the arguments to this function becomes the new induction problem.
\end{enumerate}
Igor II has a number of limitations. If there are a large number of examples then performance can be impacted because of the large number of combinations when matching to a defined function. Synthesis can fail or perform incorrectly if some examples from the middle of the set are removed, meaning if we want to specify a particularly large or complex example we also have to specify all of the smaller examples, reducing performance.

\subsubsection{FlashFill}
FlashFill \cite{Gulwani2012} is an Inductive Program Synthesis system which generates string and table operations over spreadsheets columns. By defining a domain specific language that is expressive enough to efficiently describe the potential string operations, it is possible to define a data structure which represents the set of possible functions in a succinct manner. \\ \\
These functions are then learned in a two-step procedure. First, for each example, the set of all potential functions that transform the given input to the given output is generated. While this set could be very large, it is optimised by reducing the number of potential substrings of a string be quadratic, not exponential in the size of the string. After this set is generated for each example, the sets are examined to find matching cases and learn conditionals to determine between them. These solutions are then optimised, with shorter expressions being preferred in general.\\ \\
FlashFill is fairly unique in the field of program synthesis due to the fact it has been implemented as a consumer tool. Included in Microsoft Excel 2013, it allows users to quickly generalise an operation over multiple spreadsheet rows.

\begin{figure}[h!]
\centering
\includegraphics[width=0.4\textwidth]{C2/flash_fill.png}
\caption{FlashFill UI}
\label{fig:flashfill}
\end{figure}
\mbox{}\\
However FlashFill has been described as a ``controversial feature'' due to its simplicity. John Walkenbach, an Excel textbook author, wrote ``It's a great concept, but it can also lead to lots of bad data. (...) Be very careful. (...) [M]ost of the extracted data will be fine. But there might be exceptions that you don't notice unless you examine the results very carefully'' \cite{Bauer2016}.

%\renewcommand\bibname{{References}}
%\bibliography{References}
%\bibliographystyle{plain}

\pagebreak


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{framed}
\usepackage{hyperref}
\usepackage{mathrsfs}
\usepackage[parfill]{parskip}
\usepackage{physics}

\begin{document}
\title{Exercise Guide for \textit{Principles of Mathematical Analysis (3rd Ed.)} by Walter Rudin}
\author{Muthu Chidambaram}
\date{Last Updated: \today}

\maketitle

\tableofcontents
\newpage

\section*{About}

\begin{quote}
        \textit{``It is not possible to overstate how good this book is. I tried to give it uncountably many stars but they only have five. Five is an insult. I'm sorry Dr. Rudin...''} - \href{https://www.amazon.com/review/R23MC2PCAJYHCB}{Amazon Review}
\end{quote}

An actual solution manual for the book can be found \href{https://minds.wisconsin.edu/handle/1793/67009}{here}.
What follows are notes I took as I did exercises (they're more like hints towards my thinking than
solutions) while working through the book on my own.

\include{chapter_1}
\include{chapter_2}
\include{chapter_3}
\include{chapter_4}
\include{chapter_5}
\include{chapter_6}
\include{chapter_7}

\end{document}


\documentclass{article}

\usepackage{mathrsfs,amsmath}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{listings}
\usepackage{syntax}
\usepackage{pythonhighlighting}

\usepackage{graphicx}

\graphicspath{ {./assets/} }

\usepackage[margin=1.4in]{geometry}

\title{Handout \#3 | CS 471}
\author{Jared Dyreson\\
        California State University, Fullerton}

\DeclareRobustCommand{\bowtie}{%
  \mathrel\triangleright\joinrel\mathrel\triangleleft}

\usepackage [english]{babel}
\usepackage [autostyle, english = american]{csquotes}
\MakeOuterQuote{"}

\titlespacing*{\section}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}
\titlespacing*{\subsection}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=black,
    urlcolor=black
}

\begin{document}

\maketitle
\tableofcontents

\newpage

\section{Questions}

\begin{enumerate}

\item What are nodal, queueing, transmission, processing, and propagation delays?
\begin{itemize}
\item Nodal ($d_{proc}$): the time that a node spends processing a packet
\item Queueing: the sum of the delays encountered by a packet between the time of insertion into the network and the time of delivery to the destination.
\item Transmission: the amount of time required to push all the packet's bits through a wire
\item Processing: the time it takes routers to process the packet header.
\item Propagation: measure of the time required for a signal to propagate from one end of the circuit to the other.
\end{itemize}

\item What is the difference between transmission and propagation delays?
\begin{itemize}
\item Transmission delays refer to the entire packet being delivered when the propagation delay is in reference to an individual bit sent through the circuit.
\end{itemize}

\item Two systems are connected by a router. Both systems and the router have transmission rates of 1,000 BPS. Each link has a propagation delay of 10ms. Also, it takes the router 2ms to process the packet. Suppose the first system want to send a 10,000 bit packet to the second system. How long will it take before the receiver system obtain the entire packet?
\begin{itemize}
\item Regardless of delays, it will take at least 10 seconds (10000 milliseconds) to transmit each way. Each way will also have a delay of 10 milliseconds along with an additional 2 milliseconds for processing. Therefore it will take:
$$ 20+ 0.2 + 0.002 = 20.022 $$ seconds for the packet to be sent in this ecosystem.
\end{itemize}

\item Consider two hosts, $A$ and $B$, connected by a single link of rate $R$ bps. Suppose that the two hosts are separated by $m$ meters, and suppose the propagation speed along the links is $s$ meters/second. Host $A$ is to send a packet of size $L$ bits to host $B$.
\begin{itemize}
\item Express the propagation delay, $d_{prop}$, in terms of $m$ and $s$.

\begin{itemize}
\item $d_{prop} = \frac{m}{s}$
\end{itemize}

\item Determine the transmission time of the packet, $d_{trans}$ in terms of $L$ and $R$
\begin{itemize}
\item $d_{trans} = \frac{L \text{ (bits) }}{R \text{ (bits/second) }}$
\end{itemize}

\item Ignoring processing and queueing delays, obtain an expression for the end-to-end delay
\begin{itemize}
\item Originally, $d_{nodal}$ can be expressed using the following: $d_{nodal} = d_{proc} + d_{queue} + d_{trans} + d_{prop}$
\item Therefore, in this instance $d_{nodal}$ can be written as: $d_{nodal} = d_{trans} + d_{prop} \implies d_{nodal} = L + R$
\end{itemize}

\newpage

\item Suppose host A begins to transmit the packet at $t = 0$. At $t = d_{trans}$, where is the last bit of the packet?
\begin{itemize}
\item The last bit of the packet has already been sent to the destination node
\end{itemize}

\item Suppose $d_{prop} > d_{trans}$. At $t = d_{trans}$, where is the first bit of the packet?
\begin{itemize}
\item Host A has already finished transmitting the last bit of the packet but since the initial condition says the destination has not yet received the first bit.
\end{itemize}

\item Suppose $d_{prop} < d_{trans}$. At $t = d_{trans}$, where is the first bit of the packet?
\begin{itemize}
\item The first bit of the packet has reached the destination node.
\end{itemize}

\item Suppose $s = 2.5 \times 10^{8}$, $L = 120 \text{ bits }$, and $R = 56 \text{ kbps } \implies 56000 \text{ bps }$. Find the distance $m$ so that $d_{prop} = d_{trans}:$
$$ \frac{L}{R} = \frac{m}{s}$$
$$ \frac{120}{56000} = \frac{m}{2.5 \times 10^{8}}$$
$$m = (\frac{120}{56000} \times (2.5 \times 10^{8})) \div 1000$$
$$m \cong 535.714 \text{ km }$$
\end{itemize}

\end{enumerate}

\end{document}


\documentclass[twoside]{article}
\setlength{\oddsidemargin}{0.25 in}
\setlength{\evensidemargin}{-0.25 in}
\setlength{\topmargin}{-0.6 in}
\setlength{\textwidth}{6.5 in}
\setlength{\textheight}{8.5 in}
\setlength{\headsep}{0.75 in}
\setlength{\parindent}{0 in}
\setlength{\parskip}{0.1 in}

%
% ADD PACKAGES here:
%

\usepackage{amsmath,amsfonts,graphicx}

%
\newcounter{lecnum}
\renewcommand{\thepage}{\thelecnum-\arabic{page}}
\renewcommand{\thesection}{\thelecnum.\arabic{section}}
\renewcommand{\theequation}{\thelecnum.\arabic{equation}}
\renewcommand{\thefigure}{\thelecnum.\arabic{figure}}
\renewcommand{\thetable}{\thelecnum.\arabic{table}}

%
% The following macro is used to generate the header.
%
\newcommand{\lecture}[4]{
   \pagestyle{myheadings}
   \thispagestyle{plain}
   \newpage
   \setcounter{lecnum}{#1}
   \setcounter{page}{1}
   \noindent
   \begin{center}
   \framebox{
      \vbox{\vspace{2mm}
    \hbox to 6.28in { {\bf EE402 - Discrete Time Systems
	\hfill Spring 2018} }
       \vspace{4mm}
       \hbox to 6.28in { {\Large \hfill Lecture #1 \hfill} }
       \vspace{2mm}
       \hbox to 6.28in { {\it Lecturer: #2 \hfill } }
      \vspace{2mm}}
   }
   \end{center}
   \markboth{Lecture #1}{Lecture #1}

   \vspace*{4mm}
}

\renewcommand{\cite}[1]{[#1]}
\def\beginrefs{\begin{list}%
        {[\arabic{equation}]}{\usecounter{equation}
         \setlength{\leftmargin}{2.0truecm}\setlength{\labelsep}{0.4truecm}%
         \setlength{\labelwidth}{1.6truecm}}}
\def\endrefs{\end{list}}
\def\bibentry#1{\item[\hbox{[#1]}]}

%Use this command for a figure; it puts a figure in wherever you want it.
%usage: \fig{NUMBER}{SPACE-IN-INCHES}{CAPTION}
\newcommand{\fig}[3]{
			\vspace{#2}
			\begin{center}
			Figure \thelecnum.#1:~#3
			\end{center}
	}
% Use these for theorems, lemmas, proofs, etc.
\newtheorem{theorem}{Theorem}[lecnum]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newenvironment{proof}{{\bf Proof:}}{\hfill\rule{2mm}{2mm}}

% **** IF YOU WANT TO DEFINE ADDITIONAL MACROS FOR YOURSELF, PUT THEM HERE:

\begin{document}

% Lecture Details
\lecture{12}{Asst. Prof. M. Mert Ankarali}

\par

\section*{State-Space Representation of DT Systems}

State-space representation of a (causal \& finite dimensional) LTI CT system is given by
%
\begin{align*}
  \mathrm{Let} \ x(t) &\in \mathbb{R}^n \ , \ y(t) \in \mathbb{R}^m \ ,\  u(t) \in
  \mathbb{R}^r , \\
  \dot{x}(t) &= A x(t) + B u(t) , \\
  y(t) &= C x(t) + D u(t) , \\
  \mathrm{where} \ A &\in \mathbb{R}^{n \times n} \ , \
    B \in \mathbb{R}^{n \times r} \ ,\  C \in \mathbb{R}^{m \times n} \ , \ D \in \mathbb{R}^{m \times r}
\end{align*}
%
State-space representation of a (causal \& finite dimensional) LTI DT system is given by
%
\begin{align*}
  \mathrm{Let} \ x[k] &\in \mathbb{R}^n \ , \ y[k] \in \mathbb{R}^m \ ,\  u[k] \in
  \mathbb{R}^r , \\
  x[k+1] &= G x[k] + H u[k] , \\
  y[k] &= C x[k] + D u[k] , \\
  \mathrm{where} \ G &\in \mathbb{R}^{n \times n} \ , \
    H \in \mathbb{R}^{n \times r} \ ,\  C \in \mathbb{R}^{m \times n} \ , \ D \in \mathbb{R}^{m \times r}
\end{align*}
%
Depending on the values of $m$ and $r$ we have
%
\begin{itemize}
  \item $m = r = 1$, the system represents a SISO system
  \item $m > 1 \ , \  r < 1$, the system represents a MIMO system
  \item $m = 1 \ , \ r > 1$, the system represents a MISO system
  \item $m > 1  \ , \ r = 1$, the system represents a SIMO system
\end{itemize}
%
for both CT and DT cases.

\textbf{State property of CT state-space models:} Given the initial time,
$t_0$ and state $x(t_0)$ and input $u(t)$ for $t_0 \leq t < t_f$ (with
$t_0 \ \& \ t_f$ arbitrary), we can compute the output $y(t)$ for
$t_0 \leq t \leq t_f$ and the state $x(t)$ for $t_0 \leq t \leq t_f$.

\textbf{State property of DT state-space models:}
Given the state vector $x[k]$ and input $u[k]$ at an arbitrary time $k$,
we can compute the the present output, $y[k]$, and next state $x[k+1]$.

Note that both definitions are not limited to LTI state-space models.
Nonlinear and time-varying state-space models also are based on this
definition.

When a state-space representation includes minimum number of state
variables, the representation is called minimal.

\subsection*{Canonical State-Space Realizations of (SISO) DT Systems}

\subsubsection*{Reachable/Controllable Canonical Form}

For the sake of clarity let's assume that the system that we would
like to represent is a third order DT system with the following difference equation
and transfer function

\begin{align*}
y[k] &=  -a_1 y[k-1] - a_2 y[k-2] - a_3 y[k-3]
+ b_0 x[k] + b_1 x[k-1] + b_2 x[k-2] + b_3 x[k-3] \\
Y(z) &= \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + b_3 z^{-3}}{1+ a_1 z^{-1} + a_2 z^{-2} + a_3 z^{-3}} X(z)
\end{align*}

We know that following block
ram realizes this system structure
with minimum number of delay elements and it is a canonical
realization. Delay operation is directly
related with state and state evolution concept.
%
     \begin{center}
 \begin{minipage}[h]{0.7\linewidth}
     \begin{center}
       \includegraphics[width=\textwidth]{reachable}
     \end{center}
 \end{minipage}
     \end{center}
%
If we label the signals as given in the Figure,
state evolution equations can be derived as
%
\begin{align*}
X_1(z) = X_2(z) z^{-1}  \quad &\rightarrow \quad x_1[k+1] = x_2[k]
\\
X_2(z) = X_3(z) z^{-1}  \quad &\rightarrow \quad x_2[k+1] = x_3[k]
\\
X_3(z) = \left( U(z)  - \left( X_1(z) a_3 + X_2(z) a_2 + X_3(z) a_1 \right) \right) z^{-1}
\quad &\rightarrow \quad
x_3[k+1] =  u[k] + x_1[k] (-a_3) + x_2[k] (-a_2) + x_3[k] (-a_1)
\end{align*}
%
where as output equation can be derived as
%
\begin{align*}
y[k] &= b_1 x_3[k] + b_2 x_2[k] + b_3 x_1[k]
b_0 u[k] - b_0 \left( a_1 x_3[k] + a_2 x_2[k] + a_3 x_1[k] \right)
\\
&= b_0 u[k] + (b_3 - b_0 a_3) x_1[k] + (b_2 - b_0 a_2) x_2[k]
+ (b_1 - b_0 a_1) x_3[k]
\end{align*}
%
If we gather these equations, we can obtain the state space form
%
\begin{align*}
  \mathbf{x}[k+1] &= \left[ \begin{array}{ccc} 0 & 1 & 0 \\ 0 & 0 & 1
    \\ -a_3 & -a_2 & -a_1 \end{array} \right] \mathbf{x}[k]
   +
  \left[ \begin{array}{c} 0\\ 0
    \\ 1 \end{array} \right] u[k]
\\
y[k] &= \left[ \begin{array}{ccc} (b_3 - b_0 a_3) &  (b_2 - b_0 a_2) &
                                                                       (b_1 - b_0 a_1) \end{array} \right]
+ b_0 u[k]
\end{align*}
%
where
%
\begin{align*}
\mathbf{x} = \left[ \begin{array}{c} x_1[k] \\ x_2[k] \\
x_1[k] \end{array} \right] \quad , \quad
A = \left[ \begin{array}{ccc} 0 & 1 & 0 \\ 0 & 0 & 1
    \\ -a_3 & -a_2 & -a_1 \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} 0\\ 0
    \\ 1 \end{array} \right]
\\ C = \left[ \begin{array}{ccc} (b_3 - b_0 a_3) &  (b_2 - b_0 a_2) &
   (b_1 - b_0 a_1) \end{array} \right]
\quad , \quad
D = b_0
\end{align*}
%
The form obtained with this approach is called
reachable/controllable canonical form.

For a general $n^{th}$ order system reachable/controllable
canonical form has the following $A \ ,  B \ ,  C \ , \& \ D$
matrices
%
\begin{align*}
A &= \left[ \begin{array}{ccccc} 0 & 1 & 0 & \cdots & 0 \\ 0 & 0 & 1 &
                                                                      \cdots & 0
\\ \vdots & \vdots & \vdots & & \vdots
\\ 0 & 0 & 0 & \cdots & 1
    \\ -a_n & -a_{n-1} & -a_{n-2} & \cdots & -a_1 \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} 0\\ 0 \\ \vdots \\ 0
    \\ 1 \end{array} \right]
\\ C &= \left[ \begin{array}{ccccc} (b_n - b_0 a_n)
  &  (b_{n-1} - b_0 a_{n-1}) & \cdots &  (b_2 - b_0 a_2) &
   (b_1 - b_0 a_1) \end{array} \right]
\quad , \quad
D = b_0
\end{align*}

\subsubsection*{Observable Canonical Form}

We also learnt a different type of canonical
minimal realization which is illustrated
in the Figure below
%
     \begin{center}
 \begin{minipage}[h]{0.6\linewidth}
     \begin{center}
       \includegraphics[width=\textwidth]{observable}
     \end{center}
 \end{minipage}
     \end{center}
%
If we label the signals as given in the Figure,
state evolution equations can be derived as
%
\begin{align*}
X_1(z) = \left( b_3 U(z) - a_3 \left( U(z) b_0 + X_3(z) \right) \right) z^{-1}
\quad &\rightarrow \quad x_1[k+1] = b_3 u[k] - a_3 \left( u[k] b_0 +
        x_3[k] \right)
\\
X_2(z) = \left( b_2 U(z) + X_1(z) - a_2 \left( U(z) b_0 + X_3(z) \right) \right) z^{-1}
\quad &\rightarrow \quad x_2[k+1] = b_2 u[k] + x_1[k] - a_2 \left( u[k] b_0 +
        x_3[k] \right)
\\
X_3(z) = \left( b_1 U(z) + X_2(z) - a_1 \left( U(z) b_0 + X_3(z) \right) \right) z^{-1}
\quad &\rightarrow \quad x_3[k+1] = b_1 u[k] + x_2[k] - a_1 \left( u[k] b_0 +
        x_3[k] \right)
\end{align*}
%
where as output equation can be derived as
%
\begin{align*}
y[k] &= b_0 u[k] + x_3[k]
\end{align*}
%
If we combine the state and output equations, we
can obtain the state space form as
%
%
\begin{align*}
  \mathbf{x}[k+1] &= \left[ \begin{array}{ccc} 0 & 0 & -a_3 \\ 1 & 0 & -a_2
    \\ 0 & 1 & -a_1 \end{array} \right] \mathbf{x}[k]
   +
  \left[ \begin{array}{c} b_3 - b_0 a_3 \\ b_2 - b_0 a_2
    \\ b_1 - b_0 a_1 \end{array} \right] u[k]
\\
y[k] &= \left[ \begin{array}{ccc} 0 & 0 & 1 \end{array} \right]
+ b_0 u[k]
\end{align*}
%
where
%
\begin{align*}
\mathbf{x} = \left[ \begin{array}{c} x_1[k] \\ x_2[k] \\
x_1[k] \end{array} \right] \quad , \quad
A = \left[ \begin{array}{ccc} 0 & 0 & -a_3 \\ 1 & 0 & -a_2
    \\ 0 & 1 & -a_1 \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} b_3 - b_0 a_3 \\ b_2 - b_0 a_2
    \\ b_1 - b_0 a_1 \end{array} \right]
\quad , \quad
C = \left[ \begin{array}{ccc} 0 & 0 & 1 \end{array} \right]
\quad , \quad
D = b_0
\end{align*}
%

The form obtained with this approach is called
observable canonical form.

For a general $n^{th}$ order system observable
canonical form has the following $A \ ,  B \ ,  C \ , \& \ D$
matrices
%
\begin{align*}
A &= \left[ \begin{array}{ccccc} 0 & 0 & \cdots & 0 & -a_{n}
              \\ 1 & 0 & \cdots & 0 & -a_{n-1}
\\ \vdots & \vdots & \vdots & \vdots & \vdots
\\ 0 & 0 & \cdots & 0 & -a_2
    \\ 0 & 0 & \cdots & 1 & -a_1 \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} (b_n - b_0 a_n)  \\ (b_{n-1} - b_0
             a_{n-1}) \\ \vdots \\ (b_2 - b_0 a_2) \\   (b_1 - b_0
             a_1)
\end{array} \right]
\\ C &= \left[ \begin{array}{ccccc} 0 & 0 & \cdots &  0 & 1 \end{array} \right]
\quad , \quad
D = b_0
\end{align*}
%
\subsubsection*{Diagonal Canonical Form}

If the pulse transfer function of the system
has distinct poles, we can expand it
using partial fraction expansion
%
\begin{align*}
Y(z) &= \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + b_3 z^{-3}}{1+ a_1
       z^{-1} + a_2 z^{-2} + a_3 z^{-3}} X(z)
\\
&= \left( b_0 + \frac{c_1}{z - p_1} + \frac{c_2}{z - p_2}
+ \frac{c_3}{z - p_3} \right) X(z)
\end{align*}
%
It is possible to realize this expanded form in block diagram
form as given in the Figure below.
%
     \begin{center}
 \begin{minipage}[h]{0.5\linewidth}
     \begin{center}
       \includegraphics[width=\textwidth]{diagonal}
     \end{center}
 \end{minipage}
     \end{center}
%
Now let's concentrate on the candidate ``state variables''
and try to write state evaluation equations
%
\begin{align*}
X_1(z) &= \frac{1}{z - p_1} U(z) \quad \rightarrow \quad x_1[k+1] = p_1
  x_1[k] + u[k]
\\
X_2(z) &= \frac{1}{z - p_2} U(z) \quad \rightarrow \quad x_2[k+1] = p_2
  x_2[k] + u[k]
\\
X_3(z) &= \frac{1}{z - p_3} U(z) \quad \rightarrow \quad x_3[k+1] = p_3
  x_3[k] + u[k]
\end{align*}
%
where as output equation can be derived as
%
\begin{align*}
y[k] &= b_0 u[k] + c_1 x_1[k] + c_2 x_2[k] + c_3 x_3[k]
\end{align*}
%
If we combine the state and output equations, we
can obtain the state space form as
%
%
\begin{align*}
  \mathbf{x}[k+1] &= \left[ \begin{array}{ccc} p_1 & 0 & 0\\ 0 & p_2 & 0
    \\ 0 & 0 & p_3 \end{array} \right] \mathbf{x}[k]
   +
  \left[ \begin{array}{c} 1 \\ 1
    \\ 1 \end{array} \right] u[k]
\\
y[k] &= \left[ \begin{array}{ccc} c_1 & c_2 & c_3 \end{array} \right]
+ b_0 u[k]
\end{align*}
%
where
%
\begin{align*}
\mathbf{x} = \left[ \begin{array}{c} x_1[k] \\ x_2[k] \\
x_1[k] \end{array} \right] \quad , \quad
A = \left[ \begin{array}{ccc} p_1 & 0 & 0 \\ 0 & p_2 & 0
    \\ 0 & 0 & p_3 \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} 1 \\ 1
    \\ 1 \end{array} \right]
\quad , \quad
C = \left[ \begin{array}{ccc} c_1 & c_2 & c_3 \end{array} \right]
\quad , \quad
D = b_0
\end{align*}
%

The form obtained with this approach is called
diagonal canonical form. Obviously, this form is
not applicable for systems that has repeated roots.

For a general $n^{th}$ order system with distinct
roots diagonal canonical form has the following
$A \ ,  B \ ,  C \ , \& \ D$ matrices
%
\begin{align*}
A &= \left[ \begin{array}{ccccc} p_1 & 0 & \cdots & 0 & 0
              \\ 0 & p_2 & \cdots & 0 & 0
\\ \vdots & \vdots & \vdots & \vdots & \vdots
\\ 0 & 0 & \cdots & p_{n-1} & 0
    \\ 0 & 0 & \cdots & 0 & p_n \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\  1
\end{array} \right]
\\ C &= \left[ \begin{array}{ccccc} c_1 & c_2 & \cdots &  c_{n-1} & c_n \end{array} \right]
\quad , \quad
D = b_0
\end{align*}
%

\subsubsection*{Jordan Canonical Form}

Generalization of diagonal canonical
farm is called Jordan canonical form
which handles repeated roots.

In Jordan form the distinct roots has the
same structure with Diagonal canonical
form. Let's assume that the $3^{rd}$
order pulse transfer function has
three repeated roots. In this case,
we can expand it using partial fraction
expansion
%
\begin{align*}
Y(z) &= \frac{b_0 + b_1 z^{-1} + b_2 z^{-2} + b_3 z^{-3}}{1+ a_1
       z^{-1} + a_2 z^{-2} + a_3 z^{-3}} X(z)
\\
&= \left( b_0 + \frac{c_1}{(z - p)^3} + \frac{c_2}{(z - p)^2}
+ \frac{c_3}{z - p} \right) X(z)
\end{align*}
%
It is possible to realize this expanded form in block diagram
form as given in the Figure below.
%
     \begin{center}
 \begin{minipage}[h]{0.5\linewidth}
     \begin{center}
       \includegraphics[width=\textwidth]{jordan}
     \end{center}
 \end{minipage}
     \end{center}
%
Now let's concentrate on the candidate ``state variables''
and try to write state evaluation equations
%
\begin{align*}
X_1(z) &= \frac{1}{z - p} X_2(z) \quad \rightarrow \quad x_1[k+1] = p \
  x_1[k] + x_2[k]
\\
X_2(z) &= \frac{1}{z - p} X_3(z) \quad \rightarrow \quad x_2[k+1] = p
         \ x_2[k] +
  x_3[k]
\\
X_3(z) &= \frac{1}{z - p} U(z) \quad \rightarrow \quad x_3[k+1] = p \
  x_3[k] + u[k]
\end{align*}
%
where as output equation can be derived as
%
\begin{align*}
y[k] &= b_0 u[k] + c_1 x_1[k] + c_2 x_2[k] + c_3 x_3[k]
\end{align*}
%
If we combine the state and output equations, we
can obtain the state space form as
%
\begin{align*}
  \mathbf{x}[k+1] &= \left[ \begin{array}{ccc} p & 1 & 0\\ 0 & p & 1
    \\ 0 & 0 & p \end{array} \right] \mathbf{x}[k]
   +
  \left[ \begin{array}{c} 0 \\ 0
    \\ 1 \end{array} \right] u[k]
\\
y[k] &= \left[ \begin{array}{ccc} c_1 & c_2 & c_3 \end{array} \right]
+ b_0 u[k]
\end{align*}
%
where
%
\begin{align*}
\mathbf{x} = \left[ \begin{array}{c} x_1[k] \\ x_2[k] \\
x_1[k] \end{array} \right] \quad , \quad
A = \left[ \begin{array}{ccc} p & 1 & 0 \\ 0 & p & 1
    \\ 0 & 0 & p \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} 0 \\ 0
    \\ 1 \end{array} \right]
\quad , \quad
C = \left[ \begin{array}{ccc} c_1 & c_2 & c_3 \end{array} \right]
\quad , \quad
D = b_0
\end{align*}
%
$A, \ B, \ \& \ C$ forms a Jordan block.

For a general $n^{th}$ order system a Jordan block
with $m$ repeated roots inside a stat-space representation
in Jordan canonical form looks like
%
\begin{align*}
A &= \left[ \begin{array}{c|ccccc|c}
\ddots & & & & & &
\\ \hline
& \bar{p} & 1 & \cdots & 0 & 0 &
\\ & 0 & \bar{p} & \cdots & 0 & 0
\\ & & & \ddots & & &
\\ & 0 & 0 & \cdots & \bar{p} & 1
    \\ & 0 & 0 & \cdots & 0 & \bar{p}
\\
\hline
& & & & & & \ddots
 \end{array} \right]
\quad , \quad
B = \left[ \begin{array}{c} \vdots \\\hline
0 \\ 0 \\ \vdots \\ 0 \\  1 \\ \hline
\vdots
\end{array} \right]
\\ C &= \left[ \begin{array}{c|ccccc|c} \cdots &
c_1 & c_2 & \cdots &  c_{n-1} & c_n & \cdots\end{array} \right]
\end{align*}
%

\subsection*{Similarity Transformations}

Consider the state-space representation of a
given DT system
%
\begin{align*}
  x[k+1] = G x[k] + H u[k]
\\
  y[k] = C x[k] + D u[k]
\end{align*}
%
Let's define a new ``state-vector'' $\hat{x}$ such that
%
\begin{align*}
  P x[k] = \hat{x}[k] \quad \mathrm{where}
\\
  P \in \mathbb{R}^{n \times n} \quad \mathrm{det}(P) \neq 0
\end{align*}
%
Then we can transform the state-space equations using $P$
as
%
\begin{align*}
  P^{-1} \hat{x}[k+1] = G P^{-1} \hat{x}[k] + H u[k]
\quad &, \quad y[k] = C P^{-1} \hat{x}[k] + D u[k]
\\
  \hat{x}[k+1] = P G P^{-1} \hat{x}[k] + P H u[k]
\quad &, \quad y[k] = C P^{-1} \hat{x}[k] + D u[k]
\end{align*}
%
The ``new'' state-space representation is obtained as
%
\begin{align*}
  \hat{x}[k+1] &= \hat{G} \hat{x}[k] + \hat{H} u[k]
    \\
  y[k] &= \hat{C} x[k] + \hat{D} u[k]
\\
\hat{G} &= P  G P^{-1} \ , \ \hat{H} = P  H \ , \ \hat{C} = C P^{-1} \ ,
  \ \hat{D} = D
\end{align*}
%
Since there exist infinitely many non-singular $n \times n$
matrices, for a given LTI DT system, there exist infinitely
many different but equivalent state-space representations.

\vspace{24pt}

\textbf{Example:} Show that $A \in \mathbb{R}^{n \times n}$ and $P^{-1} A
P$, where $P \mathbb{R}^{n \times n}$ and $\mathrm{det}(P) \neq 0$, have the
same characteristic equation

\textbf{Solution:}
\begin{align*}
  \mathrm{det}\left(\lambda I - P^{-1} A P \right) &=
\mathrm{det}\left( \lambda P^{-1} I P - P^{-1} A P \right)
\\
&= \mathrm{det} \left( P^{-1} \left( \lambda I - A \right) P \right)
\\
&= \mathrm{det} \left( P^{-1} \right)
\mathrm{det} \left( \lambda I - A \right)
\mathrm{det} \left( P \right)
\\
&= \mathrm{det} \left( P^{-1} \right) \mathrm{det} \left( P \right)
\mathrm{det} \left( \lambda I - A \right)
\\
\mathrm{det}\left(\lambda I - P^{-1} A P \right) &= \mathrm{det} \left( \lambda I - A \right)
\end{align*}

\subsection*{Obtaining Transfer Functions from a State-Space
  Representation}

Let's consider the following general state-space form
%
\begin{align*}
  x[k+1] = G x[k] + H u[k]
\\
  y[k] = C x[k] + D u[k]
\end{align*}
%
In order to obtain transfer function form,
we assume that initial conditions are zero.
Under this assumption, let's take z-transform
of both equations
%
\begin{align*}
  z X(z) &= G X(z) + H U(z)
\quad , \quad
  Y(z) = C X(z) + D U(z)
\\
\left(z I - G \right) X(z) &= H U(z)
\\
X(z) &= \left(z I - G \right)^{-1} H U(z)
\\
Y(z) &= C \left(z I - G \right)^{-1} H U(z) + D U(z)
\\
Y(z) &= \left[ C \left(z I - G \right)^{-1} H + D \right] U(z)
\\
T(z) & = \left[ C \left(z I - G \right)^{-1} H + D \right]
\end{align*}
%
If the system is a SISO system, then $T(z)$ is a transfer function,
where as for MIMO case $T(z)$ becomes a \textit{transfer function
  matrix}. Note that $\left(z I - G \right)^{-1}$ is invertible for
all $z \in \mathbb{C}$ except the eigenvalues of $G$.

\vspace{24pt}

\textbf{Example:} Let $p$ be a pole of $T(z)$, show that
$p$ is also an eigenvalue of $G$.

\textbf{Solution:} Let
%
\begin{align*}
  T(z) = \frac{n(z)}{d(z)}
\end{align*}
%
If $p$ is a pole of $T(z)$, then $d(z)|_{p} = 0$. Now let's analyze
the dependence of $T(z)$ to the state-space form.
%
\begin{align*}
  T(z) &= \left[ C \left(z I - G \right)^{-1} H + D \right]
\\
  \left(z I - G \right)^{-1} &=
\frac{\mathrm{Adj} \left(z I - G \right) }{\mathrm{det} \left(z I - G
                               \right) }
\\
 T(z) &= \frac{C \mathrm{Adj} \left(z I - G \right) H + D \mathrm{det}
        \left(z I - G
                               \right)}{\mathrm{det} \left(z I - G
                               \right) }
\end{align*}
%
If $p$ is a pole of $T(z)$, then
%
\begin{align*}
\mathrm{det} \left(z I - G \right)|_{z = p} = 0
\end{align*}
%
Obviously $p$ is an eigenvalue of $G$.

\subsubsection*{Invariance of Transfer Functions Under Similarity
  Transformation}

Consider the two different state-space representations
%
\begin{align*}
  x[k+1] = G x[k] + H u[k]  \quad & \quad \quad \hat{x}[k+1] = \hat{G} \hat{x}[k] + \hat{H} u[k]
\\
  y[k] = C x[k] + D u[k] \quad & \quad \quad  y[k] = \hat{C} x[k] + \hat{D} u[k]
\end{align*}
%
where they are related with the following similarity transformation
%
\begin{align*}
P x[k] = \hat{x}[k] \ , \
\hat{G} &= P  G P^{-1} \ , \ \hat{H} = P  H \ , \ \hat{C} = C P^{-1} \ ,
  \ \hat{D} = D
\end{align*}
%
Let's compute the transfer function for the second representation
%
\begin{align*}
  \hat{T}(z) &= \left[ \hat{C} \left(z I - \hat{G} \right)^{-1} \hat{H}
  + \hat{D} \right]
\\
&= \left[ C P^{-1} \left(z I - P  G P^{-1} \right)^{-1} P H
  + D \right]
\\
&= \left[ C P^{-1} \left( P \left( z I -   G \right) P^{-1} \right)^{-1} P H
  + D \right]
\\
&= \left[ C P^{-1} P \left( z I -   G \right)^{-1} P^{-1} P H
  + D \right]
\\
&= \left[ C \left( z I -   G \right)^{-1} H + D \right]
\\
\hat{T}(z) &= T(z)
\end{align*}

\newpage

\section*{Solution of Discrete-Time State-Space Equations}

Let's first assume that $u[k] = 0$, and find un-driven (homogeneous)
response.
%
\begin{align*}
  x[k+1] &= G x[k] \\
  y[k] &= C x[k]
\end{align*}
%
Unlike CT systems we can compute the response iteratively
%
\begin{align*}
  x[1] &= G x[0]
  \\
  x[2] &= G x[1] = G^2 x[0]
  \\
  x[3] &= G x[2] = G^3 x[0]
  \\
  \vdots
  \\
  x[k] &= G x[k-1] = G^k x[0] \quad , \quad y[k] = C G^k x[0]
\end{align*}
%
It is easy to see that for $k , p \in \mathbb{Z}$ where $k > p$
%
\begin{align*}
  x[k] &= G^{k-p} x[p]
\end{align*}
%
Let $\Psi(k) = G^k$, then this matrix of functions solves the
homogeneous difference equation
%
\begin{align*}
  x[k+1] &= G x[k]
\\
\\
  x[k] &=\Psi[k] x[0]
\\
  x[k] &=\Psi[k-p] x[p]
\\
 x[k+m] &=\Psi[ k + m - m] x[m] = \Psi[k]
\end{align*}
%
$\Psi[k]$ is called the state-transition matrix.
%
Now let's consider input-only state response (i.e. $x[0] = 0$).
%
\begin{align*}
  x[k+1] &= G x[k] + H u[k]
  \\
  \\
  x[1] &= H u[0]
  \\
  x[2] &= G x[1] + H u[1] = G H u[0] + H u[1]
  \\
  x[3] &= G x[2] + H u[2] = G^2 H u[0] + G H u[1] + H u[2]
  \\
  x[4] &= G x[3] + H u[3] = G^3 H u[0] + G^2 H u[1] + G H u[2] + H
         u[3]
  \\
  \vdots
 \\
  x[k] &= G x[k-1] + H u[k-1] \\
         &= G^{k-1} H u[0] + G^{k-2} H u[1] +
         \cdots + G H u[k-2] + H u[k-1]
         \\
         &= \left[ \begin{array}{c|c|c|c|c} G^{k-1} H & G^{k-2} H &
         \cdots & G H & H \end{array} \right]
         \left[ \begin{array}{c}
                  u[0] \\ u[1] \\ \vdots \\ u[k-2] \\ u[k-1]
         \end{array} \right]
         \\
         &= \sum\limits_{j = 0}^{k-1} G^{k-j-1} H u[j]
         \\
         &= \sum\limits_{j = 0}^{k-1} G^{j} H u[k-j-1]
\end{align*}
%
Given that $\Psi[k] = G^k$
%
\begin{align*}
    x[k] &= \sum\limits_{j = 0}^{k-1} \Psi[k-j-1] H u[j]
\\
&= \sum\limits_{j = 0}^{k-1} \Psi[j] H u[k-j-1]
\end{align*}
%
If we combine homegeneous and driven responses we can simply obtain
%
\begin{align*}
    x[k] &= \Psi[k] x[0] + \sum\limits_{j = 0}^{k-1} \Psi[k-j-1] H u[j]
\\
&= \Psi[k] x[0] + \sum\limits_{j = 0}^{k-1} \Psi[j] H u[k-j-1]
\end{align*}
%
whereas output at time $k$ has the form
%
\begin{align*}
    y[k] &= C \Psi[k] x[0] + C \left( \sum\limits_{j = 0}^{k-1}
           \Psi[k-j-1] H u[j] \right) + D u[k]
\\
&= C \Psi[k] x[0] + C \left( \sum\limits_{j = 0}^{k-1} \Psi[j] H
  u[k-j-1] \right) +  D u[k]
\end{align*}
%

\subsection*{Z-domain Solution of State-Space Equations}

We already computed the transfer function under zero initial
conditions.
%
\begin{align*}
  Y(z) =  \left[ C \left(z I - G \right)^{-1} H + D \right] U(z)
\end{align*}
%
Now let's compute the response to initial condition in Z-domain.
%
\begin{align*}
\mathcal{Z} \left[ x[k+1] \right] &= \mathcal{Z} \left[ G x[k] \right]
\\
z X(z) - z x[0] &= G X(z)
\\
\left( z I - G \right) X(z) &= z X(z)
\\
X(z) &= z \left( z I - G \right)^{-1} x[0]
\end{align*}
%
Similarly $Y(z)$ takes the form
%
\begin{align*}
  Y(z) &= z C \left( z I - G \right)^{-1} x[0]
\end{align*}
%
We can also observe that
%
\begin{align*}
  \mathcal{Z} \left[ \Psi[k] \right] &= \mathcal{Z} [ G^k ] =
  z \left( z I - G \right)^{-1}
\\
  \mathcal{Z}^{-1} [   z \left( z I - G \right)^{-1} ] &= \Psi[k] = G^k
\end{align*}
%
If we expand $z \left( z I - G \right)^{-1}$ by long ``division'' we
can also observe the relation in z-domain and time doman expressions
from a different perspective
%
     \begin{center}
 \begin{minipage}[h]{0.5\linewidth}
     \begin{center}
       \includegraphics[width=\textwidth]{directdivision}
     \end{center}
 \end{minipage}
     \end{center}
%
\begin{align*}
z \left( z I - G \right)^{-1} &= I + z^{-1} G + z^{-2} G^2 + z^{-3} G^3
  + \cdots
\\
\mathcal{Z}^{-1} \left[ z \left( z I - G \right)^{-1} \right] &=
I \, \delta[k] + G \, \delta[k-1] + G^2 \, \delta[k-2] + G^3 \,
  \delta[k-3] + \cdots
\end{align*}
%

\newpage

\textbf{Example:} Consider the following state-space representation
%
\begin{align*}
  x[k+1] &= \left[ \begin{array}{ccc} 1 & 0 & 0\\ 0 & 1/2 & 0
    \\ 0 & 0 & -1 \end{array} \right] x[k]
    + \left[ \begin{array}{c} 1 \\ 1 \\ 1\end{array} \right] u[k]
\\
 y[k] &= \left[ \begin{array}{ccc} 1 & 2 & 3 \end{array} \right] x[k]
\end{align*}
%
\begin{itemize}
  \item Compute the closed form expression $\Psi[k]$ using the time
   expression

    \textbf{Solution:} The state-space representation is in Diagonal
    canonical form

\begin{align*}
  \Psi[k]  = G^k = \left[ \begin{array}{ccc} 1 & 0 & 0\\ 0 & 1/2 & 0
    \\ 0 & 0 & -1 \end{array} \right]^k
    = \left[ \begin{array}{ccc} 1^k & 0 & 0\\ 0 & (1/2)^k & 0
    \\ 0 & 0 & (-1)^k \end{array} \right]
 = \left[ \begin{array}{ccc} 1 & 0 & 0\\ 0 & (1/2)^k & 0
    \\ 0 & 0 & (-1)^k \end{array} \right]
\end{align*}

\item Compute the closed form expression $\Psi[k]$ using the z-domain
  solution method

\textbf{Solution:}

\begin{align*}
  \Psi[k]  &= \mathcal{Z}^{-1} \left[   z \left( z I - G \right)^{-1} \right]
\\
&= \mathcal{Z}^{-1} \left[   z \left( \left[ \begin{array}{ccc} z-1 & 0 & 0\\ 0 & (z-1/2) & 0
    \\ 0 & 0 & z+1 \end{array} \right] \right)^{-1} \right]
\\
&= \mathcal{Z}^{-1} \left[   \left[ \begin{array}{ccc} \frac{z}{z-1} & 0 & 0\\ 0 & \frac{z}{z-1/2} & 0
    \\ 0 & 0 & \frac{z}{z+1} \end{array} \right] \right]
\\
&= \left[ \begin{array}{ccc} 1 & 0 & 0\\ 0 & (1/2)^k & 0
    \\ 0 & 0 & (-1)^k \end{array} \right] \quad \mathrm{for} k \geq 0
\end{align*}

\item Compute the impulse response of the system from the time domain
solution

\textbf{Solution:}

\begin{align*}
  x[k] &= G^{k-1} H u[0] \quad \mathrm{for} \  k > 0 \\
  y[k] &= C G^{k-1} H \quad \mathrm{for} \ k > 0 \\
         &= \left[ \begin{array}{ccc} 1 & 2 & 3 \end{array} \right]
                \left[ \begin{array}{ccc} 1 & 0 & 0\\ 0 & (1/2)^{k-1} & 0
    \\ 0 & 0 & (-1)^{k-1} \end{array} \right]
      \left[ \begin{array}{c} 1 \\ 1 \\ 1\end{array} \right]
\\
&= \left[ \begin{array}{ccc} 1 & 2 & 3 \end{array} \right]
\left[ \begin{array}{c} 1 \\ (1/2)^{k-1} \\ (-1)^{k-1} \end{array}
  \right]
\\
y[k] &= 1 + 2 (1/2)^{k-1} + 3 (-1)^{k-1} \quad \mathrm{for} \ k > 0
\end{align*}

\item Compute the transfer function $\frac{Y(z)}{U(z)}$

\textbf{Solution:}

\begin{align*}
  T(z) &= C \left( z I - G \right)^{-1} H \\
         &= \left[ \begin{array}{ccc} 1 & 2 & 3 \end{array} \right]
\left[ \begin{array}{ccc} z-1 & 0 & 0\\ 0 & z-1/2 & 0
    \\ 0 & 0 & z+1 \end{array} \right]^{-1}
\left[ \begin{array}{c} 1 \\ 1 \\ 1\end{array} \right]
\\
&= \left[ \begin{array}{ccc} 1 & 2 & 3 \end{array} \right]
\left[ \begin{array}{ccc} \frac{1}{z-1} & 0 & 0\\ 0 & \frac{1}{z-1/2} & 0
    \\ 0 & 0 & \frac{1}{z+1} \end{array} \right]
\left[ \begin{array}{c} 1 \\ 1 \\ 1\end{array} \right]
\\
&=
\left[ \begin{array}{ccc} 1 & 2 & 3 \end{array} \right]
\left[ \begin{array}{c} \frac{1}{z-1} \\ \frac{1}{z-1/2} \\
         \frac{1}{z+1}\end{array} \right]
\\
  T(z) &= \frac{1}{z-1} + \frac{2}{z-1/2} + \frac{3}{z+1}
\end{align*}

\item Compute the inverse Z-transform of the  transfer function

\textbf{Solution:}

\begin{align*}
  t[k] &= \mathcal{Z}^{-1} \left[ \frac{1}{z-1} + \frac{2}{z-1/2} +
  \frac{3}{z+1} \right]
\\
&= \left( 1 + 2 (1/2)^{k-1} + 3 (-1)^{k-1} \right) h[k-1]
\end{align*}
%
where $h[k]$ is the unit step function

\end{itemize}

% **** This ENDS THE EXAMPLES. DON'T DELETE THE FOLLOWING LINE:
\end{document}


\documentclass[letter,11pt]{scrartcl}
\usepackage{amsmath,amssymb}
\usepackage[amssymb]{SIunits}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{standalone}
\usepackage{tikz,pgf,pgfplots}
\usetikzlibrary{decorations.pathmorphing}

\usepackage[margin=20mm]{geometry}
\newenvironment{exercise}[1][Uppgift]{\begin{trivlist} \item[\hskip
    \labelsep {\stepcounter{exerctr}\bfseries #1
      \arabic{exerctr}}]}{\end{trivlist}\vspace{10mm}}

\newcounter{exerctr}
\newcounter{abcctr}[exerctr]

\newcommand{\abc}{\noindent\vspace{1mm}\\ {\bf
    \stepcounter{abcctr}(\alph{abcctr})\ }}
\newcommand{\bbm}{\begin{bmatrix}}
\newcommand{\ebm}{\end{bmatrix}}
\newcommand{\point}[1]{\hfill {\bf (#1p)}\\ \vspace{-5mm}}
\newcommand{\ctrb}{\EuScript{S}}
\newcommand{\Lap}{\mathcal{L}}
\newcommand{\obsv}{\EuScript{O}}
\newcommand{\realdel}[1]{\text{Re}\left\{#1\right\}}
\newcommand{\imagdel}{\text{Im}}
\newcommand{\bC}{\mathbb{C}}
\newcommand{\bR}{\mathbb{R}}
\newcommand{\bmpv}{\begin{minipage}[t]}
\newcommand{\bmps}{\begin{minipage}[t]{45mm}}
\newcommand{\bmpm}{\begin{minipage}[t]{90mm}}
\newcommand{\bmpl}{\begin{minipage}[t]{\textwidth}}
\newcommand{\emp}{\end{minipage}}
\newcommand*{\zethree}{\big(z - \mexp{-3h}\big)}
\newcommand*{\mexp}[1]{\ensuremath{\mathrm{e}^{#1}}}

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
            \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

\tikzset{
   ragged border/.style={ decoration={random steps, segment length=1mm, amplitude=0.5mm},
           decorate,
   }
}

\title{Computerized control partial exam 1 (15\%)}
\author{Kjartan Halvorsen}
\date{}

\begin{document}

\maketitle

\begin{description}
\item[Time] September 15 17:30
\item[Place] 4209
\item[Permitted aids] The single colored page with your own notes, table of Laplace transforms, calculator
\end{description}

All answers should be readable and well motivated (if nothing else is written). Solutions/motivations should be written on the provided spaces in this exam. Use the last page if more space is needed.

\begin{center}
{\Large Good luck!} \\
\end{center}

\begin{tabular}{|l|l|}
\hline
\multicolumn{2}{|l|}{\bmpl
Matricula and name
\vspace*{18mm}
\emp}\\
\hline

\end{tabular}

\clearpage
%-----------------------------------------------------------------
\subsection*{The system}
The drawing in figure \ref{fig:apollo-sketch} shows the Apollo Lunar Module (used to put Neil Armstrong and Buzz Aldrin on the moon July 21 1969). The input signal is the thrust of the attitude thrusters. These thrusters causes an angular acceleration of the Lunar Module, which integrated twice gives a change in its orientation $\theta$.  When the Lunar Module makes an angle to the vertical ($\theta \neq 0$) then the main thrusters will give a horizontal force component and thus an acceleration in the $x$-direction.
\begin{figure}[hbtp]
\begin{center}
  \includegraphics[width=0.6\linewidth]{apollo-2.png}
\end{center}
\caption{Horizontal movement of the Apollo Lunar Module is obtained by tilting the module with respect to vertical.}
\label{fig:apollo-sketch}
\end{figure}

The plant model is described by the block diagram
\begin{center}
  \includegraphics[width=0.9\linewidth]{apollo-block}
\end{center}
Note that the angular velocity is measured using a gyroscope and used in an inner feedback controller. The open-loop transfer function of the plant from the signal $u$ (the control signal to the attitude thrusters) to the  horizontal velocity $v(t)$ is $G(s)=  \frac{k_1k_2}{s^2(s+k_1k_3)}$. For simplicty, assume $k_1=k_2=1$ and $k_3=2$.

\subsection*{Problem 1}

Discretize the system using zero-order-hold (step-invariant) sampling for arbitrary sampling interval $h$.

What is the relationsship between the poles of the continuous-time system and the poles of the corresponding discrete-time system when doing zero-order-hold sampling?

\noindent
\fbox{
\bmpl
{\bf Derivation and discussion of relationship between the continuous-time and discrete-time poles:}\\
\vspace*{\textheight}
\emp}

\subsection*{Problem 2}

In the rest of the exam, we have $k_3=0$, so there is no inner feedback from the gyro signal.  With a particular choice of sampling period $h$, the following error feedback controller is proposed for the system
\[ F(z) = K\frac{0.72 z^2 - 1.3 z + 0.60}{z^2 + 0.48 z + 0.10}. \]
\begin{center}
    \begin{tikzpicture}[scale = 0.6, node distance=20mm, block/.style={rectangle, draw, minimum width=15mm}, sumnode/.style={circle, draw, inner sep=2pt}]

      \node[block] (plant) {$H(z)$};
      \node[block, left of=plant, node distance=30mm] (controller) {$F(z)$};
      \node[sumnode, left of=controller, node distance=20mm] (refsum) {\tiny $\sum$};
      \node[coordinate, left of=refsum, node distance=22mm] (refinput) {};
      \node[coordinate, right of=plant, node distance=22mm] (output) {};

      \draw[->] (refinput) -- node[above] {$v_{ref}(kh)$} (refsum);
      \draw[->] (refsum) -- node[above] {} (controller);
      \draw[->] (controller) -- node[above] {$u(kh)$} (plant);
      \draw[->] (plant) -- node[coordinate] (measure) {} node[above, pos=0.8] {$v(kh)$} (output);
      \draw[->] (measure) -- ++(0,-18mm) -| node[right, pos=0.95] {$-$} (refsum);
     \end{tikzpicture}
   \end{center}

The root locus of the system w.r.t~the gain $K$ is given below
\begin{center}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] at (0,0) {\includegraphics[width=0.6\linewidth]{apollo_rst_rlocus-crop}};
    \node[coordinate, pin={[pin distance=20mm] 10:{$K=2.8$}}] at (6.6,8.45) {};
\end{tikzpicture}
\end{center}

In figure~\ref{fig:step}, four different closed-loop responses to a step in the reference velocity $v_{ref}$ are shown. The different responses are for four different values of $K$. Identify (and circle) the corresponding step plot for each value of $K$ in the table below. \textbf{Motivate your choice!}

\begin{center}
\begin{tabular}{cl}
\(K\) & Step plot\\\hline
0.08 & A\hspace*{2mm} B\hspace*{2mm} C\hspace*{2mm} D\\
0.3 & A\hspace*{2mm}  B\hspace*{2mm}  C\hspace*{2mm} D\\
1.0 & A\hspace*{2mm} B\hspace*{2mm}  C\hspace*{2mm} D\\
2.5 & A\hspace*{2mm} B\hspace*{2mm}  C\hspace*{2mm} D\\ \hline
\end{tabular}
\end{center}

\begin{figure}[t]
\begin{center}
\begin{tabular}{cc}
A & B\\
\includegraphics[width=0.4\linewidth]{apollo-step-plot-3-crop}
&\includegraphics[width=0.4\linewidth]{apollo-step-plot-1-crop}\\
C & D\\
\includegraphics[width=0.4\linewidth]{apollo-step-plot-4-crop}
&\includegraphics[width=0.4\linewidth]{apollo-step-plot-2-crop}

\end{tabular}
\caption{Step responses for different values of $K$.}
\label{fig:step}
\end{center}
\end{figure}

\noindent
\fbox{
\bmpl
{\bf Motivation:}\\
\vspace*{80mm}
\emp}

%\clearpage

\subsection*{Problem 3}
With the feedback controller of Problem 2, and using $K=1$ we obtain a loop gain $H_o(z)=F(z)H(z)$ whose Bode diagram and Nyquist diagram are given in the figure below. Mark in the figure (both the Bode diagram and the Nyquist diagram) the phase margin and the amplitude margin of the system, and give the corresponding cross-over frequencies.

\begin{center}
\includegraphics[width=\linewidth]{bode-loop-gain-exc}
\end{center}

\noindent
\fbox{
\bmpl
\begin{tabular}{ll}
Cross-over frequency: & \\[2mm]
Phase margin:&\\[2mm]
Phase cross-over frequency: &\\[2mm]
Amplitude margin: &
\end{tabular}
\emp}

\subsection*{Problem 4 - bonus problem}

What is the sampling period $h$, the Nyquist frequency $\omega_N$ and the sampling frequency $\omega_s$ used in Problem 2 and 3? Is this a reasonable sampling period, in your opinion? Motivation is required! (Bonus problem worth 5p. Full points are possible without answering this question)

\noindent
\fbox{
\bmpl
\begin{tabular}{ll}
Sampling period: & \\[2mm]
Nyquist frequency:&\\[2mm]
Sampling frequency: &\\[2mm]
{\bf Motivation}:\\[80mm]
\end{tabular}
\emp}

% A certain continuous-time transfer function is sampled using zero-order-hold with sampling period $h=1$. The resulting discrete-time system has the poles (crosses) and zero (circle) shown in the figure below.
% \begin{center}
%   \begin{tikzpicture}
%     \pgfmathsetmacro{\bbeta}{0.5*sqrt(2)}
%     \begin{axis} [
%       width=8cm,
%       height=8cm,
%       axis lines=middle,
%       axis line style={->},
%       xtick={-1, 1},
%       ytick={-1,1},
%       yticklabels={$-i$, $i$},
%       %xticklabels={$-b$, -1},
%       xmin=-2,
%       xmax=2,
%       ymin=-2,
%       ymax=2,
%       xlabel=Re,
%       ylabel=Im,
%       ]

%       \addplot [ thick,black, mark=x, mark size=4pt, only marks] coordinates { (\bbeta,\bbeta) (\bbeta,-\bbeta)};
%       \addplot [ thick,black, mark=o, mark size=4pt, only marks] coordinates { (-1,0) };

%       \addplot [ dashed,black, no marks, domain=0:360, samples=800] ( {cos(x}, {sin(x)});
%     \end{axis}
%   \end{tikzpicture}
% \end{center}
% *Determine the poles of the continuous-time system.*

% \noindent
% \fbox{
% \bmpl
% {\bf Calculation and answer:}\\
% \vspace*{40mm}
% \emp}

\clearpage

\noindent
{\bf If necessary,} you can continue your solutions on this page. Mark clearly which problem the solution corresponds to.

%\end{document}

%*****************************************************************
%*****************************************************************
\newpage
\setcounter{page}{1}

\section*{Solutions}
\subsection*{Problem 1}
   The transfer function to discretize is \(G(s) = \frac{1}{s^3}\). First calculate the step-response of the system \[Y(s) = G(s)\frac{1}{s} = \frac{1}{s^4} = \frac{1}{3!}\cdot \frac{3!}{s^4}.\] Inverse Laplace-transform gives
   \[ y(t) = \frac{1}{6} \mathcal{L}^{-1} \left\{\frac{3!}{s^4}\right\} = \frac{1}{6} t^3.\]
   Sampling $y(t)$ gives
   \[ y(kh) = \frac{1}{6} (kh)^3 =  \frac{h^3}{6} k^3 \]
   which has the Z-transform
   \[ Y(z) = \frac{h^3}{6} \cdot \frac{z(z^2 + 4z + 1)}{(z-1)^4}.\]
   Dividing the z-transform of the system response to that of the input (the step) gives
   \begin{align*}
   H(z) &= \frac{Y(z)}{U(z)} = \frac{z-1}{z}Y(z) = \frac{\frac{1}{6}(z^2 + 4z + 1)}{(z-1)^3}.
   \end{align*}

   All the three continuous-time poles are in the orgin. They are mapped to the point $z=1$ in the z-plane by $z=\mathrm{e}^{sh}$ when we use zero-order-hold sampling.

\subsection*{Problem 2}

From the root locus we see that if the gain is $K>2.8$, then the closed-loop system will have two complex-conjugated poles outside the unit circle, and the system will be unstable.  For a gain smaller but close to $K=2.8$ we should observe a response with quite fast osciallations. We know that we have three start-points in $z=1$, and we see that two complex-conjugated branches starting in $z=1$ go outside the unit circle before entering into the stable region. So for low-values of $K$ we should expect poorly damped slow oscillations, or even an unstable system. For intermediate values of $K$, we get poles well inside the unit circle, and so a well-damped response. By this reasoning we arrive at

\begin{description}
\item[$K=0.08$] Slow and oscillatory response. This must correspond to step-response B.
\item[$K=0.3$] Faster response than for $K=0.08$, still maybe oscillatory. This is seen in step-response D
\item[$K=2.5$] Should give two compled-conjugated poles that are fast ($ \omega h \approx 1.2$) and close to the unit circle. We expect fast and poorly damped oscillations with aproximately  five samples per period ($2\pi/1.2 \approx 5$). This must correspond to response C
\item[$K=1$] This leaves the intermediate value $K=1$, which gives a well-behaved and damped response: A.
\end{description}

\begin{center}
\begin{tabular}{cl}
\(K\) & Step plot\\\hline
0.08 & A\hspace*{2mm} \circled{B}\hspace*{2mm} C\hspace*{2mm} D\\
0.3 & A\hspace*{2mm}  B\hspace*{2mm}  C\hspace*{2mm} \circled{D}\\
1.0 & \circled{A}\hspace*{2mm} B\hspace*{2mm}  C\hspace*{2mm} D\\
2.5 & A\hspace*{2mm} B\hspace*{2mm}  \circled{C}\hspace*{2mm} D\\ \hline
\end{tabular}
\end{center}

\subsection*{Problem 3}

\begin{center}
\includegraphics[width=0.7\linewidth]{apollo-rst-margin-crop}
\end{center}
%\end{document}

\subsection*{Problem 4}

There are several ways to find the sampling period $h$. Maybe the easiest is to look at the step-responses in Problem 2. Clearly there are 10 samples per 10 seconds, so $h=\unit{1}{s}$. It can also be seen from the bode diagram of Problem 3 that the plot ends at the frequency $\omega \approx 3.14$, which is the Nyquist frequency. Since $\omega_N h = \pi$, then again we get $h=1$. The sampling frequency (in rad/s) is twice the Nyquist frequency, or $\omega_s = \frac{2\pi}{h} = 2\pi$.

Is this sampling frequency reasonable? The step-response A in Problem 2 reaches the peak. \unit{1.4}{\meter\per\second} after \unit{6}{\second}.
which corresponds to an acceleration of approximately 0.2 m/s$^2$.%\unit{0.2}{\meter\per\second\square}.
This is about 12\% of the gravitational acceleration on the moon
(\unit{1.622}{\meter\per\second\squared}).
Since the horizontal force comes from the horizontal component of the main thrusters, this means that the module is tilted $\tan^{-1} 0.12 = \unit{7}{\degree}$. Which seems reasonable. On the other hand, in this response we have less than the recommended number of sampling periods per rise time (rule-of-thumb says 4-10). So maybe the sampling period it is a little too long. Half a second is probably better.

\end{document}


\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{caption}
\usepackage[margin=1in]{geometry}

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

\title{Applied Statistics Problem Set}
\author{Student name}
\date{3rd of January 2021}

\begin{document}

\maketitle

I have worked with student A (All problems), student B (problem 1.2) and student C (problem 1.3).

%%%%%%%%%%%%%%%% PART I %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{I - Distributions and probabilities}

This is a template for the problem set and exam hand in for Applied Statistics. Please submit one pdf file with your solutions, with answers \textbf{\underline{bolded and underlined}} where relevant.
%
All tables and figures should be easy to read and clearly referenced. There's no page limit, but it should be possible to keep it under 10-15 pages, especially if you want the TAs to stay happy!
%
There is no need to submit or show any code (unlike for the exam, where this should be submitted separately), just your answers. Finally, please state who you worked with at the top of the report, but remember that your answers should be your own.

\subsection*{Problem 1.1} You can add sub sections for questions here.

\subsubsection*{1.1.1} $N_3$ follows X distribution, since...

\subsubsection*{1.1.2} The probability can be calculated as follows...

% ----------------------------------------------------------------------
\subsection*{1.2}
More answers here.

%%%%%%%%%%%%%%%% PART II %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{II - Error Propagation}
You can add equations, like so, in Equation \ref{eq1}:

\begin{equation}
    \chi ^{2} = \sum \frac{(model-data)^{2}}{error^{2}}
    \label{eq1}
\end{equation}

\subsection*{Problem 2.1}
\subsubsection*{2.1.1} The uncertainty...

%%%%%%%%%%%%%%%% PART III %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{III - Monte Carlo}
You can add figures, like so, in Figure \ref{fig1} (they may not go exactly where you want - that's alright).

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.25]{Troels_InOffice.jpg}
    \caption{``A friendly man'' [Katriona Gould]}
    \label{fig1}
\end{figure}

\section*{Problem 3.1}
You can also create Tables, like so:

\begin{table}[hbtp!]
\begin{centering}
\begin{tabular}{ |c|c|c|c| }
  \hline
  Data & $\mu$ & $\sigma$ & N\\
  \hline
  \textbf{Data1} & 0.0 & 1.0 & 100 \\
  \textbf{Data2} & 0.0 & 1.0 & 100 \\
  \hline
\end{tabular}
\caption{Mean ($\mu$), standard deviation ($\sigma$) and data set length (N) for two different data sets.}
\label{tab:cleaned}
\end{centering}
\end{table}

Finally, it makes for easier reading, if you include colors, for example between \textcolor{red}{sample A} and \textcolor{blue}{sampel B}, but that is of course just an option.

%%%%%%%%%%%%%%%% PART III %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{III - Monte Carlo}

%%%%%%%%%%%%%%%% PART IV %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{IV - Statistical tests}

%%%%%%%%%%%%%%%% PART V %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section*{V - Fitting data}

%%%%%%%%%%%%%%%% Bibliography %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\bibliography{}
%Roger Barlow: Statistics: A guide to the use of statistics.

\end{document}


\documentclass{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{amssymb}

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ (\hmwkClassInstructor\ \hmwkClassTime): \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Problem \arabic{#1} (continued)}{Problem \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Problem \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Problem \arabic{homeworkProblemCounter}}{}\nobreak{}

%
% Homework Problem Environment
%
% This environment takes an optional argument. When given, it will adjust the
% problem counter. This is useful for when the problems given for your
% assignment aren't sequential. See the last 3 problems of this template for an
% example.
%
\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Problem \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

%
% Homework Details
%   - Title
%   - Due date
%   - Class
%   - Section/Time
%   - Instructor
%   - Author
%

\newcommand{\hmwkTitle}{Homework\ \#4}
\newcommand{\hmwkDueDate}{February 7th, 2017}
\newcommand{\hmwkClass}{Elements of Algebra I}
\newcommand{\hmwkClassTime}{Section 161}
\newcommand{\hmwkClassInstructor}{Professor Deepam Patel}
\newcommand{\hmwkAuthorName}{Yao Xiao}

%
% Title Page
%

\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass:\ \hmwkTitle}}\\
    \normalsize\vspace{0.1in}\small{Due\ on\ \hmwkDueDate\  }\\
    \vspace{0.1in}\large{\textit{\hmwkClassInstructor\ \hmwkClassTime}}
    \vspace{3in}
}

\author{\textbf{\hmwkAuthorName}}
\date{}

\renewcommand{\part}[1]{\textbf{\large Part \Alph{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large Solution}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle

\pagebreak

\begin{homeworkProblem}
1.\\a) \(GL_n(\mathbb{R}) \) it has an inverse because it's an invertible matrix, and also the product of two real numbers is a real number so the product of two real numbers matrix is a real number matrix. The identity matrix is invertible as well\\
b) it's a sub group, since multiplication of 1,-1 is closed under \( \{1,-1\} \), and identity 1 \( \in \{1,-1\} \) , and also \(\{1^{-1},-1^{-1}\} \) is in \( \{1,-1\} \)\\
c) it's not a subgroup, since the inverse of positive integer is not positive
\end{homeworkProblem}

\begin{homeworkProblem}
a) \( Z_2 * Z_2 * Z_2 \), since there's no generator \\
b) \( Z_2 * Z_2 = \{  (0,1), (0,0), (1,0), (1,1) \} \) Since no elements to itself will equal to (1,1)
\end{homeworkProblem}

\begin{homeworkProblem}
For \(k \in \mathbb{Z}_8 \) , gcd(8, k) = 1, k = 1, 3, 5, 7
For \(k \in \mathbb{Z}_{20} \) , gcd(20, k) = 1,  k = 1, 3, 7, 9, 11, 13, 17, 19
\end{homeworkProblem}

\begin{homeworkProblem}
Let the order of ab be n, so
 \[\begin{split}
(ab)^n=e\\
 (ab)(ab)(ab)...(ab)=e\\
 a(ba)(ba)(ba)(ba)....(ba)b=e\\
 a^{-1}a(ba)(ba)(ba)(ba)....(ba)ba=e\\
 (ba)^n=e
 \end{split}\]
 So ba has an order of n too.
\end{homeworkProblem}

\begin{homeworkProblem}
We must show that g is close. So assume
 \[\begin{split}
a,b \in Z, g \in G, g^{-1} \in G\\
ag=ga\\
bg=gb\\
ag^{-1}=g^{-1}a\\
bg^{-1}=g^{-1}b\\
abgg^{-1}=agbg^{-1}=agg^{-1}b=gag^{-1}b=gg^{-1}ab
 \end{split}\]
 so ab is close under Z.
Let \( a \in Z\) n. a has an
inverse \(a^{-1} \in G \)  \\
we want to show that \(a^{-1} \in Z\) \\
let \( g, g^{-1} \in G\)
 \[\begin{split}
(g^{-1}a^{-1}g)^{-1}=g^{-1}ag=g^{-1}ga=a
 \end{split}\]
 Which implies \(g^{-1}a^{-1}g=a^{-1}\), multiply \(g^{-1}\) on the both sides, we get  \(g^{-1}a^{-1}=a^{-1}g^{-1}\). So \(a^{-1} \in Z\)

\end{homeworkProblem}

\begin{homeworkProblem}
\[\begin{split}
|g^k|=\frac{n}{gcd(n,k)}\\
gcd(40,k)=40/10=4\\
 \end{split}\]
So all elements in Z40 has a gcd of 4 is the answer, which is 4,12,28,36. Respectively, \(x^4,x^{12},x^{28},x^{36}\) are the elements of order 10.

\end{homeworkProblem}

\begin{homeworkProblem}
We could show that kr=n. So a cyclic group of order n is equal to a group of \(\{e^0,e^1,e^2...e^{n-1} \} \). We could easily find a subgroup with an order r. \(\{e^0,e^k,e^(2k)...e^{k(r-1)} \} \) We assume there's another group which has an order of r, namely G'. And we could tell that G'=\(<k'>\) and k'r=n. But according to division theory, there exists only unique integers q,r such that a=qb+r , so k=k'.
\end{homeworkProblem}

\begin{homeworkProblem}
We assume that  \(d=gcd(n',n)>1\). Then \(k=\frac{n'n}{d}\) is an integer since n/d is an integer, as a result every element of \(Z_n * Z_m\) has an order dividing k, and it can't be cyclic because of that.

When  \(d=gcd(n',n)=1\), then  \(k=\frac{n'n}{d}=nn'\), so \(<1,1>\) could be the generator of the group so it's cyclic.
\end{homeworkProblem}

\end{document}