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

\title{CS131 B1: HW 4}
\author{Duy Nguyen}
\date{10 October 2016}

\begin{document}

\maketitle

\section*{Question 1}
\subsection*{a.$\forall x \forall y P(x,y)$}
When $ x \neq y $ the statement is \textbf{false}.
\subsection*{b.$\forall x \exists y P(x,y)$}
When $ x = 0 $ there is no $y$ where $ \frac{0}{y} = 1$. \textbf{False}.
\subsection*{c.$\exists x \forall y P(x,y)$}
There is not an $x$ where it could satisfy the condition. Alternatively, $y=0$ would blow up the statement for every $x$. \textbf{False}.
\subsection*{d.$\exists x \exists y P(x,y)$}
When $x = y$, and $y \neq 0$, the statement is true\textbf{true}.

\section*{Question 2}
\subsection*{a. $\exists x \forall y (x+y=y)$}
There exists an $x$ such that for every $y$, $x + y = y$.

This is \textbf{true} when $ x = 0$.

\subsection*{b. $\forall x \forall y ((x \geq 0) \land (y < 0) \rightarrow (x - y > 0))$}

For all $x$ greater or equal to zero, and $y$ which is a negative number, $x - y > 0$.

Since $x > y$, the equation $x - y$ is greater than 0. \textbf{True}.

\subsection*{c. $\forall x \forall y ((x \neq 0) \land (y \neq 0) \leftrightarrow (xy \neq 0))$}

For all $x$ and $y$ beside zero, their product is not zero.

Since there is no zero being multiply, the result could not be zero. Thus the statement is \textbf{true}.

\section*{Question 3}
\subsection*{a. Any person who is a female and a parent, is a mother of someone.}

\begin{tabular}{rl}
    Define: & $x$ is a person \\
            &    $y$ is another person \\
            &    $F(x)$ is a female person \\
            &    $P(x)$ is a parent \\
            &    $M(x,y)$ said x is the mother of y
\end{tabular}

Then we have:

$$\forall x \exists y (F(x) \land P(x) \rightarrow M(x,y))$$

\subsection*{b. There are people who are friends with everyone, people who have some friends, and
people who have no friends.}

\begin{tabular}{rl}
    Define: & $a, b, c, x$ are people \\
            & $F(x, y)$ said that x is friend with y
\end{tabular}

Then we have:
$$ (\exists a \forall x F(x, y)) \land
(\exists b \exists x F(x, y) \land
(\exists c \forall x \neg F(x,y))$$

\subsection*{c. For every real number $C>0$, there exists $\epsilon > 0$, such that $f(x) > C$ whenever $0 < x < \epsilon$.}

\begin{tabular}{rl}
    Define: & $C$ is a real number $> 0$ \\
    & $\epsilon$ is a small real number $>0$\\
    & $x$ is a real number \\
    & $f(x)$ is a function on x
\end{tabular}

Then we have that:
$$ \forall C \exists \epsilon (0 < x < \epsilon) \rightarrow (f(x) > C)$$

\subsection*{d. Negation of the previous statement in logical form and in English.}
$$ \forall C \exists \epsilon (0 < x < \epsilon) \rightarrow (f(x) > C)$$

Negated:

$$ \exists C \forall \epsilon \neg ((0 < x < \epsilon) \rightarrow (f(x) > C))$$
$$ \exists C \forall \epsilon ((0 < x < \epsilon) \land \neg (f(x) > C))$$
$$ \exists C \forall \epsilon ((0 < x < \epsilon) \land (f(x) \leq C))$$

There exists $C$, a real number greater than $0$ where for all $\epsilon$: $x$ is between $0$ and $\epsilon$, and  $f(x)$ is less or equal to $C$
\end{document}


\documentclass[12]{scrartcl}
\usepackage{amssymb,amsmath,gensymb,dsfont,calc,multicol,fullpage}
\makeatletter
\newcommand\Aboxed[1]{
   \@Aboxed#1\ENDDNE}
\def\@Aboxed#1&#2\ENDDNE{%
   &
   \settowidth\@tempdima{$\displaystyle#1{}$}
   \setlength\@tempdima{\@tempdima+\fboxsep+\fboxrule}
   \kern-\@tempdima
   \boxed{#1#2}
}
\makeatother

\begin{document}

\title{Homework 7, 2.2: 1(b,d,f), 3(a,f), 4(a), 7(b,c,d), 8, 12, 15, 21(extra credit) }
\author{Alex Gordon}
\date{\today}
\maketitle
\section*{Homework}
\subsection*{1. B)}
$187 = 17 \times 11 + 0$
\subsection*{1. D)}
$-24 = -6 \times 4 + 0$
\subsection*{1. F)}
$(9k^2 + 5) = (3k^2 + 5)3 + 1 $
\subsection*{3. A)}
$55 = 9 \times 6 + 1$
\subsection*{3. F)}
$(3k^4 - k^2 - 10k + 3)3 + 2$
\subsection*{4. A)}
If a is 12, b is 6 and c is 3, then \ $a \mod b \ and \ b \mod c \ but \ b \neq$ a
\subsection*{7. B)}
If b/a and c/a then $\frac{a^2/}{b \times c}$. First, if a divides b and a divides c, then by the closure properties b and c must be multiples of a. Again, by the closure properties, since a(a) = $a^2$ then that result is a multiple of a. If b and c are multiples of a, then by the closure properties, b $\times$ c is a multiple of a. If b(c) is a multiple of a, then it naturally follows that a divides b(c).
\subsection*{7. C)}
If a divides b and c divides d then ac divides bd. If a divides b then b must be a multiple of a. If c divides d then d must be a multiple of c. It then naturally follows that $a \times c$ is a multiple of c and and it also naturally follows that  $b times d$ is a multiple of d. Because of that, in the equation $\frac{ac}{bd}$ a/b leaves a remainder of 0 and c/d leaves a remainder of 0 and by the closure properties that means that there is a remainder of 0 meaning bd divides ac.
\subsection*{7. D)}
If $c$ divides $a$ then $a$ is a multiple of $c$. Therefore, for any integer x, and the problem  $\frac{ax}{cx}$ the $x$'s simply cancel out to $\frac{a(1)}{c}$
\subsection*{8.}
1) a is rational
2) b is rational
3) xw + yz
4)xw + yz
5) w $\neq$ 0
6) y $\neq$ 0
\subsection*{12.}
If $x$ is any integer, then $x = x(1)$, and so $x = \frac{x}{1}$. If x = $\frac{x}{1}$, then $x$ and 1 are both integers and 1 $\neq$ 0. Thus, $x$ can be written as a quotient of integers with a nonzero denominator, meaning $x$ is rational.
\subsection*{15.}
$x$ is divisible by 3, thus $x = 3a$ for some integer a. Similarly, $x = 4b$ for some integer b. It then follows that if you multiply $x = 3a$ by 4 and get $4x = 12a$ and you multiply $x = 4b$ by 3 and get $3x = 12b$ then
\begin{align*}
x &= 4x = 3x = 12a - 12b = 12(a-b)
\\  c &= (a-b)
\\x &= 12c
\end{align*}
Therefore, x is divisible by 12.
\subsection*{21.}
Prove that no perfect square ends in the digit 2. Let x be equal to any integer. Let  a "perfect square" = $x^2$. Since $x^2$ equals $x(x)$ then if $x(x) = y$ then the $\sqrt{y}$ must equal an integer. Therefore because the $\sqrt{2}$ is not an integer, and $x(\sqrt{y})$ is not an integer, then no perfect square root can ever end in 2.
\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UMB-CS114-2015F: Introduction to Programming in Java
% Copyright 2015 Pejman Ghorbanzade <pejman@ghorbanzade.com>
% Creative Commons Attribution-ShareAlike 4.0 International License
% More info: https://github.com/ghorbanzade/UMB-CS114-2015F
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def \topDirectory {../..}
\def \texDirectory {\topDirectory/src/main/tex}

\documentclass[10pt, compress]{beamer}

\usepackage{\texDirectory/template/style/directives}
\input{\texDirectory/template/config}
\usepackage{\texDirectory/template/style/beamerthemeUmassLecture}
\doc{number}{6}
%\setbeamertemplate{footline}[text line]{}

\begin{document}
\prepareCover

\section{Course Administration}

\begin{slide}
	\begin{itemize}
		\item[] Student Forum now available in \href{http://www.ghorbanzade.com}{Course Website}.
		\item[] 37/40 user accounts at \href{http://www.ghorbanzade.com}{Course Website} created so far.
	\end{itemize}
\end{slide}

\begin{slide}
	\begin{block}{Overview}
		\begin{itemize}
			\item[] Class Math
			\item[] Data Conversion
		\end{itemize}
	\end{block}
\end{slide}

\section{Class Math}

\begin{slide}
	Class Math provides methods to perform basic numeric operations, efficiently.
	\begin{block}{Fields}
		\begin{columns}
			\begin{column}{0.5\textwidth}
				\begin{itemize}
					\item[] Neperian Number
				\end{itemize}
			\end{column}
			\begin{column}{0.5\textwidth}
				\begin{itemize}
					\item[] Pi Number
				\end{itemize}
			\end{column}
		\end{columns}
	\end{block}
	\begin{block}{Methods}
		\begin{columns}
			\begin{column}{0.5\textwidth}
				\begin{itemize}
					\item[] abs(a)
					\item[] floor(a)
					\item[] ceil(a)
					\item[] round(a)
					\item[] sqrt(a)
					\item[] cbrt(a)
				\end{itemize}
			\end{column}
			\begin{column}{0.5\textwidth}
				\begin{itemize}
					\item[] sin(a)
					\item[] asin(a)
					\item[] sinh(a)
					\item[] cos(a)
					\item[] acos(a)
					\item[] cosh(a)
				\end{itemize}
			\end{column}
		\end{columns}
	\end{block}
\end{slide}

\begin{slide}
	\begin{block}{Methods (cont'd)}
		\begin{columns}
			\begin{column}{0.5\textwidth}
				\begin{itemize}
					\item[] exp(a)
					\item[] log(a)
					\item[] tan(a)
					\item[] atan(a)
					\item[] atan2(a)
					\item[] tanh(a)
				\end{itemize}
			\end{column}
			\begin{column}{0.5\textwidth}
				\begin{itemize}
					\item[] max(a, b)
					\item[] min(a, b)
					\item[] pow(a, b)
					\item[] random()
					\item[] toRadians(a)
					\item[] toDegrees(a)
				\end{itemize}
			\end{column}
		\end{columns}
	\end{block}
	\begin{block}{Usage}
		\begin{minted}[fontsize=\small,tabsize=8]{java}
			double randomNum = Math.random();
			int upperBound = Math.ceil(randomNum);
			int lowerBound = Math.floor(randomNum);
		\end{minted}
	\end{block}
\end{slide}

\begin{slide}
	\begin{block}{How random is Math.random()?}
		Method Math.random() is a little biased. We will discuss better alternatives later.
	\end{block}
	\begin{block}{Method Math.random()}
		\begin{minted}[fontsize=\small,tabsize=8]{java}
			double randomNum1 = Math.random();
		\end{minted}
		Output is always less than or equal to zero and less than one. What if we want a random number between $x$ and $y$?
		\begin{minted}[fontsize=\small,tabsize=8]{java}
			double randomNum2 = x + (y-x) * Math.random();
		\end{minted}
	\end{block}
\end{slide}

\section{Data Conversion}

\begin{slide}
	\begin{itemize}
		\item[] All variables should be declared only once.
		\item[] Variables of a declared type can be assigned values of that type.
	\end{itemize}
	\begin{block}{Converting Primitive Types to String}
		\begin{minted}[fontsize=\small,tabsize=8]{java}
			int a = 64;
			double b = 124.52;
			boolean c = false;
			String strA = String.valueOf(a);
			String strB = String.valueOf(b);
			String strC = String.valueOf(c);
		\end{minted}
	\end{block}
\end{slide}

\begin{slide}
	\begin{block}{Explicit Type Conversion}
		\begin{minted}[fontsize=\small,tabsize=8]{java}
			String strA = "64";
			String strB = "124.52";
			String strC = "false";
			int a = Integer.parseInt(strA);
			double b = Double.parseDouble(strB);
			boolean c = Boolean.parseBoolean(strC);
		\end{minted}
		Many methods perform a type conversion by receiving input of one type and giving output of another type.
	\end{block}
\end{slide}

\begin{slide}
	\begin{block}{Explicit Type Casting}
		\begin{minted}[fontsize=\small,tabsize=8]{java}
			double a = 124.52;
			int b = (int) a;
			int c = (int) a + b;
			int d = (int) (a + b);
		\end{minted}
		Type casting has higher precedance than other operations. Beware! Type casting may involve information loss.
	\end{block}
\end{slide}

\begin{slide}
	\begin{block}{Automatic Promotion}
		\begin{minted}[fontsize=\small,tabsize=8]{java}
			int a = 5;
			int b = -15;
			int c = 9;
			double discriminant = Math.pow(b,2) - 4 * a *c;
		\end{minted}
		Java automatically promotes data types where it assumes we have been light-headed. In above example, variables a, b and c will first be converted to type double and then other operations are performed. Automatic promotion is safe as it doesn't involve information loss.
	\end{block}
\end{slide}

\plain{}{Keep Calm\\and\\Practice}

\end{document}


\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{amssymb}
\usepackage{courier}
\usepackage{fancyhdr}
\usepackage{fancyvrb}
\usepackage[top=.75in, bottom=.75in, left=.75in,right=.75in]{geometry}
\usepackage{graphicx}
\usepackage{lastpage}
\usepackage{listings}
\lstset{basicstyle=\small\ttfamily}
\usepackage{mdframed}
\usepackage{parskip}
\usepackage{soul}
\usepackage{tabularx}
\usepackage{textcomp}
\usepackage{upquote}
\usepackage{xcolor}

% http://www.monperrus.net/martin/copy-pastable-ascii-characters-with-pdftex-pdflatex
\lstset{
upquote=true,
columns=fullflexible,
keepspaces=true,
literate={*}{{\char42}}1
         {-}{{\char45}}1
         {^}{{\char94}}1
}
\lstset{
  moredelim=**[is][\color{blue}\bf\small\ttfamily]{@}{@},
}

% http://tex.stackexchange.com/questions/40863/parskip-inserts-extra-space-after-floats-and-listings
\lstset{aboveskip=6pt plus 2pt minus 2pt, belowskip=-4pt plus 2pt minus 2pt}

\usepackage[colorlinks,urlcolor={blue}]{hyperref}
\usepackage[capitalise,nameinlink,noabbrev]{cleveref}
\crefname{section}{Question}{Questions}
\Crefname{section}{Question}{Questions}

\begin{document}

\fancyfoot[L]{\color{gray} C4CS -- F'17}
\fancyfoot[R]{\color{gray} Revision 1.0}
\fancyfoot[C]{\color{gray} \thepage~/~\pageref*{LastPage}}
\pagestyle{fancyplain}

\title{\textbf{Homework 11\\Debugging}}
\author{\textbf{\color{violet}{Solutions}}}
\date{}
\maketitle

\setcounter{section}{1}
\section{Finding primes}

\subsection{Debugging with \texttt{gdb}}

\emph{You may find it helpful to consult the
  \href{http://c4cs.github.io/static/lecture/wk7-gdb.pdf}{gdb lecture notes}
  or this
  \href{https://ccrma.stanford.edu/~jos/stkintro/Useful_commands_gdb.html}
  {quick command reference}.
}

First, make sure you are on the \texttt{gdb-debug-1} branch:
\begin{lstlisting}
@>@ git branch
  master
* gdb-debug-1
\end{lstlisting}

Next, build and run the supplied program:
\begin{lstlisting}
@>@ make
@>@ ./prime
Find all prime numbers between 3 and ?
10
Segmentation fault (core dumped)
@>@ gdb -q ./prime
Reading symbols from ./prime...done.
(gdb) run
Starting program: /media/sf_prime/prime
Find all prime numbers between 3 and ?
10

Program received signal SIGSEGV, Segmentation fault.
0x000000000040068f in check_prime (k=3) at check.c:15
@15      if (is_prime[j] == 1)@
\end{lstlisting}

\textbf{Explain in what case(s) executing this line of code could cause a
  segmentation fault?}
\begin{quote}
  \color{violet}
  This question is asking only about this specific line of code, not all of
  the things that could possibly cause segmentation faults.

  This is an array access, which is a fancy way of dereferencing a pointer.
  Since we are in C, \texttt{is\_prime[j]} is the exact same as
  \texttt{*(is\_prime + j)}.

  This means that this line of code could cause a segmentation fault if the
  value \texttt{is\_prime + j} does not point to a valid memory address.
  %
  This is most likely to happen if \texttt{is\_prime} is not a valid pointer
  or \texttt{abs(j)} is an enormous value.

  \emph{Worth Noting: While a value of \texttt{j=-1} is very likely incorrect,
    it is unlikely to cause a segmentation fault. It will simply point to a
    different, nearby variable in the program's memory space. The fact that
    bugs like this do not cause crashes (at least not immediately) can make
    them hard to track down.}
\end{quote}

\textbf{What gdb commands could you run next to prove your hypothesis right or
  wrong?}
\begin{quote}
  \color{violet}
  Either \texttt{print is\_prime} or \texttt{ptype is\_prime} to learn the
  size of the array, then \texttt{print j} to learn whether \texttt{j} is
  valid.

  Asking gdb to \texttt{print is\_prime[j]} will directly show that the memory
  pointed to is inaccessible.
\end{quote}

\vspace{2cm}
% Fun fact: This was a "real" bug, that is, when I was writing this assignment
% I made a mistake and used the debugger to track it down
Now checkout \texttt{gdb-debug-2}:
\begin{lstlisting}
@>@ git checkout gdb-debug-2
@>@ make
@>@ ./prime
Find all prime numbers between 3 and ?
10
3 is a prime
5 is a prime
7 is a prime
@9 is a prime@
\end{lstlisting}
\textbf{Copy your debugging session and add notes explaining your
  thought process as you track down why this program thinks 9 is a prime.}\\
\emph{\small Hint: It looks like things go well up until 9. A good place to
  start then may be to break in and observe how the code determines whether 9
  is a prime number.}

\begin{quote}
  \begin{lstlisting}
    $ gdb -q ./prime
    Reading symbols from ./prime...Reading symbols from [...] ...done.
    done.

    @Things go well up until checking if 9 is prime, so jump there@
    (gdb) break check_prime if k==9
    Breakpoint 1 at 0x100000e87: file check.c, line 13.
    (gdb) run
    Starting program: /private/tmp/debugging-basics/prime
    Find all prime numbers between 3 and ?
    10
    3 is a prime
    5 is a prime
    7 is a prime

    Breakpoint 1, check_prime (k=9) at check.c:13
    13    for (j=2; j*j <= k; j++) { @expect to run this loop for j=2 and j=3@

    @There's not a whole lot going on in this loop. As we move through it, the
    only variable that changes is j. (We can infer the values of things like
    is_prime[j] based on the path the code takes, though you could certainly
    print those values as well if you like)@
    (gdb) display j
    1: j = 0
    (gdb) step
    14      if (is_prime[j] == 1) @expect this to be true, as 2 is prime@
    1: j = 2
    (gdb) <enter> @repeats last command, in this case step@
    15        if (k % j == 0)  { @9 % 2 isn't 0@
    1: j = 2
    (gdb) <enter>
    19      j++; @okay, onto the next iteration of the loop@
    1: j = 2
    (gdb) <enter>
    13    for (j=2; j*j <= k; j++) { @starting off the loop for j=3@
    1: j = 3
    (gdb) <enter>
    23    is_prime[k] = 1; @wait, we just dropped out of the loop, and j is 4@
    1: j = 4
    (gdb)
    @Key thing to notice: The loop body never executed for j=3. Why? j was
    incremented twice, once at the end of the body of the for loop, and once
    by the declaration of the for loop. This double-increment is the bug.@
  \end{lstlisting}
\end{quote}

\vfill
\hrule
{\footnotesize
This homework is based off of a simplified and updated version of this gdb
tutorial:
\url{http://heather.cs.ucdavis.edu/~matloff/UnixAndC/CLanguage/Debug.html}
If you would like some more practice, or simply a slightly different
explanation of the material, this may be a good source.
}

\newpage
\section{Valgrind}

\textbf{Notice that ``3 is a prime'' printed before this warning. Why was this
  warning not emitted when running \texttt{check\_prime(3,~\dots)}?}
\begin{quote}
  \color{violet}
  Valgrind detects errors at run time. For \texttt{check\_prime(3,~\dots)},
  the for loop check \texttt{j*j~$<=$~k} (\texttt{2*2~$<=$~3}) fails and
  the body of the loop is never entered. This means \texttt{is\_prime[j]}
  (\texttt{is\_prime[2]}) never runs, which means valgrind does not detect
  the error.

  The key takeaway here is that because of how valgrind works, it can only
  catch an error when it actually happens.
\end{quote}

\hrule
\begin{lstlisting}
@>@ valgrind --vgdb=yes --vgdb-error=0 ./prime
\end{lstlisting}
In another terminal, follow the directions that valgrind prints to connect
gdb. In this case, valgrind has already `run' the program for you and inserted
a breakpoint at the very beginning of the program, we just need to `continue'
it. The program will run until valgrind encounters an issue, at which point
valgrind will automatically break for you.
\begin{lstlisting}
@(gdb)@ continue

valgrind terminal:
==23589== Conditional jump or move depends on uninitialised value(s)
==23589==    at 0x400623: check_prime (prime.c:32)
==23589==    by 0x4006C4: main (prime.c:52)
==23589==
@==23589== (action on error) vgdb me ...  # this is where valgrind waits for gdb@

gdb terminal:
Program received signal SIGTRAP, Trace/breakpoint trap.
0x0000000000400623 in check_prime (k=5, is_prime=0xffefff910) at prime.c:32
@32      if (is_prime[j] == 1)   # this is the problematic line of code@
\end{lstlisting}

~

\textbf{What is the value of \texttt{j} at this point?}
\begin{quote}
  \color{violet}\tt
  (gdb) print j\\
  j = 2
\end{quote}

\textbf{What is the value of \texttt{is\_prime[j]} at the point?}
\begin{quote}
  \color{blue}\tt
  (gdb) print is\_prime[j]\\
  = -16777744 $\leftarrow$ This will be a garbage value and vary person to person
\end{quote}

\textbf{Use git to look at the most recent commit. What line of code was
  deleted that should not have been?}

\begin{quote}
  \begin{lstlisting}
$ git log -p

[... trim some output ...]

  int main() {
+       int is_prime[MAX_PRIMES];
+       int upper_bound;
        int N;

        printf("Find all prime numbers between 3 and ?\n");
        scanf("%d", &upper_bound);

@-       is_prime[2] = 1;@
-
        for (N = 3; N <= upper_bound; N += 2) {
-               check_prime(N);
+               check_prime(N, is_prime);
                if (is_prime[N])
                        printf("%d is a prime\n",N);
  }
  \end{lstlisting}
\end{quote}

\end{document}


\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\begin{document}
\title{Linear Quadratic Gaussian (LQG) Control Lecture Notes}
\author {Ahmad Hamdan}
\maketitle
\newpage
\section*{Introduction}
Liner quadratic Gaussian control problem is one of the basic optimal control problem in control theory engineering. This problem cover liner systems derived by additive white Gaussian noise phenomena. The challenge is to evaluate the performance of output feedback law of the controller in term of quadratic cost function with some Gaussian noise involvement in output measurements which is Gaussian random vector.
\section*{Fundamentals}
Following are the three essential points :\\

•	Concerned with Liner system\\

•	Minimization of quadratic cost function as main criterion\\

•	External perturbations are Gaussian noise
\section*{Solution to control problem}
Under defined assumptions, optimal control solution can be determined in form of control law which is LQG controller. That is simply a hybrid combination of state estimator and state feedback. The state estimator is known as kalman filter or liner quadratic state estimator and state feedback is known as linear quadratic regulator.\cite{aastrom2012introduction}

\begin{figure}[h]
  \centering
  \includegraphics[width=2.99 in]{l.PNG}
  \caption{Schematic block diagram}\label{1}
\end{figure}

As shown in Figure \ref{1}, the state space model control of  plant by feedback gain 'K' and observer gain 'L'.\cite{eide2011lqg}
\section*{Design principle}
As this LQG control law determined by arrangement of two techniques so state estimator and state feedback can be designed independently stated by separation principle of design. LQG control is easily applied on linear time varying system and linear time invariant system and account for linear dynamic feedback control law.\cite{lindquist1973feedback}
\section*{Limitations}
Dimension of system state is the main parameter which can describe the limitations of LQG control law. If dimension of system state is large then problems may be occur during the implementation of classical LQG controller. \cite{georgiou2013separation} \cite{van2000numerical}
\section*{Rectification}
The limitations regarding large dimension state can be rectified as reduced order LQG problem known as fixed order LQG problem. In which number of states of LQG controller is fixed prior. Although solution is not unique however numerical algorithms are available to find optimal projection equations which establish locally optimized reduced order LQG controller.\cite{georgiou2013separation} \cite{van2000numerical}
\section*{Robustness of LQG controller}
Optima of the LQG doesn't necessarily guarantee robust stability. After design of the LQG controller, the rigorous stability including its closed system will be evaluated individually for performance analysis. Stochastic analysis is must instead of deterministic behavior of system parameters for robust stability. Therefore, optimal gains can be derived by computing the expected value of cost function. The perturbed nonlinear system can also be control by LQG. \cite{van1999optimal}
\section*{Mathematical representation of problem}
we have an arbitrary linear dynamic system with continuous time\\
\begin{equation}
\frac{d}{dt}
x(t) = A(t)x(t) + B(t)u(t) + v(t)
\end{equation}
\begin{equation}
y(t) = C(t)x(t) + w(t)
\end{equation}
where x(t) is system state variables vector, u(t) is control input vector, v(t) is the additive white Gaussian system noise, y(t) represents output vector and w(t) is the measurement white additive Gaussian noise. The aim is to find the history of control input vector u(t) which depends on past measurements at each time step 't'.\cite{bernstein1986optimal}

\begin{equation}
J = E[x^T (T) Fx (T)+\int_{0}^{T}{x^T(t)}Q(t)x(t) + u^T(t)R(t)u(t) dt]
\end{equation}
\begin{align*}
F\geq0, Q(t)\geq0, R(t)>0
\end{align*}
The cost function 'J' is minimized when\
\begin{align*}
y(t\textquotesingle), 0\leq t\textquotesingle<t
\end{align*}
where J represents cost function, T is final time horizon which is either finite or infinite and E represent the expected value. so the first term of cost function becomes ignore-able if final time  goes to infinity in first term $x^T (T) Fx (T)$.The cost function need to be finite by keeping the J/T.\cite{bernstein1986optimal}
\section*{Mathematical representation of LQG controller}
The LQG control problem is solved by LQG controller which is specified through following equations in-term of kalman gain L(t) and feedback gain K(t).
\begin{equation}
\frac{d}{dt}
\hat{x(t)} = A(t)\hat{x(t)} + B(t)u(t) + L(t)(y(t)-C(t) \hat{x(t)})
\end{equation}
\begin{equation}
u(t) = -K(t)\hat{x(t)}
\end{equation}
\begin{equation}
\hat{x(0)} = E[x(0)]
\end{equation}
where L(t) represents the kalman gain which is associated with kalman filter. That filter generates estimated value of state x(t) through previous inputs. then it computes the kalman gin by the help of matrices A(t), C(t) with two white Gaussian noise matrices v(t), w(t) and $E[x(0)x^T(0)]$  \cite{bernstein1986optimal} \cite{sharp2011vehicle} .\\
\section{Kalman gain:}
The above defined five matrices compute the kalman gain by following riccati differential equation \cite{van1999optimal} \cite{bernstein1986optimal}
\begin{equation}
\frac{d}{dt}
P(t) = A(t)P(t) + P(t)A^T(t) - P(t)C^T(t)w^-1 (t)C(t)P(t)+v(t)
\end{equation}
so by getting the solution P(t), then kalman gain L(t)
\begin{equation}
L(t) = P(t)C^T(t)w^-1 (t)
\end{equation}
\section{Feedback gain:}
the feedback gain matrix is determined by following equations \cite{van1999optimal} \cite{bernstein1986optimal} \\
\begin{equation}
-\frac{d}{dt}
S(t) = A^T(t)S(t) + S(t)A(t) - S(t)B(t)R^-1 (t)B^T(t)S(t)+Q(t)
\end{equation}
\begin{equation}
K(t) = R^-1(t)B^T(t)S(t)
\end{equation}
\section*{Conclusion}
LQG control problem divided into two section in which we have first  riccati equation describes the linear quadratic estimation problem solver in-term of kalman gain equation which resolve the estimation problem and second riccati equation defines the linear quadratic problem by linear quadratic regulator feedback gain equation. Hence LQG problem called separable.
\bibliographystyle{ieeetran}
\bibliography{ref_lqg}
\end{document}


% === CSC165 Winter 2018 ===
% __authors__ = 'Jacob Chmura, Conor Vedova, Eric Koehli'
% === Problem Set 3 ===

% ******************************************************************************
%                              BEGIN PREAMBLE
% ******************************************************************************

\documentclass[12pt, a4paper]{amsart}

\usepackage{amssymb, amscd, amsmath, amsthm, url, microtype, enumitem}
\usepackage[margin=2.5cm]{geometry}
\usepackage{csc}
\usepackage{setspace} % A package for spacing (double space, etc.)
% \linespread{1.3} % halfspaced

\pagestyle{plain} % Avoids repeating the authors on every page.
\onehalfspacing   % part of setspace package
% \vspace{5mm} % adds a blank line.

% Either use these or the geometry package:
% \addtolength{\oddsidemargin}{-0.5in}
% \addtolength{\evensidemargin}{-0.5in}
% \addtolength{\textwidth}{1in}
% \addtolength{\topmargin}{-0.3in}
% \addtolength{\textheight}{0.3in}

\newtheorem {Theorem}                    {Theorem}
\newtheorem {Proposition}[Theorem]       {Proposition}
\newtheorem {Lemma}      [Theorem]       {Lemma}
\newtheorem {Corollary}  [Theorem]       {Corollary}
\newtheorem*{Claim}       {Claim}
\newtheorem*{Question}   {Question}
\newtheorem*{Exercise}   {Exercise}

\theoremstyle{definition}
\newtheorem  {Definition} [Theorem]{Definition}

\theoremstyle{remark}
\newtheorem*{Remark}	{Remark}
\newtheorem{Example}[Theorem]	{Example}

\numberwithin{Theorem}{section}

\newcommand{\mute}[1] {}
\newcommand{\mc}[1]{\mathcal{#1}}
\newcommand{\mf}[1]{\mathfrak{#1}}
\newcommand{\cal}[1]{\mathcal{#1}}

% \def \N{\mathbb{N}}
% \def \Z{\mathbb{Z}}
% \def \R{\mathbb{R}}
% \def \C{\mathbb{C}}
% \def \Q{\mathbb{Q}}

\def \vphi{\varphi}
\def \eps{\varepsilon}
\def \ssm{\smallsetminus}

% ******************************************************************************
%                               END PREAMBLE
% ******************************************************************************
% Document starts here
\begin{document}

% Document metadata
\title{CSC165H1 Winter 2018: Problem Set 3}
\author{By: Jacob Chmura, Conor Vedova, Eric Koehli}
\date{March 14, 2018}
\maketitle
\newpage
% End

\section{Special numbers}
define $F_n = 2^{2^{n}} + 1$. Prove that $$\forall n \IN \N,
F_n - 2 = \prod_{i=0}^{n-1} F_i$$
From the definition above, it follows that $(1):$ $F_n - 2 = 2^{2^n} + 1 - 2 = 2^{2^n} - 1$.

\begin{proof}

Let $P(n)$ be the statement $F_n - 2 = \prod_{i=0}^{n-1} F_i$, where $n \IN \N$.
We will show that $P(n)$ is true for all natural numbers by induction on $n$.

\base

Let $n = 0$. Then,

\begin{align*}
    F_0 - 2 &= 2^{2^0} + 1 - 2 \\
    &= 2^1 - 1 \\
    &= 1
\end{align*}

On the other hand, when a products lower bound is greater than it's upper bound,
the product is empty. Therefore,

\begin{align*}
    \prod_{i=0}^{0-1} F_i &= 1 = F_0 - 2
\end{align*}

This shows that $P(0)$ is true.

\istep

Let $k \IN \N$ and assume that $P(k)$ is true. That is, $\forall k \IN \N,
F_k - 2 = \prod_{i=0}^{k-1} F_i$. We want to show that $P(k + 1)$ is true, that is,
$$F_{k+1} - 2 = \prod_{i=0}^{k} F_{i}$$

From the LHS we have,

\begin{align*}
    F_{k+1} - 2 &= 2^{2^{k+1}} + 1 - 2 \\
    &= \big( 2^{2^k} \big)^2 - 1 \\
    &= \big( 2^{2^k} - 1 \big) \big( 2^{2^k} + 1 \big)
    \tag{$a^2 - b^2 = (a - b)(a + b)$} \\
    &= \big( F_k - 2 \big) \big( 2^{2^k} + 1 \big) \tag{By (1)} \\
    &= \bigg( \prod_{i=0}^{k-1}F_i \bigg) \cdot F_k \tag{By the induction hypothesis} \\
    &= \prod_{i=0}^{k}F_{i}
\end{align*}

Thus $P(k + 1)$ follows from $P(k)$, and this completes the induction step. Having
proved steps 1 and 2, we can conclude by the Axiom of Induction
that $P(n)$ is true for all natural numbers $n$.

\end{proof}

\newpage

\section{Sequences}

Define $a_0 = 1$, and for all natural numbers $n$, $$a_{n+1} = \frac{1}{\frac{1}{a_n} + 1}$$

\begin{enumerate}

    \item[(a)] $a_0 = 1$, $a_1 = \frac{1}{2}$, $a_2 = \frac{1}{3}$, $a_3 = \frac{1}{4}$

    \item[(b)] Since the numerator of the sequence is constant, we can put $1$ in the
    numerator. As n increases, the denominator is increasing by one, and since we are
    starting at $n = 0$, we can write $a_n = \frac{1}{n + 1}$.

    Prove that for all natural numbers $n$, $$a_n = \frac{1}{n + 1}$$

    \begin{proof}

    Let $P(n)$ be the statement $a_n = \frac{1}{n + 1}$.
    We will show that $P(n)$ is true for all natural numbers $n$.

    \base

    Let $n = 0$. Then $$a_0 = \frac{1}{0 + 1} = 1$$
    and $a_0 = 1$ by definition. This shows that $P(0)$ is true.

    \istep

    Let $k \IN \N$ and assume that $P(k)$ is true. That is,
    for all $k \IN \N$, $a_k = \frac{1}{k + 1}$.
    We want to show that $P(k + 1)$ is true. That is,
    $$a_{k+1} = \frac{1}{k + 2}$$
    Starting from the recursive definition, we have

    \begin{align*}
        a_{k+1} &= \frac{1}{\frac{1}{a_k} + 1} \\
        &= \frac{1}{\frac{1}{\frac{1}{k+1}} + 1} \tag{By the induction hypothesis} \\
        &= \frac{1}{k+1 + 1} \\
        &= \frac{1}{k+2}
    \end{align*}

    Thus $P(k + 1)$ follows from $P(k)$, and this completes the induction step. Having
    proved steps 1 and 2, we can conclude by the Axiom of Induction
    that $P(n)$ is true for all natural numbers $n$.

    \end{proof}

\end{enumerate}

\newpage

Define $a_{k, 0} = k$, and for all natural numbers $n$,
$$a_{k, n + 1} = \frac{k}{\frac{1}{a_{k, n}} + 1}$$

\begin{enumerate}

    \item [(c)] $a_{2, 0} = 2$, $a_{2, 1} = \frac{4}{3}$, $a_{2, 2} = \frac{8}{7}$,
     $a_{2, 3} = \frac{16}{15}$, and

     $a_{3, 0} = 3$, $a_{3, 1} = \frac{9}{4}$, $a_{3, 2} = \frac{27}{13}$,
     $a_{3, 3} = \frac{81}{40}$

    \item[(d)] Prove that for all natural numbers $k$ and $n$, that,

    $$k > 1 \IMP a_{k, n} = \frac{k^{n+1}}{\sum_{i = 0}^{n} k^i}$$

    \begin{proof}
    Let $k \IN \N$. Assume that $k > 1$.
    Let $P(n)$ be the statement

    $$a_{k, n} = \frac{k^{n+1}}{\sum_{i = 0}^{n} k^i}$$

    where $n \in \N$. We will show that $P(n)$ is true for all natural numbers $k > 1, n$,
    by Mathematical Induction on $n$.

    \base

    Let $n = 0$. In this case, we have
    $$a_{k, 0} = \frac{k^{1}}{\sum_{i = 0}^{0} k^i} = \frac{k}{k^{0}} = k$$

    This is the same result as the definition of $a_{k, 0}$, so $P(0)$ is satisfied.

    \istep

    Let $t \IN \N$ and assume that $P(t)$ is true. That is, we assume
    $$a_{k, t} = \frac{k^{t+1}}{{\sum_{i = 0}^{t} k^i}}$$
    and we want to show that $P(t + 1)$ is true. That is,
    $$a_{k, t+1} = \frac{k^{t+2}}{{\sum_{i = 0}^{t+1} k^i}}$$

    By the recursive definition,

    \begin{align*}
        a_{k, t+1} &= \frac{k}{\frac{1}{a_{k, t}} + 1} \\
        &= \frac{k}{\frac{\sum_{i = 0}^{t} k^i}{k^{t+1}} + 1} \tag{By induction hypothesis} \\
        &= \frac{k}{\frac{\sum_{i = 0}^{t} k^i + k^{t+1}}{k^{t+1}}} \\
        &= \frac{k \cdot k^{t+1}}{{\sum_{i = 0}^{t} k^i + k^{t+1}}} \\
        &= \frac{k^{t+2}}{{\sum_{i = 0}^{t+1} k^i}}
    \end{align*}

    Thus $P(t + 1)$ follows from $P(t)$, and this completes the induction step.
    Since we fixed $k$ to be an arbitrary natural number greater than $1$ prior to the induction,
    it must be the case that the result holds for all natural numbers $k$ greater than $1$.
    Having proved steps 1 and 2, we can now conclude by the Axiom of Induction
    that $P(n)$ is true for all natural numbers $k > 1$ and $n$.

    \end{proof}

\end{enumerate}

\newpage

\section{Properties of Asymptotic Notation}

\begin{enumerate}

    \item[(a)] Define $Sum_f(n) = \sum_{i = 0}^{n} f(i) = f(0) + f(1) + \dots + f(n)$.

    Prove that for all $f$: $\N \rightarrow \R^{\geqslant 0}, f \in O(n) \implies Sum_f \in O(n^2)$

    \begin{proof}

    Let $f$: $\N \rightarrow \R^{\geq 0}$ and
    assume that $f \in O(n)$. That is, \\
    $\exists c_0, n_0 \in \R^{+}, \forall n \in \N, n \geq n_0 \implies f(n) \leq c_0 \cdot n$

    Want to show that the sum of the arbitrary function $f$ is in $O(n^2)$. That is,
    $Sum_f (n) \in O(n^2)$. Or, in expanded form, \\
    $\exists c_1, n_1 \in \R^{+}, \forall n \in \N, n \geq n_1 \implies Sum_f(n) \leq c_1 \cdot n^2$

    \medbreak

    Let $c_0, n_0$ be such that $f \IN O(n)$ for these values. Let $c_1 = \sum_{i = 0}^{n_0 - 1} f(i) + c_0$ and $n_1 = \max(n_0, 1)$. Let $n \IN \N$ and assume $n \geqslant n_1$.
    We know that $n \geq n_1 \geq n_0$. So, it follows that $f(n) \leq c \cdot n$. Using this, let's analyze the following sum:

    \begin{align*}
        \sum_{i = 0}^{n} f(i) &= \sum_{i = 0}^{n_0 - 1} f(i) + \sum_{i =  n_0}^{n} f(i) \\
        &\leq \sum_{i = 0}^{n_0 - 1} f(i) + \sum_{i =  n_0}^{n} c_0n\tag{$\forall n \geq n_0, f(n) \leq c_0n$} \\
        &= \sum_{i = 0}^{n_0 - 1} f(i) + (n-n_0) \cdot c_0n \\
        &= \sum_{i = 0}^{n_0 - 1} f(i) - c_0nn_0 + c_0n^2 \\
    \end{align*}
    Since for any $k \IN \R^{\geqslant 0}$ and $n \geq 1$, $k \leq k \cdot n^2$, which holds by the way $n_1$ was chosen,
    \begin{align*}
         \sum_{i = 0}^{n_0 - 1} f(i) &\leq (\sum_{i = 0}^{n_0 - 1} f(i)) \cdot n^2 \tag{Because $f(n) \geq 0$}
    \end{align*}
    So,
    \begin{align*}
        \sum_{i = 0}^{n_0 - 1} f(i) - c_0nn_0 + c_0n^2 &\leq (\sum_{i = 0}^{n_0 - 1} f(i)) \cdot n^2 - c_0nn_0 + c_0n^2 \\
        &\leq (\sum_{i = 0}^{n_0 - 1} f(i)) \cdot n^2 + c_0n^2 \tag{since $-c_0nn_0 \leq 0$} \\
        &= (\sum_{i = 0}^{n_0 - 1} f(i)) + c_0) \cdot n^2 \\
        &= c_1 \cdot n^2
    \end{align*}
    So, it follows that $Sum_f(n) \leq c_1 \cdot n^2$. Therefore, $Sum_f(n) \IN O(n^2)$

    \end{proof}

    \item[(b)] Prove that for all natural numbers $n$,
    $$\sum_{i = 1}^{2^n} \frac{1}{i} \geq \frac{n}{2}$$

    \begin{proof}

    Let $P(n)$ be the statement above, where $n \in \N$.
    We will prove that $P(n)$ is true for all natural numbers by mathematical induction.

    \base

    Let $n = 0$.
    Then we have,
    $$\sum_{i = 1}^{2^0} \frac{1}{i} = \sum_{i = 1}^{1} \frac{1}{i} = 1 \geq \frac{0}{2} = \frac{n}{2}$$
    This shows that $P(0)$ is true.

    \istep

    Let $k \in \N$ and assume that $P(k)$ is true. That is,
    $$\sum_{i = 1}^{2^k} \frac{1}{i} \geq \frac{k}{2}$$
    We want to show that $P(k+1)$ is true. That is,
    $$\sum_{i = 1}^{2^{k+1}} \frac{1}{i} \geq \frac{k+1}{2}$$

    Analyzing the left hand side,

    \begin{align*}
        \sum_{i=1}^{2^{k+1}} \frac{1}{i} &= \sum_{i=1}^{2^k} \frac{1}{i} + \frac{1}{2^k + 1} + \frac{1}{2^k + 2} + ... + \frac{1}{2^k + 2^k} \\
        &\geq \frac{k}{2}+ \frac{1}{2^k + 1} + \frac{1}{2^k + 2} + ... + \frac{1}{2^k + 2^k} \tag{By induction Hypothesis} \\
    \end{align*}

    Now to proceed with the proof, it will be shown that $\frac{1}{2^k + 1} + \frac{1}{2^k + 2} + ... + \frac{1}{2^k + 2^k} \geq \frac{1}{2}$.

    Notice,  $\frac{1}{2^k + 1} + \frac{1}{2^k + 2} + ... + \frac{1}{2^k + 2^k} \geq \frac{1}{2^k + 2^k} + \frac{1}{2^k + 2^k} + ... + \frac{1}{2^k + 2^k}$, since $\frac{1}{2^k + k}$ is the smallest element of the summation.

 \newpage

    With this fact in mind:

    \begin{align*}
        \sum_{i=1}^{2^{k+1}} &\geq \frac{k}{2}+ \frac{1}{2^k + 1} + \frac{1}{2^k + 2} + ... + \frac{1}{2^k + 2^k} \\
        &\geq \frac{k}{2} + \frac{1}{2^k + 2^k} + \frac{1}{2^k + 2^k} + ... + \frac{1}{2^k + 2^k} \\
        &= \frac{k}{2} + 2^k \cdot \frac{1}{2^k + 2^k}\\
        &= \frac{k}{2} + \frac{1(2^k)}{2 \cdot 2^k} \\
        &= \frac{k}{2} + \frac{1}{2} \\
        &= \frac{k+1}{2}
    \end{align*}

    Thus $P(k + 1)$ follows from $P(k)$, and this completes the induction step. Having
    proved steps 1 and 2, we can conclude by the Principle of Mathematical Induction
    that $P(n)$ is true for all natural numbers $n$.
    \end{proof}

    \newpage

     \item[(c)]
     \emph{Disprove} The following claim: \\
     $\forall f, g: \N \xrightarrow{} \R^{\geq 0}, f(n) \in O(g(n)) \implies Sum_f(n) \in O(n\cdot g(n))$. \\

     We will prove the negation of the statement: \\
     $\exists f, g: \N \xrightarrow{} \R^{\geq 0}, f(n) \in O(g(n)) \land Sum_f(n) \notin O(n\cdot g(n))$ \\

    \begin{proof}
    Let $f(n) = \frac{1}{n}$ and $g(n) = \frac{1}{2 \cdot n}$ \\

    First showing $f \in O(g)$: \\
     $\exists c_0, n_0 \in \R^{+}, \forall n \in \N, n \geq n_0 \implies \frac{1}{n} \leq c_0 \cdot \frac{1}{2 \cdot n}$

    Let $n_0 = 0$ and $c_0 = 2$
    Let $n \in \N$.
    Assume $n \geq n_0$
    Then $\forall n$:

\begin{align*}
    f(n) &= \frac{1}{n} \\
    &\leq \frac{1}{n} \\
    &= 2 \cdot \frac{1}{2 \cdot n} \\
    &= c_0 \cdot g(n)
\end{align*} \\

    So by definition,  $f \in O(g)$.

    Now we will show the following by negating the definition of Big-Oh:

    $Sum_f(n) \notin O(n\cdot g(n))$:

    $\forall c_1, n_1 \in \R^{\geq 0}, \exists n \in \N, n \geq n_1 \land Sum_f (n) > c_1 \cdot n \cdot g(n)$ \\

    Let $c_1, n_1 \in \R^{\geq 0}$ \\
    Take $n = max(2^{\ceil {c_1}} + 2, 2^{n_1})$
    Then it follows that $n \geq 2^{n_1} \geq n_1$, and the first part of the \emph{and} is satisfied.

    Also, $n > 2^{\ceil{c_1}}  \implies log_2 n > \ceil{c_1} \geq c_1$. So $log_2 n > c_1 $(1)

    Importantly, by the way that $n$ was chosen, it must be a power of two.
    It follows that $log_2 n \in \N$. (2)

    From (b) we know that for all natural numbers $t$:

    $$\sum_{i = 1}^{2^t} \frac{1}{i} \geq \frac{t}{2}$$

    Change of variable: Let $t = log_2 n$. By (2) we know that $t \in \N$ and we have:

    $$\sum_{i = 1}^{n} \frac{1}{i} \geq \frac{log_2 n }{2}$$

    Now we can see that the left side of the inequality is just $Sum_f (n)$, so it follows that:
\begin{align*}
    Sum_f (n)  &\geq \frac{log_2 n }{2} \\
    &= g(n)\cdot n \cdot log_2 n \\
    &> g(n) \cdot n \cdot c_1 \tag{(By (1), $log_2 n > c_1$}
\end{align*}

So, $n \geq n_1 \land Sum_f(n) > c_1 \cdot n \cdot g(n)$.

Therefore, $Sum_f(n) \notin O(n\cdot g(n))$. \\

Together, we have proven $\exists f, g: \N \xrightarrow{} \R^{\geq 0}, f(n) \in O(g(n)) \land Sum_f(n) \notin O(n\cdot g(n))$. Since the negation of the original is proven, the original statement is disproven.
\end{proof}
\end{enumerate}

\end{document} % The document ends here


\documentclass[11pt]{article}
\usepackage[cm]{fullpage}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage{amsmath}
\usepackage{multicol}
\setlength{\columnsep}{1cm}

\title{S1336 - Project 1}%replace with the appropriate homework number
\author{Erik Weilow} %if necessary, replace with your course title

\newcommand{\triplefigure}[3]{
\begin{figure}[H]
  \centering
  \begin{minipage}{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{#1}
  \end{minipage}
  \begin{minipage}{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{#2}
  \end{minipage}
  \begin{minipage}{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{#3}
  \end{minipage}
\end{figure}
}
\newcommand{\singlefigure}[1]{
\begin{figure}[H]
  \centering
  \begin{minipage}{0.4\textwidth}
    \centering
    \includegraphics[width=\textwidth]{#1}
  \end{minipage}
\end{figure}
}

\begin{document}
\maketitle
\newpage

\section*{1.1}

In this section, the plots for the general solutions are integrated using Velocity Verlet. As will be shown later, both Runge Kutta and regular Euler produces solutions that aren't energy preserving.

\subsection*{Pendulums vs harmonic oscillators}
\triplefigure{./plots/1_1/comparison_1.png}{./plots/1_1/comparison_2.png}{./plots/1_1/comparison_3.png}
In this first part, it can be seen that a numerical solution for a pendulum has longer period than for that of a harmonic oscillator.
Increasing the initial angle increases the amplitude of oscillations.

\subsection*{Pendulums: general solution}
\triplefigure{./plots/1_1/sol_pendulum_1.png}{./plots/1_1/sol_pendulum_2.png}{./plots/1_1/sol_pendulum_3.png}
It can be seen that the solution doesn't scale linearly with increased starting angle.

\subsection*{Harmonic oscillators: general solution}
\triplefigure{./plots/1_1/sol_harmonic_1.png}{./plots/1_1/sol_harmonic_2.png}{./plots/1_1/sol_harmonic_3.png}
More or less the same result as for a pendulum, though with a slightly shorter period as previously shown.

\subsection*{Rolling mean of energy for pendulum}
\triplefigure{./plots/1_1/rollingMean_1.png}{./plots/1_1/rollingMean_2.png}{./plots/1_1/rollingMean_3.png}
We can't even see the simulation using Euler in this plot - it shot right up within mere seconds.
Runge Kutta becomes "good" on timescales on the order of 1000 seconds for $\Delta t \approx 0.01$.
For longer timescales, we need a smaller $\Delta t$.

Both Euler-Cromer and Velocity Verlet have energies that oscillate fast enough to cause aliasing effects (hence why the rolling average of those are a solid block of color).

\subsection*{Rolling mean of energy for harmonic oscillator}
\triplefigure{./plots/1_1/rollingMean_harmonic_1.png}{./plots/1_1/rollingMean_harmonic_2.png}{./plots/1_1/rollingMean_harmonic_3.png}
For the harmonic oscillator, we get basically the same results as for the pendulum but the energies oscillate less for Euler-Cromer and Velocity Verlet.

\subsection*{Harmonic oscillators: Numerical vs analytic}
\triplefigure{./plots/1_1/comparison_numanalytic_1.png}{./plots/1_1/comparison_numanalytic_2.png}{./plots/1_1/comparison_numanalytic_3.png}
In these plot, the ratio between the analytic and numerical solution is plotted over time:
$$
\frac{1 + \|\text{analytic}(t)\|}{1 + \|\text{numerical}(t)\|}
$$
Using Velocity-Verlet integration we can see aliasing effects (indicative of inequal periods), but the energy is stable as shown previously, so the numerical integration is still stable.

\section*{1.2}
\singlefigure{./plots/1_2/period.png}
Harmonic oscillator has constant period, smaller than pendulum for all but the minimal initial values.
The perturbation series gives a good match for the period of a harmonic oscillator, even if stopping at the sixth power.

\section*{1.3}

\subsection*{Dampened harmonic oscillator}
\triplefigure{./plots/1_3/dampened_dx.png}{./plots/1_3/dampened_E.png}{./plots/1_3/dampened_x.png}
The middle plot shows energy as function of time, in which it's clear that the dampening also decreases energy of the oscillator over time.

From the leftmost figure we see that the velocity of the dampened oscillator decreases with time. A larger $\gamma$ results in shorter relaxation time.

The rightmost plot shows the position of the dampened oscillator over time and it's clear from there as well that higher $\gamma$ results in shorter relaxation time.

A thing to note is that from the selected values of $\gamma$ as well as the chosen initial conditions, the oscillations share more or less the same frequency.

\pagebreak
\begin{multicols}{2}
\subsection*{Relaxation time as function of $\gamma$}
\singlefigure{./plots/1_3/study.png}
To find relaxation time, I fit the exponential $f(t) = A e^{-Bt}$ to local peaks of the numerical simulation.
After finding values for $A$ and $B$, the relaxation time becomes $t_r = \frac{1}{B}$. The result is shown in the plot above.

The drop to exactly 0 around $\gamma\approx 5.9$ is exactly when the oscillator becomes critically dampened, as we only have one local maxima (the initial value) for such a system, and cannot fit the above mentioned exponential (that has two parameters) to a function with a single maximum.
\columnbreak
\subsection*{Minimum x as function of $\gamma$}
\singlefigure{./plots/1_3/study_2.png}
This plot shows the minimum values of $\theta (t)$ over time for different $\gamma$. Just like in the previous section, we can conclude that the system becomes critically dampened around $\gamma \approx 5.9$ (even though it's harder to find the exact value in this plot).
\end{multicols}

\section*{1.4}
\subsection*{Phase space portrait of dampened pendulum}
\singlefigure{./plots/1_4/study.png}
What this phase space portrait shows us is that the oscillations will eventually die out, because the spiral converges towards $\theta(t_\infty) = 0$, $\theta'(t_\infty) = 0$.

\pagebreak
\section*{1.5}
\begin{multicols}{2}
  \subsection*{Energy average}
  \singlefigure{./plots/1_5/study.png}
  We see here that both the Leapfrog method and Velocity Verlet are energy preserving methods over long time, even for a relatively large time step as $\Delta t = 0.25$.
  \columnbreak
  \subsection*{Trajectories}
  \singlefigure{./plots/1_5/study2.png}
  Leapfrog produces different trajectory than Velocity Verlet, which is interesting to note.
\end{multicols}

% ![](./plots/1_1/comparison_1.png)
% ![](./plots/1_1/comparison_2.png)
% ![](./plots/1_1/comparison_3.png)
\end{document}


% Modified based on Xiaoming Sun's template
\documentclass{article}
\usepackage{amsmath,amsfonts,amsthm,amssymb}
\usepackage{setspace}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{extramarks}
\usepackage{chngpage}
\usepackage{soul,color}
\usepackage{graphicx,float,wrapfig}

\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
}

\newcommand{\Class}{Mathesmatics for Computer Science}

% Homework Specific Information. Change it to your own
\newcommand{\Title}{Homework 4}

% In case you need to adjust margins:
\topmargin=-0.45in      %
\evensidemargin=0in     %
\oddsidemargin=0in      %
\textwidth=6.5in        %
\textheight=9.0in       %
\headsep=0.25in         %

% Setup the header and footer
\pagestyle{fancy}                                                       %
\chead{\Title}  %
\rhead{\firstxmark}                                                     %
\lfoot{\lastxmark}                                                      %
\cfoot{}                                                                %
\rfoot{Page\ \thepage\ of\ \protect\pageref{LastPage}}                          %
\renewcommand\headrulewidth{0.4pt}                                      %
\renewcommand\footrulewidth{0.4pt}                                      %

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Some tools
\newcommand{\enterProblemHeader}[1]{\nobreak\extramarks{#1}{#1 continued on next page\ldots}\nobreak%
                                    \nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak}%
\newcommand{\exitProblemHeader}[1]{\nobreak\extramarks{#1 (continued)}{#1 continued on next page\ldots}\nobreak%
                                   \nobreak\extramarks{#1}{}\nobreak}%

\newcommand{\homeworkProblemName}{}%
\newcounter{homeworkProblemCounter}%
\newenvironment{homeworkProblem}[1][Problem \arabic{homeworkProblemCounter}]%
  {\stepcounter{homeworkProblemCounter}%
   \renewcommand{\homeworkProblemName}{#1}%
   \section*{\homeworkProblemName}%
   \enterProblemHeader{\homeworkProblemName}}%
  {\exitProblemHeader{\homeworkProblemName}}%

\newcommand{\homeworkSectionName}{}%
\newlength{\homeworkSectionLabelLength}{}%
\newenvironment{homeworkSection}[1]%
  {% We put this space here to make sure we're not connected to the above.

   \renewcommand{\homeworkSectionName}{#1}%
   \settowidth{\homeworkSectionLabelLength}{\homeworkSectionName}%
   \addtolength{\homeworkSectionLabelLength}{0.25in}%
   \changetext{}{-\homeworkSectionLabelLength}{}{}{}%
   \subsection*{\homeworkSectionName}%
   \enterProblemHeader{\homeworkProblemName\ [\homeworkSectionName]}}%
  {\enterProblemHeader{\homeworkProblemName}%

   % We put the blank space above in order to make sure this margin
   % change doesn't happen too soon.
   \changetext{}{+\homeworkSectionLabelLength}{}{}{}}%

\newcommand{\Answer}{\ \\\textbf{Answer:} }
\newcommand{\Acknowledgement}[1]{\ \\{\bf Acknowledgement:} #1}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make title
\title{\textmd{\bf \Class: \Title}}
\date{March 25, 2019}
\author{Xingyu Su 2015010697}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{spacing}{1.1}
\maketitle \thispagestyle{empty}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin edit from here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[LPV 6.10.22]
We are given $n + 1$ numbers from the set $\{1, 2, \cdots , 2n\}$. Prove that there are two numbers among them such that one divides the other.

\Answer

Divide each of the numbers $a_i$ into groups $A_k$ by $a_i=2^{p}\cdot k$ with bigest integer $p$, which is:
\begin{equation*}
A_k = {2^0 k + 2^1 k+2^2 k+\cdots}
\end{equation*}

Obviously every $k$ is $k\equiv 1(mod2)$, and we have a n-segmentation of $\{1, 2, \cdots, 2n \}$:
\begin{align*}
A_{1}&={2^0\cdot1,2^1\cdot1,2^2\cdot1,\cdots};\\
A_{3}&={2^0\cdot3,2^1\cdot3,2^2\cdot3,\cdots};\\
\cdots \\
A_{2n-1}&={2^0\cdot(2n-1)};
\end{align*}

And every two numbers in each group  will have one can be divided by the other. So if we are given $n+1$ numbers, at least 2 are from one group, with pigeon hole principle known. So there are two numbers among them such that one divides the other.
\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[LPV 6.10.23]
What is the number of positive integers not larger than 210 and not divisible by 2, 3 or 7?

\Answer
Similar to \textbf{6.9.1}, we have
\begin{equation*}
210-(\frac{210}{2}+\frac{210}{3}+\frac{210}{7})+(\frac{210}{2\cdot3}+\frac{210}{2\cdot7}+\frac{210}{3\cdot7})-\frac{210}{2\cdot3\cdot7} = 60
\end{equation*}
integers not larger than 210 and not divisible by 2, 3 or 7.

\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[Special Problem 3]
	Let $X_1 , X_2 , \cdots , X_n$ be independent Poisson trials such that $Pr\{X_i = 1\} = p_i$ . Let $X = \sum_{1\leq i\leq n} X_i$ and $\mu = E(X)$. In class we derived one version of the Chernoff Bounds regarding the probability that $X > (1 + \sigma)\mu$. Here you are asked to prove the following bounds in a similar way:

(a) For $0 <\delta < 1$,
\begin{equation*}
Pr\{X\leq(1-\delta)\mu\}\leq\left(\frac{e^{-\delta}}{(1-\delta)^{1-\delta}}\right)^\mu.
\end{equation*}

(b) Assume that $p_i = 1/2$ for all $i$. Prove the stronger bound that
\begin{equation*}
Pr{|X -\frac{n}{2}| > a} \leq 2e^{\frac{-2a^2}{n}}.
\end{equation*}
(Hint: First show that $e^t + 1 \leq 2e^{t/2+t^2/8}$ for all $t > 0$.)

\Answer

(a) Known $Pr(X_i=1)=p_i$ and $Pr(X\leq a) \leq e^{ta} \Pi_i E[e^{-tX_i}]$ with $t>0$.
\begin{align*}
Pr(X\leq(1-\delta)\mu)
  & \leq \frac{\Pi_{i=1}^n E[e^{-tX_i}]}{e^{-t(1-\delta)\mu}}\\
  & = \frac{\Pi_{i=1}^n{[p_ie^{-t}+(1-p_i)]}}{e^{-t(1-\delta)\mu}}
\end{align*}

\hspace{1em}
And with know $1+x \leq e^x$, we have $p_i e^{-t} +(1-p_i) = p_i(e^{-t}-1)+1\leq e^{p^i(e^{-t}-1)}$. So
\begin{align*}
Pr(X\leq (1-\delta)\mu)
  &\leq \frac{\Pi_{i=1}^n e^{p_i(e^{-t}-1)}}{e^{-t(1-\delta)\mu}} \\
  &= \frac{e^{(e^{-t}-1)\sum_{i=1}^n p_i}}{e^{-t(1-\delta)\mu}} \\
  &= \frac{e^{(e^{-t}-1)\mu}}{e^{-t(1-\delta)\mu}}
\end{align*}

\hspace{1em}
Set $t=-\ln(1-\delta)$ and $t>0$ when $0<\delta<1$, then
\begin{align*}
Pr(X\leq(1-\delta)\mu)
  &\leq \frac{e^{(e^{-t}-1)\mu}}{e^{-t(1-\delta)\mu}} \\
  &= \frac{e^{-\delta\mu}}{(1-\delta)^{(1-\delta)\mu}} \\
  &= \left[\frac{e^{-\delta}}{(1-\delta)^{(1-\delta)}}\right]^\mu
\end{align*}

(b) I have no idea from $e^t-1\leq 2e^{t/2+t^2/8}$. But a different prove from \textbf{Probability and Computing: Randomized Algorithms and Probabilistic Analysis} is found as below:

\hspace{1em}
Let $Y_1, Y_2, \cdots, Y_n$ be independent random variables with $Pr(Y_i=1)=Pr(Y_i=-1)=\frac{1}{2}$ and $Y=\sum_{i=1}^n Y_i$, for any $t>0$,
\begin{align*}
E[e^{tY_i}]
  &= \frac{1}{2}e^t+\frac{1}{2}e^{-t}\\
  &= \frac{1}{2}(1+t+\frac{t^2}{2!}+\frac{t^3}{3!}+\cdots)-\frac{1}{2}(1-t+\frac{t^2}{2!}-\frac{t^3}{3!}+\cdots) \\
  &= \sum_{i\geq0}\frac{t^{2i}}{(2i)!} \\
  &= \sum_{i\geq0}{(t^2/2)^i}/{i!} \\
  &= e^{t^2/2}.
\end{align*}

\hspace{1em}
With $t=\frac{a}{n}>0$, we get
\begin{align*}
Pr(Y\geq a)
  & \leq \frac{E[e^{tY}]}{e^{ta}} \\
  &= \frac{\Pi_{i=1}^n E[e^{tY_i}]}{e^{ta}}\\
  &= e^{n t^2/2-ta} \\
  &= e^{-{a^2}/{2n}}
\end{align*}

\hspace{1em}
So with $X_i$ have $Pr(X_i=1)=Pr(X_i=0)=\frac{1}{2}$ and $X=\sum_{i=1}^n X_i$. We get $\mu=\frac{n}{2}$ and $X=\frac{1}{2}\sum_{i=1}^n(X_i+1)=\frac{1}{2}Y+\mu$

\begin{equation*}
Pr(X\geq \mu+a)=Pr(Y\geq 2a)\leq e^{-4a^2/2n}
\end{equation*}

\hspace{1em}
with symmetry, we finally get

\begin{equation*}
Pr(|X-\frac{n}{2}|\geq a) \leq 2e^{\frac{-2a^2}{n}}
\end{equation*}

\end{homeworkProblem}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{homeworkProblem}[Special Problem 4]
Use the Chernoff Bounds derived in class and in the above problem to prove the following inequalities: For all $0 < \delta \leq 1$

  (a) $Pr\{X \geq (1 + \delta)\mu\} \leq e^{-\mu\delta^2/3}.$

  (b) $Pr\{X \leq (1 - \delta)\mu\} \leq e^{-\mu\delta^2/2}$

\textbf{Remark} Note that it follows from (a) and (b) that $Pr\{|X - E(X)| > a\} \leq 2e^{-a^2/3E(X)}$ for all $0 < a \leq E(X)$.

\Answer

(a) From SP3a we get a symmetry formula:
\begin{equation*}
Pr(X\geq(1+\delta)\mu) \leq \left[\frac{e^\delta}{(1+\delta)^{(1+\delta)}}\right]^\mu
\end{equation*}

\hspace{1em}
To get
\begin{equation*}
Pr(X \geq (1 + \delta)\mu) \leq e^{-\mu\delta^2/3}
\end{equation*}

\hspace{1em}
We can get
\begin{equation*}
\frac{e^\delta}{(1+\delta)^{(1+\delta)}}  \leq e^{-\delta^2/3}
\end{equation*}

\hspace{1em}
first.

\hspace{1em}
The derivative of upper inequality is writen as blow:
\begin{equation*}
f(\delta) = \delta-(1+\delta)\ln(1+\delta)+\frac{\delta^2}{3}\leq 0
\end{equation*}

\hspace{1em}
So
\begin{align*}
f'(\delta) &= - \ln(1+\delta) +\frac{2}{3}\delta \\
f''(\delta)&=-\frac{1}{1+\delta}+\frac{2}{3}
\end{align*}

\hspace{1em}
So $f''(\delta)<0$ for $0<\delta<\frac{1}{2}$ and $f''(\delta)>0$ for $\frac{1}{2}<\delta\leq 1$. And $f'(0) = 0$, $f'(1)=-\ln(2)+\frac{2}{3}<0$, so $f'(\delta)<0$ for all $0<\delta\leq1$.

\hspace{1em}
With $f(0) = 0$, we are convienced now that $f(\delta)<0$ for all $0<\delta\leq1$, which equals to (a).

(b) Similary to (a), we get the derivative as below:
\begin{equation*}
g(\delta) = -\delta-(1-\delta)\ln(1-\delta)+\frac{\delta^2}{2}\leq 0
\end{equation*}

\hspace{1em}
And
\begin{align*}
g'(\delta) &=  \ln(1-\delta)+\delta\\
g''(\delta) &=  1-\frac{1}{1-\delta}
\end{align*}

\hspace{1em}
Obviously, $g''(\delta)<0$ for all $0<\delta\leq1$. And $g'(0)=0$, so $g'(\delta)<0$; $g(0)=0$, so $g(\delta)<0$ is got easily.

\end{homeworkProblem}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ACKNOWLEGEMENT
\Acknowledgement

  SP3a: Wikipedia \href{https://en.wikipedia.org/wiki/Chernoff_bound#cite_note-MitzenmacherUpfal-3}{Chernoff bound}

  SP3b: Part 4.8 and 4.9 from book \href{https://books.google.com/books?id=0bAYl6d7hvkC&pg=PR7&hl=zh-CN&source=gbs_selected_pages&cad=3#v=onepage&q=chernoff%20bound&f=false}{Probability and Computing: Randomized Algorithms and Probabilistic Analysis}

% End edit to here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{spacing}
\end{document}

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


\documentclass[12pt, a4paper, twoside]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage[margin=0.8in]{geometry}
\usepackage{listings}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage{indentfirst}
\usepackage[inline]{enumitem}
\usepackage{tabularx}
\usepackage{xcolor}
\usepackage{array}
\usepackage{minted}
\usemintedstyle{vs}
\usepackage[belowskip=0pt,aboveskip=0pt,font=small,labelfont=small]{caption}
\captionsetup{width=\linewidth}

\makeatletter
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
    \node[shape=circle, draw, inner sep=1pt,
        minimum height={\f@size*1.25},] (char) {\vphantom{WAH1g}#1};}}
\makeatother

\def \courseNumber {EE2703}
\def \assignmentNumber {10}
\def \myName {Akilesh Kannan}
\def \rollNumber {EE18B122}

\setlength\intextsep{0pt}
\graphicspath{{plots/}}
\setlist[itemize]{noitemsep, topsep=0pt}
\fancyhead[RO,LE]{\courseNumber : Assignment \assignmentNumber}
\fancyhead[LO,RE]{\myName}
\cfoot{\thepage}

\title{\courseNumber : Assignment \assignmentNumber}
\author{\myName\ (\rollNumber)}
\date{\today}

\pagestyle{fancy}

\begin{document}
\maketitle

\section{Introduction}
In this assignment, we shall explore the convolution of two discrete-time signals. We shall look at \textit{linear convolution} and \textit{circular convolution} and their relationship. We shall also look at a certain sequence called \textit{Zadoff-Chu sequence}, and it's special properties.

\section{The FIR Filter}
The given FIR Filter is this:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{Fig0.png}
    \caption{FIR Filter $h[.]$}
    \label{fig:Fig0}
\end{figure}
If we observe carefully, we can see that the envelope of the filter looks like a $sinc(x)$ function, which means that it's DTFT will look similar to a $rect(\omega)$.

The magnitude and phase response of the given filter is given by:
\begin{equation}
    H(e^{j\omega}) = \sum_{n=0}^{11}h[n]e^{-j\omega n}
\end{equation}
Using the command \texttt{scipy.signal.freqz}, we shall be able to get the frequency response as shown below:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{Fig1.png}
    \caption{Frequency Response of FIR Filter $H(e^{j\omega})$}
    \label{fig:Fig1}
\end{figure}

Since, the sequence $h[.]$ is real, it's DTFT $H(e^{j\omega})$ will be even\footnotemark. So, we can see that the magnitude response indeed looks like similar to $rect(\omega)$. \footnotetext{$H(e^{-j\omega}) = \sum_{n=0}^{11}h[n]e^{j\omega n} = H^*(e^{j\omega})\ \implies\ |H(e^{-j\omega})| = |H(e^{j\omega})|$}
\section{Linear Convolution}
Now, we shall take an input signal $x[n] = cos(0.2\pi n)+cos(0.85\pi n)$, and observe the output of the filter.
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{Fig2.png}
    \caption{Input to filter, $x[.]$}
    \label{fig:Fig2}
\end{figure}

The output of the filter $y[.]$ can be got by linear convolution of the input $x[.]$ and the filter's impulse response $h[.]$
\begin{equation}
    y[n] = x\ast h = \sum_{\{k:\ h[k]\neq 0\}}x[n-k]h[k]
\end{equation}

Using the command \texttt{numpy.convolve} to perform the linear convolution operation of $x[.]$ and $h[.]$, we get:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{Fig3.png}
    \caption{Output of Filter, $y[n]$}
    \label{fig:Fig3}
\end{figure}

As expected, we see a sinusoid of frequency approximately $0.2\pi$. This is because the filter has damped the high frequency component $cos(0.85\pi n)$ greatly. We can see from the magnitude response that $|H(e^{j\omega})| \Big{\lvert}_{\omega=0.85\pi}$ is close to 0.

\section{Circular Convolution}
An N-point circular convolution is defined as:
\begin{gather}
    y[.] = x[.]\ \text{\circled{N}}\ h[.]\\
    y[n] = \sum_{m=0}^{N-1}x[m]h[(n-m)\mod N],\ n\in [0, N-1]
\end{gather}

Here, the length of all the three signals involved, $x[.]$, $h[.]$ and $y[.]$ are the same and equal to $N$.

We can easily see that the $y[.]$ obtained as a result of circular convolution and that obtained by linear convolution will not be same always. However, if we take an P-point circular convolution, by appropriately zero padding the two signals, such that $P \geq len(y_{lin}[.])$, then, the two will match. This is because $y_{cir}[.]$ is the principal period of $\tilde{y}_{lin}[.]$, which is a periodic extension of $y_{lin}[.]$, with period $P$. So, if the period $P < len(y_{lin}[.])$, then there will be time-aliasing, which will distort the output. Otherwise, if $P \geq len(y_{lin}[.])$, then, there will not be any time-aliasing and so, $y_{cir}[.]$ and $y_{lin}[.]$ will have the same information.

We get the following graphs, depending on the length of the circular convolution output.

\begin{enumerate}[label= \texttt{Case (\alph*)}]
    \item $N = 1024$
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.5]{Fig4.png}
        \caption{1024-point circular convolution}
        \label{fig:Fig4}
    \end{figure}
    \item $N = 1034$
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.5]{Fig5.png}
        \caption{1034-point circular convolution}
        \label{fig:Fig4}
    \end{figure}
\end{enumerate}

Here, we can see that the 1034-point circular convolution results in the same output as linear convolution. This is because, the length of linear convolution signal is $1024 + 11 - 1 = 1034$. Thus, we have implemented linear convolution using circular convolution.

But, to efficiently implement linear convolution through circular convolution, we have to take $2^m$-point circular convolution. This is because, the underlying algorithm, the \textit{Fast Fourier Transform} (FFT) is most efficient when it is used for $2^m$-point signals.

\section{Circular Correlation of Zadoff-Chu Sequence}
Consider the Zadoff-Chu sequence, a commonly used sequence in communication. The properties of the sequence are:
\begin{enumerate}
    \item It is a complex sequence.
    \item It is a constant amplitude sequence.
    \item The auto correlation of a Zadoff-Chu sequence with a cyclically shifted version of itself is zero, except at the shift.
    \item Correlation of Zadoff-Chu sequence with a delayed version of itself will give a peak at that delay.
\end{enumerate}

The Zadoff-Chu sequence is shown below:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{Fig6.png}
    \caption{Zadoff-Chu Sequence}
    \label{fig:Fig6}
\end{figure}

We can verify property (3) given above, by plotting the auto-correlation of $zChu[.]$ with a cyclically delayed version of itself. I have taken the auto-correlation with $zChu[.]$ cyclically rotated by 5. The result was:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{Fig7.png}
    \label{fig:Fig7}
\end{figure}
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.5]{Fig8.png}
    \caption{Auto-correlation of $zChu[.]$ with a cyclically delayed version of itself}
    \label{fig:Fig7}
\end{figure}
In the above figure, we can see that the auto-correlation is non-zero only at $n=5$, which corresponds to the delay value.

\section{Conclusion}
Linear convolution algorithm implemented using a direct summation is non-optimal and computationally expensive.  A faster way to perform the convolution is to use the DFTs of the input and the filter.  Circular convolution can be used for the implementation of linear convolution, with a much faster computation speed.  The magnitude and phase response of a low pass filter were studied and the system’s output, for a mixed frequency signal was obtained through three different methods.  For the Zadoff-Chu sequence, it's auto-correlation with a cyclically shifted version of itself was found to be non-zero only at the point corresponding to the shift.
\end{document}


\documentclass[
  xhtml,%
  use filename%
]{internet}

\usepackage{tutorial}
\usepackage{hyperref}

\title{Algebra in Programming}
\begin{document}
\maketitle

\section*{Getting Started}

\begin{enumerate}
\item Log on to the computer and launch a web browser
\item Navigate to \href{http://luacanvas.mathforge.org}{http://luacanvas.mathforge.org}
\item Click on the checkbox in the lower right corner, labelled \verb+Graphics mode+
\item The big area in the centre of the screen is where you can type code (we call this the \emph{editor} region).
Clicking on the box labelled \verb+Execute+ will run your code.
\end{enumerate}

\section*{Printing Messages}

To display a message, we use the \verb+print+ command.
Click in the editor region and type:

\begin{verbatim}
print("hello world")
\end{verbatim}

Now click \verb+Execute+ to run your program.

Click \verb+Edit+ to get back to the program.
Try changing the message.

\section*{Storing Information}

In computer programs, we use \emph{variables} to store information.
A variable is a label which tells the computer what information to use.
First we have to store some information.
Make sure you are in the editor view and type:

\begin{verbatim}
name = "Harry Potter"
\end{verbatim}

If you run this program, not a lot will happen.
That's because we've only stored the information, we haven't done anything with it yet.
We can combine this with our earlier message.
After the line above, type:

\begin{verbatim}
print("Welcome to Hogwarts,", name)
\end{verbatim}

(Notice the comma after the \verb+"+ and before \verb+name+.)

Try changing the name and see what happens.

\section*{Strings and Numbers}

When a computer stores information, it also remembers what \emph{type} of information it is.
A \emph{string} is a bit like a word; it is made out of letters and other characters, like \verb+Harry Potter+.
Another type of information is a \emph{number}.
By knowing the type of information, the computer is able to do things with that information.

For example, we can take a string and make all its letters lowercase.
Following on from the above, type:

\begin{verbatim}
print(name:lower())
\end{verbatim}

What do you think you would get if you changed \verb+lower+ to \verb+upper+?

\bigskip

If we store a number, we can do numbery things with that information.
Type:

\begin{verbatim}
x = 3
print(x)
print(x+4)
print(3*x)
\end{verbatim}

(The character between the \verb+3+ and \verb+x+ is an \emph{asterisk}, \verb+*+.
What operation does it represent?)

\section*{Getting Information}

The last piece of programming that we need today is how to get information.
We want to ask the person running the program for information and pass that on to the computer.
This means that we want to store it in a variable.
Type:

\begin{verbatim}
x = prompt("Enter something:")
print(x)
\end{verbatim}

Run this program.
In the text box, type something and press \verb+return+.
Note that the program waits for you to enter something before carrying on.

\section*{Planting Vegetables}

We can put this together with our algebraic expressions to find out what our gardener would plant.
Type the following, but in place of the \verb+?+s put the right expression (remember to use \verb+*+ for multiplication):

\begin{verbatim}
m = prompt("How many cabbages did you plant?")
print("You planted",?,"leeks")
print("You planted",?,"carrots")
print("You planted",?,"cauliflowers")
print("Next year, you'll plant",?,"cabbages")
\end{verbatim}

\section*{Letters are Unknown Numbers}

When writing the program, you didn't know what number \verb+m+ would be.
But you could still tell the computer what to do with it, and once the computer found out what \verb+m+ was it could carry out your instructions.

So in the program, \verb+m+ stands for a number that \emph{we don't yet know}.
But as it will become a known number, we can pretend that it is a number and do numbery things to it such as adding, subtracting, and multiplying.

\section*{Do It Yourself}

Now try the other questions on the sheet, writing programs that will ask for the initial information and give the answers to each part of the question.

\end{document}