\chapter{Interfacing DTMF}
\label{ch:dtmf}
%------------------------------------------------

\ac{DTMF} is a common method used by phone companies to conduct surveys and other requests. It is a telecommunication signaling system using the voice-frequency band over telephone lines between telephone equipment and other communications devices and switching centers. First developed at Bell Systems in United States in 1963, it found its wide spread usage ever since.

\begin{figure}
    \centering
    \includegraphics[width=2.9in]{Images/DTMF/DTMF_module.jpg}
    \caption[DTMF Module]{A \ac{DTMF} module }
    \setfloatalignment{b}
\end{figure}

\par The keypad is given a fixed set of pure tone ( pure sine wave ) that generates an audio of that particular frequency. This audio is analyzed at the switching centers and telephone equipment and decoded back to detect the key pressed. The keypad grid is divided into two groups of audio frequency ranges, The Row (Low group) frequencies and The Column (High group) frequencies. Whenever a key is pressed, corresponding mixture of audio are generated and transmitted via telephone line. Table ~\ref{tab:keypad} depicts how the frequency are distributed between rows and column.

\begin{table}
    \centering
    \renewcommand{\arraystretch}{2.5}
    \begin{tabular}{cc|c|c|c|c|}
        \cline{3-6}
        \textit{\textbf{}} &
          \textit{\textbf{}} &
          \multicolumn{4}{c|}{\textit{\textbf{Column (High Group) frequencies}}} \\ \cline{3-6}
         &
           &
          \textbf{1209 Hz} &
          \textbf{1336 Hz} &
          \textbf{1477 Hz} &
          \textbf{1633 Hz} \\ \hline
        \multicolumn{1}{|c|}{\multirow{4}{*}{ \hspace{1.2mm} \rotatebox[origin=c]{90}{\textit{\textbf{Row (Low Group) frequencies}}}}} &
          \textbf{697 Hz} &
          1 &
          2 &
          3 &
          A \\ \cline{2-6}
        \multicolumn{1}{|c|}{} & \textbf{770 Hz} & 4  & 5 & 6  & B \\ \cline{2-6}
        \multicolumn{1}{|c|}{} & \textbf{852 Hz} & 7  & 8 & 9  & C \\ \cline{2-6}
        \multicolumn{1}{|c|}{} & \textbf{941 Hz} & \# & 0 & \# & D \\ \hline
    \end{tabular}
    \caption[Keypad frequency]{Each key generates unique combination of frequency}
    \label{tab:keypad}
\end{table}

\par For example if the customer presses 8 , audio of frequency 2188Hz (1336+852) is generated and transmitted via telephone line. At the receiving center, they are passed through a decoder to generate the key value 8.

\section{Number systems - Binary and Decimal}

\par In the digital world, number are represented in various forms. For humans to read smoothly, we in our day to day life make use of Decimal numbers. Decimal numbers have 10 possible digits, ranging from 0 to 9. All number are generated by placing these symbol in one’s, ten’s, hundred’s places. Notice that the places are represented as powers of 10. To remind that the number is in decimal system and not in some other system, we write 10 as its subscript. Since decimal numbers are the mostly used, its automatically assumed that the number is in decimal form, if there are no subscript written. Table \ref{tab:decimal} depicts few examples of decimal numbers.

\begin{table*}
    \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{|c|c|c|c|c|}
    \hline
    \textit{\textbf{Decimal pattern}} &
      \textit{\textbf{\begin{tabular}[c]{@{}c@{}}Thousand’s place\\ $10^3$\end{tabular}}} &
      \textit{\textbf{\begin{tabular}[c]{@{}c@{}}Hundred’s place\\ $10^2$\end{tabular}}} &
      \textit{\textbf{\begin{tabular}[c]{@{}c@{}}Ten’s place\\ $10^1$\end{tabular}}} &
      \textit{\textbf{\begin{tabular}[c]{@{}c@{}}One’s place\\ $10^0$\end{tabular}}} \\ \hline
    \textbf{$(1598)_{10}$} & 1 & 5 & 9 & 8 \\ \hline
    \textbf{$(559)_{10}$}  &   & 5 & 5 & 9 \\ \hline
    \textbf{$(48)_{10}$}   &   &   & 4 & 8 \\ \hline
    \textbf{$7_{10}$}      &   &   &   & 7 \\ \hline
    \end{tabular}
    \vspace{3mm}
    \caption[Decimal Number system]{Decimal number system}
    \label{tab:decimal}
\end{table*}

\par Consider a system that can accept N number of decimal digits (places), it means that the system can have $(base)^N$ possible values i.e., $10^N$ possible values ranging from 0 to $10^N - 1$ numbers. Assume we can accept any 4 digit decimal number. It means that there can be $10^4 = 10000$ values ranging from 0 to 9999

\paragraph{ } Computers are digital systems where signal/states are represented by 0V or 5V. They have only 2 states possible. To execute any instruction, they require an array of 2 states called “bi-nary”. Each state are called as a \textbf{bit}. Bit zero represents 0V and bit one represents 5V. To work upon decimal numbers, digital system needs to convert and represent decimal number as its equivalent binary numbers.

\par Consider a 3 bit binary number. There can be total of $2^3 = 8$ possible values, ranging from 0 to 7 as shown in the table \ref{tab:binary}.

\begin{table}
    \centering
     \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{|c|c|c|c|c|}
    \hline
        \textbf{\textit{Binary pattern}} & \textbf{\textit{$2^2$}} & \textbf{\textit{$2^1$}} & \textbf{\textit{$2^0$}} & \textbf{\textit{Decimal equivalent }}\\ \hline
        $(000)_2$ & 0 & 0 & 0 & 0 \\ \hline
        $(001)_2$ & 0 & 0 & 1 & 1 \\ \hline
        $(010)_2$ & 0 & 1 & 0 & 2 \\ \hline
        $(011)_2$ & 0 & 1 & 1 & 3 \\ \hline
        $(100)_2$ & 1 & 0 & 0 & 4 \\ \hline
        $(101)_2$ & 1 & 0 & 1 & 5 \\ \hline
        $(110)_2$ & 1 & 1 & 0 & 6 \\ \hline
        $(111)_2$ & 1 & 1 & 1 & 7 \\ \hline
    \end{tabular}
    \caption[Binary system]{A 3 bit binary to decimal mapping}
    \label{tab:binary}
\end{table}

\vspace{5mm}
\par You might have heard of byte, kilo byte, megabyte etc. They denote range of collection of bits to represent an information. If “int” is 4 bytes long, it means it can have $4*8 = 32bits = 4294967296$ possible values. See table \ref{fig:memory_size}

\begin{table}
    \centering
    \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{|l|l|l|}
    \hline
        4 bit &  =1 nibble & $2^4$ = 16                                     combinations \\ \hline
        8 bit & = 1 byte & $2^8$ = 256                                   combinations \\ \hline
        $2^{10}$ byte & = 1 kilobyte & $2^{18}$ = 262144                           combinations \\ \hline
        $2^{10}$ kilobyte & = 1 megabyte & $2^{28}$ = 268435456                     combinations \\ \hline
        $2^{10}$ megabyte & = 1 gigabyte & $2^{38}$ = 274877906944               combinations \\ \hline
    \end{tabular}
    \caption[Memory size]{Computer memory capacity}
    \label{fig:memory_size}
    \setfloatalignment{b}
\end{table}

\section{Converting Decimal to Binary}

To convert a decimal number to its equivalent binary number, keep dividing the number by 2 and append the remainders in reverse order (bottom to top) as shown in figure \ref{fig:dec_to_bin}.

\begin{figure}
    \centering
    \includegraphics{Images/DTMF/decimal_to_binary.png}
    \caption[Decimal to binary]{Converting to binary}
    \label{fig:dec_to_bin}
    \setfloatalignment{b}
\end{figure}

\section{Converting Binary to Decimal}

To convert binary number to its equivalent decimal number, keep multiplying the binary digit with $2^p$ , where p is digit position starts from zero and then find its sum as depicted in table \ref{tab:bin_to_dec}.

\begin{table*}
    \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{|c|c|c|c|c|c|}
    \hline
        \textbf{\textit{Position values}} & \textbf{\textit{$2^3$ = 8}} & \textbf{\textit{$2^2$ = 4}} & \textbf{\textit{$2^1$ = 2}} & \textbf{\textit{$2^0$ = 1}} & \textbf{\textit{Decimal value}} \\ \hline
        Binary pattern1 = $(1011)_2$ & 1 & 0 & 1 & 1 & 1*$2^3$  + $0*2^2$ + 1*$2^1$ + 1*$2^0$ = $11_{10}$ \\ \hline
        Binary pattern2 = $(110)_2$ &  & 1 & 1 & 0 & 1*$2^2$ + 1*$2^1$ + $0*2^0$ = $6_{10}$ \\ \hline
    \end{tabular}
    \vspace{3mm}
    \caption[Binary to decimal]{Converting to decimal}
    \label{tab:bin_to_dec}
\end{table*}

\section{MT8870 DTMF Decoder}

\ac{DTMF} decoder is a module the accepts the audio frequency and converts them to the digital signals. The audio can be fetched from a mobile phone via aux cable ( headphone set ) and connect it to the aux jack of the module.

\begin{figure}
    \centering
    \includegraphics[width=4.3in]{Images/DTMF/DTMF_series.png}
    \caption[MT8870 DTMF decoder]{Various models of \ac{DTMF} decoder}
\end{figure}

\par The board needs to be powered up via 5V pins and the decoded output is received via pins Q1,Q2,Q3,Q4 in binary format. Table \ref{fig:dtmf_map} shows the mapping of key pressed from binary to decimal value.

\begin{table*}
    \renewcommand{\arraystretch}{1.2}
    \vspace{3mm}
    \begin{tabular}{|c|c|c|c|c|c|c|c|}
    \hline
        \textbf{Key pressed} & \textbf{Audio frequency[Hz]} & \textbf{Q4} & \textbf{Q3} & \textbf{Q2} & \textbf{Q1} & \textbf{Binary pattern} & \textbf{Decimal equivalent} \\ \hline
        1 & 1906 & 0 & 0 & 0 & 1 & 1 & 1 \\ \hline
        2 & 2033 & 0 & 0 & 1 & 0 & 10 & 2 \\ \hline
        3 & 2174 & 0 & 0 & 1 & 1 & 11 & 3 \\ \hline
        4 & 1979 & 0 & 1 & 0 & 0 & 100 & 4 \\ \hline
        5 & 2106 & 0 & 1 & 0 & 1 & 101 & 5 \\ \hline
        6 & 2247 & 0 & 1 & 1 & 0 & 110 & 6 \\ \hline
        7 & 2061 & 0 & 1 & 1 & 1 & 111 & 7 \\ \hline
        8 & 2188 & 1 & 0 & 0 & 0 & 1000 & 8 \\ \hline
        9 & 2329 & 1 & 0 & 0 & 1 & 1001 & 9 \\ \hline
        0 & 2150 & 1 & 0 & 1 & 0 & 1010 & 10 \\ \hline
        $*$ & 2277 & 1 & 0 & 1 & 1 & 1011 & 11 \\ \hline
        \# & 2418 & 1 & 1 & 0 & 0 & 1100 & 12 \\ \hline
        A & 1906 & 1 & 1 & 0 & 1 & 1101 & 13 \\ \hline
        B & 2033 & 1 & 1 & 1 & 0 & 1110 & 14 \\ \hline
        C & 2174 & 1 & 1 & 1 & 1 & 1111 & 15 \\ \hline
        D & 1979 & 0 & 0 & 0 & 0 & 0 & 0 \\ \hline
    \end{tabular}
    \vspace{3mm}
    \caption[DTMF pattern]{Mapping \ac{DTMF} inputs to decimal values}
    \label{fig:dtmf_map}
\end{table*}

\section{Programming DTMF decoder}

\par As shown in figure \ref{fig:dtmf_ckt}, the q1,q2,q3,q4 of \ac{DTMF} is connected to 7,6,5,4 pins of Arduino respectively. The StD pin is connected to pin3, which turns HIGH whenever the module receives a new frequency. The module is powered via 5V line and is connected to a cell phone via aux cable. The Phone acts as receiver/switch center. Lets write a code to interpret the \ac{DTMF} signals.

\begin{figure}
    \centering
    \includegraphics[width=4.3in]{Images/DTMF/DTMF_ckt.png}
    \caption[DTMF with Arduino]{Circuit diagram for interfacing \ac{DTMF} with Arduino Uno }
    \label{fig:dtmf_ckt}
\end{figure}

\begin{lstlisting}[style=CStyle]
int Q1=7, Q2=6, Q3=5, Q4=4, StD = 3; //pin allocations
int dec_number;

void setup(){
    //set pins as input for Arduino.
    pinMode(Q1,INPUT);pinMode(Q2,INPUT);
    pinMode(Q3,INPUT);pinMode(Q4,INPUT);
    pinMode(StD,INPUT);

    Serial.begin(9600);
}

void loop(){
    dec_number = 0;

    if(digitalRead(StD)==HIGH){ //received new frequency

        //converting binary signals to decimal number
        //using bit manipulation in C
        dec_number |= digitalRead(Q1)<<0 ;  //2^0 position
        dec_number |= digitalRead(Q2)<<1 ;	//2^1 position
        dec_number |= digitalRead(Q3)<<2 ;	//2^2 position
        dec_number |= digitalRead(Q4)<<3 ;	//2^3 position
        Serial.print("The code is ");
        Serial.println(dec_number);
    }
}
\end{lstlisting}

\par Now make a call to the receiver phone \textbf{“A”} from another phone \textbf{“B”}. Make key presses in the phone B so that corresponding audio is heard at the phone A. Observe the Serial monitor for the output. It might happen that you cannot observe proper detection in the Serial monitor. This can be due to various factor like different audio jack material, internal phone circuitry, phone model and version etc. Try with some other phones. Have you ever noticed that whenever we press the button on earphone mic, it behaves differently in different phones?

\paragraph{ } Can you reconfigure the system to control a bot? Go through the section \ref{section:bot_interface} to get an idea to integrate the bot with \ac{DTMF}. Your wireless bot is ready for action.

\begin{figure}
	\centering
	\includegraphics[width=4.3in]{Images/DTMF/wireless_bot.png}
	\caption{Wireless bot using DTMF}
\end{figure}


\documentclass[12pt]{article}
\usepackage[pdftex]{graphicx}
\newcommand{\kg}{\mathrm{kg}}
\newcommand{\m}{\mathrm{m}}
\newcommand{\cm}{\mathrm{cm}}
\newcommand{\mm}{\mathrm{mm}}
\newcommand{\km}{\mathrm{km}}
\newcommand{\mi}{\mathrm{mi}}
\newcommand{\s}{\mathrm{s}}
\newcommand{\ms}{\mathrm{ms}}
\newcommand{\h}{\mathrm{h}}
\newcommand{\N}{\mathrm{N}}
\newcommand{\J}{\mathrm{J}}
\newcommand{\W}{\mathrm{W}}
\newcommand{\hp}{\mathrm{hp}}
\newcommand{\rad}{\mathrm{rad}}
\newcounter{problem}
\stepcounter{problem}
\newcounter{answer}[problem]
\newenvironment{problem}{\noindent\begin{minipage}{\textwidth}\sloppy\sloppypar\raggedright\textbf{\theproblem.}\refstepcounter{problem}\stepcounter{answer}---}{\end{minipage}\vspace{2ex}}
\newcommand{\source}[1]{[{#1}]}
\newenvironment{answers}{\\}{}
\newcommand{\answer}[1]{\textbf{\Alph{answer}:}\refstepcounter{answer}~\mbox{#1\hspace{3ex}}}
\begin{document}

\section*{NYU General Physics 1---Final Exam}

\begin{problem}
  \source{from lecture 2011-09-06} What is the mass of a cubic
  kilometer (a cube one km on a side) of water?
  \begin{answers}
    \answer{$10^{6}\,\kg$}
    \answer{$10^{8}\,\kg$}
    \answer{$10^{10}\,\kg$}
    \answer{$10^{12}\,\kg$}
    \answer{nowhere near any of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-08} A dense, heavy ball marked ``1''
  takes time $t_1$ to fall from a height of $1\,\m$, and an identical
  ball marked ``2'' takes time $t_2$ to fall from a height of $4\,\m$,
  both near the surface of the Earth.  If air resistance is not a
  factor, what is $t_1 / t_2$?
  \begin{answers}
    \answer{1}
    \answer{0.5}
    \answer{0.25}
    \answer{0.125}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-13} A girl throws a stone at an angle
  $\theta$ to the horizontal, so it flies upwards and to the right.
  Subsequently, because of gravity, it travels on a parabolic
  trajectory.  Precisely at the top of its parabolic trajectory, when
  it is exactly at its highest point, what is the acceleration of the
  stone?  Ignore air resistance.
  \begin{answers}
    \answer{0}
    \answer{$9.8\,\m\,\s^{-2}$ to the right}
    \answer{$9.8\,\m\,\s^{-2}$ to the left}
    \answer{$9.8\,\m\,\s^{-2}$ straight down}
    \answer{not enough information to say}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-15} A car, starting at rest,
  accelerates at a constant acceleration of $0.5\,\m\,\s^{-2}$ in the
  $x$ direction for $10\,s$.  How far does the car go during this
  $10\,\s$ period?
  \begin{answers}
    \answer{$0.5\,\m$}
    \answer{$5\,\m$}
    \answer{$10\,\m$}
    \answer{$25\,\m$}
    \answer{$50\,\m$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-20} A block is placed on a frictionless
  inclined plane and released.  After release, if we ignore air
  resistance, how many forces are there to consider?  That is, how
  many non-zero forces are there on the free-body diagram for the block?
  \begin{answers}
    \answer{1}
    \answer{2}
    \answer{3}
    \answer{4}
    \answer{more than 4}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-27} An airplane turns in a horizontal
  turn---turns without gaining or losing altitude---by banking.  You
  can think of the airplane as having four forces acting on it:
  Gravity $m\,\vec{g}$, a combined normal force $\vec{N}$ coming from
  the two wings, a thrust force driving the plane through the air, and
  a drag force.  What is true as it is turning in its banked turn?
  \begin{answers}
    \answer{$|\vec{N}|>|m\,\vec{g}|$}
    \answer{$|\vec{N}|<|m\,\vec{g}|$}
    \answer{$\vec{N}+m\,\vec{g}=0$}
    \answer{The net force is in the vertical direction.}
    \answer{None of the above are true.}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-09-29} A textbook of mass $m$ is dropped
  from a high height onto a hard surface.  When it hits the surface,
  it is initially moving quickly (downwards) but it rapidly changes
  its velocity (it bounces!).  While it is in contact with the
  surface---while it is bouncing---or changing its velocity---it is
  subject to a contact force $\vec{N}$ that obeys the following:
  \begin{answers}
    \answer{$\vec{N}$ acts downwards and $|\vec{N}| > |m\,\vec{g}|$}
    \answer{$\vec{N}$ acts downwards and $|\vec{N}| = |m\,\vec{g}|$}
    \answer{$\vec{N}$ acts upwards and $|\vec{N}| = |m\,\vec{g}|$}
    \answer{$\vec{N}$ acts upwards and $|\vec{N}| > |m\,\vec{g}|$}
    \answer{none of these is true}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-10-06} In lecture, Prof Hogg swung a full
  coffee cup over his head on a circular arc.  Why did the coffee stay
  in the cup when it was directly above his head?
  \begin{answers}
    \answer{The cup was accelerating downwards with $|\vec{a}|>|\vec{g}|$.}
    \answer{The cup was accelerating downwards with $|\vec{a}|<|\vec{g}|$.}
    \answer{The cup was applying an upward force on the coffee.}
    \answer{The cup was applying no force on the coffee.}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-10-13} We considered a block sliding down
  a frictionless hill and off a frictionless jump.  The block flew up
  into the air, but it did not return to the height from which it
  started.  Why not?
  \begin{answers}
    \answer{Energy was not conserved.}
    \answer{The block lost energy to heat during its slide.}
    \answer{Not all of the potential energy was converted into kinetic energy.}
    \answer{After the jump, the horizontal component of velocity is constant.}
    \answer{There are energies other than kinetic and potential to consider.}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-10-18} A bullet lodged in a block.  What
  statement about the collision is true?
  \begin{answers}
    \answer{It was elastic because energy was conserved.}
    \answer{It was inelastic because energy was not conserved.}
    \answer{It was elastic because kinetic energy was conserved.}
    \answer{It was inelastic because kinetic energy was not conserved.}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-10-20} A block of mass $m_1=1\,\kg$
  moves at speed $|\vec{v}_1|=3\,\m\,\s^{-1}$ in the positive-$x$
  direction; another block of mass $m_2=0.5\,\kg$ moves at speed
  $|\vec{v}_2|=4\,\m\,\s^{-1}$ in the negative-$x$ direction.  What is
  the center-of-mass velocity of the two-block system?
  \begin{answers}
    \answer{$0.667\,\m\,\s^{-1}$ in the positive-$x$ direction}
    \answer{$1.0\,\m\,\s^{-1}$ in the positive-$x$ direction}
    \answer{$3.333\,\m\,\s^{-1}$ in the positive-$x$ direction}
    \answer{$5.0\,\m\,\s^{-1}$ in the positive-$x$ direction}
    \answer{nowhere near any of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-10-25} In lecture we thought about having
  a heavy mass $M$ on a light table-top supported by two sawhorses
  separated by a distance $L=100\,\cm$.  If you want the leftmost
  sawhorse to take roughly 2/3 of the weight, where should you put the
  mass?
  \begin{answers}
    \answer{more-or-less right over the left support}
    \answer{about $25\,\cm$ to the right of the left support}
    \answer{about $33\,\cm$ to the right of the left support}
    \answer{about $50\,\cm$ to the right of the left support}
    \answer{more than $50\,\cm$ to the right of the left support}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-11-01} Dimensionally, the fundamental
  frequency of a guitar string of length $L$ with mass $M$ at tension
  $T$ must be
  \begin{answers}
    \answer{$\displaystyle f = \frac{1}{2}\,\sqrt{\frac{M}{T\,L}}$}
    \answer{$\displaystyle f = \frac{1}{2}\,\sqrt{\frac{L}{M\,T}}$}
    \answer{$\displaystyle f = \frac{1}{2}\,\sqrt{\frac{T}{M\,L}}$}
    \answer{$\displaystyle f = \frac{1}{2}\,\sqrt{\frac{T\,L}{M}}$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-11-10} You have a harmonic oscillator
  oscillating according to the following formula for position as a function of time:
  $$x = A\,\cos(\omega\,t + \phi)$$ What is the kinetic energy as a
  function of time?
  \begin{answers}
    \answer{$\displaystyle K = \frac{1}{2}\,m\,A^2\,\sin^2(\omega\,t + \phi)$}
    \answer{$\displaystyle K = \frac{1}{2}\,m\,A^2\,\cos^2(\omega\,t + \phi)$}
    \answer{$\displaystyle K = \frac{1}{2}\,m\,\omega^2\,A^2\,\sin^2(\omega\,t + \phi)$}
    \answer{$\displaystyle K = \frac{1}{2}\,m\,\omega^2\,A^2\,\cos^2(\omega\,t + \phi)$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-11-15} How far does a traveling sinusoidal
  wave pattern of frequency $f$ traveling at speed $v$ travel in one
  period $T$?
  \begin{answers}
    \answer{$v\,f$}
    \answer{$\displaystyle\frac{f}{v}$}
    \answer{$\displaystyle\frac{1}{f}$}
    \answer{one wavelength}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-11-17} In lecture we made a standing wave
  by adding together two traveling waves.  These waves had the
  following properties.  \emph{Hint: Recall that at certain particular
    times, the two waves summed to exactly zero.}
  \begin{answers}
    \answer{same period, same amplitude, different directions of travel}
    \answer{same period, different amplitude, different directions of travel}
    \answer{different period, same amplitude, different directions of travel}
    \answer{different period, different amplitude, same direction of travel}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-11-22} A one-atmosphere pressure
  difference can be provided by $10\,\m$ of water or $0.76\,\m$ of
  mercury.  What is the origin of this difference between water and
  mercury?
  \begin{answers}
    \answer{$P\,V=n\,R\,T$ means smaller volume makes for higher pressure}
    \answer{the gravitational acceleration $\vec{g}$ is bigger for mercury}
    \answer{mercury is more than ten times more dense than water}
    \answer{the water is below sea level, but the mercury is above it}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-11-29} A helium balloon is floating in the
  middle of a stationary, sealed (airtight), air-filled bus parked on
  Broadway.  The driver starts the bus and accelerates forwards for
  many seconds.  During this long period of steady acceleration, how
  does the balloon move, relative to the bus?
  \begin{answers}
    \answer{the balloon moves towards the front of the bus}
    \answer{the balloon stays where it is}
    \answer{the balloon moves towards the back of the bus}
    \answer{more information is needed to answer this question}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-12-01} A cylindrical pipe has constant
  cross-sectional area (constant radius $R$).  Incompressible fluid is
  forced into one end at a particular rate $\Gamma$ (volume per time).
  What is the flow velocity in the pipe?
  \begin{answers}
    \answer{$\displaystyle v = 2\pi\,R\,\Gamma$}
    \answer{$\displaystyle v = \pi\,R^2\,\Gamma$}
    \answer{$\displaystyle v = \frac{\Gamma}{2\pi\,R}$}
    \answer{$\displaystyle v = \frac{\Gamma}{\pi\,R^2}$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-12-06} If there is a horizontal pressure
  gradient in a fluid (that is, if the pressure is higher at one point
  $P$ than it is at some other point $Q$ at the same altitude or
  height), then which of the following must be true?  Assume that the
  acceleration due to gravity $\vec{g}$ points directly downwards
  (that is, vertically).
  \begin{answers}
    \answer{the fluid must be compressible}
    \answer{there must be a horizontal acceleration}
    \answer{the fluid must be flowing in a pipe}
    \answer{none of these}
    \answer{actually, this situation cannot happen}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from lecture 2011-12-13} A surface tension $\sigma$ is a
  force per unit length.  If $L$ has dimensions of length, which of
  these is an energy?
  \begin{answers}
    \answer{$\sigma$}
    \answer{$\sigma\,L$}
    \answer{$\sigma\,L^2$}
    \answer{$\sigma\,L^3$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 1, problem 1} What, approximately, is the
  density of money?
  \begin{answers}
    \answer{$0.1\,\kg\,\m^{-3}$}
    \answer{$10\,\kg\,\m^{-3}$}
    \answer{$1000\,\kg\,\m^{-3}$}
    \answer{$10^5\,\kg\,\m^{-3}$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 2, problem 1} A dragster travels 0.25\,mi
  in 5.5\,s, starting from rest.  Under the assumption of constant
  acceleration, what is the time it takes the dragster to go half-way;
  that is, how many seconds does it take to go the first 0.125\,mi?
  \begin{answers}
    \answer{substantially less than $1.38\,\s$}
    \answer{$1.38\,\s$}
    \answer{$2.75\,\s$}
    \answer{$3.9\,\s$}
    \answer{substantially more than $3.9\,\s$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 2, problem 2} A rock is thrown directly
  upwards at $3\,\m\,\s^{-1}$.  What velocity will it have after
  $1\,\s$?  Calculate for the gravitational trajectory but ignore air
  resistance.
  \begin{answers}
    \answer{$13\,\m\,\s^{-1}$ upwards}
    \answer{$3\,\m\,\s^{-1}$ upwards}
    \answer{$3\,\m\,\s^{-1}$ downwards}
    \answer{$7\,\m\,\s^{-1}$ downwards}
    \answer{nothing near any of these}
  \end{answers}
\end{problem}

%% \begin{problem}
%%   \source{from problem set 3, problem 1} The Space Station orbits
%%   about $300\,\km$ above the surface of the Earth.  What is the radius
%%   of its orbit, roughly?
%%   \begin{answers}
%%     \answer{$300\,\km$}
%%     \answer{$1300\,\km$}
%%     \answer{$6700\,\km$}
%%     \answer{$600,300\,\km$}
%%     \answer{nowhere near any of these}
%%   \end{answers}
%% \end{problem}

\begin{problem}
  \source{from problem set 3, problem 2} What is the tension T in this
  problem?\\\includegraphics{../py/stringblocks.pdf}
  \begin{answers}
    \answer{$\displaystyle m_1\,g$}
    \answer{$\displaystyle m_2\,g$}
    \answer{$\displaystyle F$}
    \answer{$\displaystyle F\,\frac{m_1}{m_1+m_2}$}
    \answer{$\displaystyle F\,\frac{m_2}{m_1+m_2}$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 4, problem 1} A block of mass $m$ sits on a
  plane inclined at an angle of $\theta=20\,\deg$ to the horizontal.
  There is a coefficient of friction $\mu=0.9$ between the block and
  the plane.  What is the magnitude of the frictional force?
  \begin{answers}
    \answer{$m\,g\,\cos\theta$}
    \answer{$m\,g\,\sin\theta$}
    \answer{$\mu\,m\,g\,\cos\theta$}
    \answer{$\mu\,m\,g\,\sin\theta$}
    \answer{$\mu\,m\,g\,\tan\theta$}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 5, problem 1} The driver of a car traveling
  east slams on the brakes, so that the car goes through a period of
  rapid deceleration.  The total force on the ground from the car must
  \begin{answers}
    \answer{have a downwards component and an eastwards component}
    \answer{have a downwards component and a westward component}
    \answer{have an upwards component and an eastwards component}
    \answer{have an upwards component and a westward component}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 5, problem 3} Which of these does
  \emph{not} have units of energy?  In these formulae, $m$ is a mass,
  $v$ is a speed, $P$ is a pressure, $L$ is a length, and $F$ is a
  force.
  \begin{answers}
    \answer{$m\,v$}
    \answer{$m\,v^2$}
    \answer{$P\,L^3$}
    \answer{$F\,L$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 6, problem 1} If a $50\,\kg$ student climbs
  9 flights of stairs, about how much work does she do?
  \begin{answers}
    \answer{$50\,\J$}
    \answer{$500\,\J$}
    \answer{$1500\,\J$}
    \answer{$15,000\,\J$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 7, problem 1} Which of these figures---cut
  from a sheet of constant-thickness aluminum---has its center of
  mass at the point $(x,y) = (-1/3,-1/3)\,\cm$?
  \begin{answers}
  \includegraphics[width=\textwidth]{../py/com_shapes.pdf}\addtocounter{answer}{4}
  \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 7, problem 2} Just before jumping out of
  the way, a (daring) student throws a ball at $20\,\mi\,\h^{-1}$
  straight at a bus moving towards the student at $35\,\mi\,\h^{-1}$.
  Assume that these are the speeds just before the collision, that the
  collision is head-on, that the collision is elastic, and that the
  front of the bus is a flat, vertical plane.  Right after the
  collision (after the ball leaves contact with the bus), what will be
  the speed of the ball?  Give your answer for the original reference
  frame.
  \begin{answers}
    \answer{$60\,\mi\,\h^{-1}$}
    \answer{$70\,\mi\,\h^{-1}$}
    \answer{$80\,\mi\,\h^{-1}$}
    \answer{$90\,\mi\,\h^{-1}$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 8, problem 2} When you are holding a heavy
  grocery bag in your hand, and your arm is bent so that the upper arm
  is vertical and the forearm is horizontal, which of the following is
  true of the magnitude of the tension in your bicep and the magnitude
  of the weight of the bag?
  \begin{answers}
    \answer{the tension is much less than the weight}
    \answer{the tension is about the same as the weight}
    \answer{the tension is much more than the weight}
    \answer{it depends}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 9, problem 2} A mass $m$ attached to a
  spring oscillates with amplitude $A$ (a length) and angular
  frequency $\omega$.  What is the total energy $E$ in the oscillator?
  \begin{answers}
    \answer{$\displaystyle E=\frac{1}{2}\,m\,\omega^2\,A^2$}
    \answer{$\displaystyle E=m\,\omega^2\,A^2$}
    \answer{$\displaystyle E=\frac{1}{2}\,k\,\omega^2\,A^2$}
    \answer{$\displaystyle E=k\,\omega^2\,A^2$}
    \answer{none of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 10, problem 1} An organ pipe that plays
  middle $C$ is about 1.1 feet long.  How long would an organ pipe
  be that plays $C$ but one octave lower, that is, a factor of two
  lower in frequency?
  \begin{answers}
    \answer{0.55 feet}
    \answer{0.78 feet}
    \answer{1.1 feet}
    \answer{1.6 feet}
    \answer{2.2 feet}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 11, problem 2} For a submerged ice cube in
  cold water, the gravitational force $|m\,\vec{g}|$ is smaller than the buoyant
  force $|\vec{F}_b|$.  What is the ratio $|m\,\vec{g}|/|\vec{F}_b|$?
  \begin{answers}
    \answer{0.92}
    \answer{0.42}
    \answer{0.08}
    \answer{0}
    \answer{nothing near any of these}
  \end{answers}
\end{problem}

\begin{problem}
  \source{from problem set 12, problem 2} If the kinematic viscosity
  $\nu$ is measured in units of $\m^2\,\s^{-1}$, then which of these
  formulae could represent a speed?  In these, $R$ is a length, and
  $g$ is an acceleration.
  \begin{answers}
    \answer{$\displaystyle\frac{g\,R^2}{\nu}$}
    \answer{$\displaystyle\frac{R}{\nu\,g}$}
    \answer{$\displaystyle\frac{g}{\nu\,R^2}$}
    \answer{$\displaystyle\frac{\nu}{g\,R}$}
    \answer{none of these}
  \end{answers}
\end{problem}

\end{document}


\PassOptionsToPackage{obeyspaces}{url}

\documentclass[12pt]{beamer}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
%\usepackage[obeyspaces]{url}

\usepackage{hyperref}

\usepackage{pythontex}

\begin{document}

%\begin{frame}[fragile]
%\py{2+2}
%\begin{pygments}{py}
%a=1
%\end{pygments}
%\end{frame}

\title{Crash Course in Python}
\author{Øystein Bjørndal}
\begin{frame}[fragile]
\maketitle
\end{frame}

\begin{frame}[fragile]
\tableofcontents
\end{frame}

\section{Python 2 vs 3}
\begin{frame}[fragile]
\frametitle{Python 2 vs 3}
\begin{columns}[T]
	\begin{column}{0.48\textwidth}
Python 2 \\
\vspace{1cm}
\pygment{py}{print "hello world"}\\
\vspace{1cm}
\pygment{py}{3/2 == 1} \\
\vspace{1cm}
\begin{small}
\begin{pygments}{py}
>>> map(str.upper, ['foo', 'baz'])
['FOO', 'BAZ']
\end{pygments}
\end{small}
	\end{column}
	\begin{column}{0.48\textwidth}
Python 3 \\
\vspace{1cm}
\pygment{py}{print("hello world")}\\
\vspace{1cm}
\pygment{py}{3/2 == 1.5} \\
\vspace{1cm}
Lazy evaluation: \\
\begin{small}
\begin{pygments}{py}
>>> map(str.upper, ['foo', 'baz'])
<map at 0x2a7c10647f0>
\end{pygments}
\end{small}
	\end{column}
\end{columns}

\begin{center}
USE PYTHON 3!
\end{center}
\end{frame}

\section{Hello world}
\begin{frame}[fragile]
\frametitle{Hello world, complete how-to}
\begin{enumerate}
\item Download and install python
\url{https://www.anaconda.com/download/} \\
Anaconda contains python and a bunch of useful packages. \\
At TI, consider installing from \url{http://software.itg.ti.com/} and fixing proxy: \url{https://infolink.sc.ti.com/business_rooms/characterization_corner/f/2782/t/80190}
(first hit when searcing for "proxy" at \url{myinfolink.ti.com/}
\item Add python to Path, either during the install or manually in Windows "Environment variables for your account"
\end{enumerate}
\end{frame}

\begin{frame}[fragile]
\frametitle{Hello world, complete how-to}
\begin{enumerate}
\setcounter{enumi}{2}
\item Write a file "hello-world.py" with
\begin{pygments}{py}
print("hello world")
\end{pygments}
\item \begin{itemize}
\item  Either use Spyder (similar to the Matlab interface with a interactive session and editor)
\item use Command prompt, type "python hello-world.py" (assuming python is on your Path
and you "cd" to the correct folder).
\end{itemize}
\item "hello world" !!
\end{enumerate}
\end{frame}

\section{Some python basics}
\begin{frame}[fragile]
\frametitle{Some python basics}
Demo:\\ \begin{small}\url{https://github.com/ehmatthes/pcc/releases/download/v1.0.0/beginners_python_cheat_sheet_pcc_all.pdf}\end{small}
\end{frame}

\section{Data science libraries}
\begin{frame}[fragile]
\frametitle{Data science libraries}
Some great libraries:
\begin{itemize}
\item Matplotlib - similar plotting interface to Matlab, just better
\item Numpy - similar optimized array/matrix operations as Matlab
\item Pandas - Uses the above 2 libraries and much more, useful for data analysis, file reading/writing
\end{itemize}
\end{frame}

\subsection{Matplotlib}
\begin{frame}[fragile]
\frametitle{Data science libraries - Matplotlib}
\begin{pyblock}
import pylab as plt
# Alternative: import pylab
# Please don't: from pylab import *

x = [1, 2, 3]
y = [2, 5, 10]

plt.plot(x, y, linestyle='--', marker='*',
	label='this is a line')
plt.legend(loc='best')
\end{pyblock}
\begin{pycode}
filename = 'fig1.pdf'
plt.savefig(filename)
plt.close(plt.gcf())
fig = r'\includegraphics[width=\textwidth]{%s}' % filename
\end{pycode}
\end{frame}

\begin{frame}[fragile]
\py{fig}
%\includegraphics[width=\textwidth]{fig1.pdf}
\end{frame}

\begin{frame}[fragile]
\frametitle{matplotlib documentation}
\url{https://matplotlib.org/api/pyplot_summary.html}
\end{frame}

\subsection{Numpy}
\begin{frame}[fragile]
\frametitle{Data science libraries - Numpy}
In the previous example, \pyv{x} and \pyv{y}, where "native" python lists, these do not work as expected from a Matlab viewpoint:
\begin{pyconsole}
x = [1, 2, 3]
y = [2, 5, 10]
x + y
x*5
# workaround
for ix in range(len(x)):
  x[ix] *= 5

x
\end{pyconsole}
\end{frame}

\begin{frame}[fragile]
\frametitle{Numpy to the rescue}
\begin{pyconsole}
import numpy as np
x = np.array([1, 2, 3])
y = np.array([2, 5, 10])
x + y
x*5
# Still works the same:
for ix in range(len(x)):
  x[ix] *= 5

x
\end{pyconsole}
\end{frame}

\begin{frame}[fragile]
\frametitle{Numpy documentation}
cheat sheet \\
\url{https://www.datacamp.com/community/blog/python-numpy-cheat-sheet} \\
\vspace{0.25cm}

Numpy for Matlab users \\
\url{https://docs.scipy.org/doc/numpy-1.14.0/user/numpy-for-matlab-users.html} \\
\vspace{0.25cm}

Documentation (or just google "numpy x")\\
\url{https://docs.scipy.org/doc/numpy-1.14.0/reference/index.html}
\end{frame}

\subsection{Pandas}
\begin{frame}[fragile]
\frametitle{Pandas documentation}
Short intro to Pandas\\
\url{https://pandas.pydata.org/pandas-docs/stable/10min.html} \\
\vspace{0.25cm}

API \\
\url{https://pandas.pydata.org/pandas-docs/stable/api.html} \\
\vspace{0.25cm}

\end{frame}

\begin{frame}[fragile]
\frametitle{Pandas}
\begin{pyblock}
import pandas as pd
s = pd.Series([2, 5, 10], index=(1000,2000,3000))
s[1000] # 2
s.plot(grid=True)
\end{pyblock}
\begin{pycode}
filename = 'fig2.pdf'
plt.savefig(filename)
fig2 = r'\includegraphics[width=\textwidth]{%s}' % filename
\end{pycode}
\end{frame}

\begin{frame}[fragile]
\py{fig2}
\end{frame}

\begin{frame}[fragile]
\frametitle{Pandas indexing series}
\begin{pyconsole}
import pandas as pd
s = pd.Series([2, 5, 10], index=(1000,2000,3000))
s[1000]
s.iloc[0]
s[3000]
s.iloc[-1]
\end{pyconsole}
\end{frame}

\begin{frame}[fragile]
\frametitle{Pandas indexing series, using strings}
\begin{pyconsole}
import pandas as pd
s = pd.Series([2, 5, 10], index=('Experiment 1',
					'Debug',
					'Debug-Debug'))
s['Experiment 1']
s.iloc[0]
s['Debug-Debug']
s.iloc[-1]
\end{pyconsole}
\end{frame}

\begin{frame}[fragile]
\frametitle{Calling from LabView}
\url{https://oslosvn.norway.design.ti.com/svn/lab/Kharon LabView 2016/trunk/Register files/Auto update register files/call_python.vi}

\vspace{1cm}
Example usage
\begin{itemize}
\item \url{https://oslosvn.norway.design.ti.com/svn/lab/Kharon LabView 2016/trunk/User Lib/Generic instrument methods/General/Log_Instr_excel.vi}
\item \url{https://oslosvn.norway.design.ti.com/svn/lab/Kharon LabView 2016/trunk/User Lib/Utilities/Reporting/Report tool/Panels/MergeToSpotfire/concatenate_csv_MAIN.vi}
\end{itemize}
\end{frame}

\section{Style guide}
\begin{frame}[fragile]
\frametitle{PEP 8}
Write better code
\url{https://www.python.org/dev/peps/pep-0008/?}\\
Not intended for beginner python users, but shows some interesting syntax and use cases and
describes best-practices.

\end{frame}

\begin{frame}[fragile]
\begin{footnotesize}
\begin{pyconsole}
import this
\end{pyconsole}
\end{footnotesize}
\end{frame}
\end{document}


%%\documentclass[handout]{beamer}
%\documentclass[aspectratio=169,13pt]{beamer}

%\input{./preamble}

\subtitle{Nonlinear Equations}

\date{}
\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\section{Problem and Approach}

\begin{frame}{Solving Nonlinear Equations}

\urcornerlinkinclass{inclass-newton-2-by-2}{Newton's Method for 2-by-2 System of Equations}

\begin{itemize}
\item
Solving (systems of) nonlinear equations corresponds to root finding:
\begin{itemize}
\sitem $f(x^*)=0$ \smcond{univariate nonlinear function}
\sitem $f(\B{x}^*)=0$ \smcond{multivariate, scalar-valued nonlinear function}
\sitem $\B f(\B x^*) = \B 0$ \smcond{multivariate, vector-valued nonlinear function}
\sitem Algorithms for root-finding make it possible to solve systems of nonlinear equations and employ a similar methodology to finding minima in optimization.
\end{itemize}

%\mdcond{}

\sitem
Main algorithmic approach: find successive roots of local linear approximations of $\B f$:

\lgcond{
\begin{itemize}
%\item various alternatives exist, including simple $\B g(\B x) = \B x - \B f(\B x)$
\item Newton's method for univariate functions starting at point $x_k$ finds root of $ h(\delta x) = f(x_k) + f'(x_k)\delta x\approx f(x_k+\delta x)$, so
\[x_{k+1} = x_k + \delta x =  x_k - f(x_k)/f'(x_k)\]
\item Newton's method for multivariate functions starting at point $\B x_k$ finds root of $\B h(\B{\delta x}) = \B f(\B x_k) + \B J_{\B f}(\B x_k)\B{\delta x}\approx \B f(\B x_k+\B{\delta x})$, with
Jacobian $(\B J_{\B f}(\B x))_{ij} = \frac{\delta f_i}{\delta x_j}(\B x)$, so
  \[\B x_{k+1} = \B x_{k} + \B{\delta x} = \B x_k - \B J^{-1}_{\B f}(\B x_k) \B f(\B x_k)\]
%\sitem Newton's method achieves very rapid convergence due to the derivative/Jacobian of the fixed-point function going to zero at the root, i.e.
%\[g'(x^*)=0 \quad \text{and more generally} \quad \B J_{\B g}(\B x^*)=\B O\]
\end{itemize}
}

\end{itemize}

\end{frame}

\section{Existence, Uniqueness, and Conditioning}

\begin{frame}{Nonexistence and Nonuniqueness of Solutions}

\urcornerlinkdemo{05-nonlinear-equations}{Three quadratic functions}

\begin{itemize}
\item Solutions do not generally exist and are not generally unique, even in the univariate case:

\lgcond{
Consider functions that are strictly greater than zero or have many zeros.
}

\item Solutions in the multivariate case correspond to intersections of hypersurfaces:

\lgcond{
The zeros of each equation define a \coloremph{hypersurface} in $\mathbb{R}^{n}$, in the linear case, these are \coloremph{hyperplanes}.
Intersections of hypersurfaces for many equations, define the solutions, which are roots of all equations.

\smallskip

Consider that two curves can intersect at many points in space.
Two hypersurfaces in three-dimensional space may not intersect or may have multiple \coloremph{curves of intersection}.
}

\end{itemize}

\end{frame}

\begin{frame}{Conditions for Existence of Solution}

\begin{itemize}
\item \coloremph{Intermediate value theorem} for univariate problems:

\lgcond{
If for $a<b$, $\mathop{sign}(f(a))\neq \mathop{sign}(f(b))$ and $f$ is continuous, then $[a,b]$ is a \coloremph{bracket} that contains a root,
\[\exists x^*{\in}[a,b],\quad f(x^*)=0.\]
}
\item A function has a unique \coloremph{fixed point} $\B g(\B x^*)= \B x^*$ in a given closed domain if it is \coloremph{contractive} and contained in that domain,
\[||\B g(\B x) - \B g (\B z)|| \leq \gamma ||\B x - \B z||\]

\lgcond{
\begin{itemize}
\item Contained implies that in the domain $S$, for any $\B x \in S$,  $\B g( \B x) \in S$, while contractive implies that the function is Lipschitz continuous in $S$.
\sitem When solving for a root of $\B f$, can define various fixed point functions $\B g$, so that their solution $\B g(\B x^*) = \B x^*$ provides a root of $\B f$, $\B f(\B x^*) =\B 0$, the simplest being $\B g(\B x)=\B f(\B x) + \B x$.
\end{itemize}
}
\end{itemize}

\end{frame}

%\begin{frame}{Conditions for Uniqueness of Solution}
%
%\begin{itemize}
%\item  The solution is unique within a neighborhood, if for root $\B x^*$, \(\B{J}_{\B{f}}(\B{x}^*)\) is nonsingular:
%\lgcond{
%\[ \B J_{\B{f}} (\B{x}) = {\footnotesize \begin{bmatrix}
%     \frac{df_1}{dx_1}(\B{x}) & \cdots & \frac{df_1}{dx_n}(\B{x})\\
%     \vdots &  & \vdots \\
%     \frac{df_m}{dx_1}(\B{x}) & \cdots & \frac{df_m}{dx_n}(\B{x})
%   \end{bmatrix}   }\]
%If $\B{J}_{\B{f}}(\B{x}^*)$ is singular, $\exists \B s \neq \B 0$ so that $\B{J}_{\B{f}}(\B{x}^*)\B s=\B 0$, which means a linear approximation cannot distinguish the solution from a nearby point, $\B x^* + \alpha \B s$, which may or may not be another root.
%
%}
%\lgcond{}
%\end{itemize}
%
%\end{frame}

\section{Multiple Roots and Conditioning}

\begin{frame}{Conditioning of Nonlinear Equations}

\begin{itemize}
\item Generally, we take interest in the absolute rather than relative conditioning of solving $\B f(\B x)= \B 0$:

\lgcond{
\begin{itemize}
\item The sensitivity of solving a nonlinear equation is the ratio of magnitudes of the perturbation to the root and perturbation to the function values.
\sitem It makes sense to consider absolute perturbations to $\B f$, since any nonzero perturbation to function values is infinite in magnitude relative to $\B f(\B x^*)=\B 0$.
\end{itemize}
}

\item The \coloremph{absolute condition number} of finding a root $x^*$ of $f$ is $1/|f'(x^*)|$ and for a root  $\B x^*$ of $\B f$ it is  $||\B{J}_{\B f}^{-1}(\B x^*)||$:

\lgcond{
\begin{itemize}
\item  If we change the value of $f$ by at most $\delta f$ at any point in the function while maintaining continuity, the root will shift by at most $|\delta f|/|f'(x^*)|$ assuming $|\delta f|$ is sufficiently small.
\sitem This relationship is the converse of conditioning in function evalution, where a perturbation to input $x$, results in a perturbation of at most $\kappa_\text{abs}(f)=|f'(x)|$ larger to the function value.
\end{itemize}
}

\end{itemize}

\end{frame}

\begin{frame}{Multiple Roots and Degeneracy}

\begin{itemize}
\item If $x^*$ is a root of $f$ with \coloremph{multiplicity} $m$, its $m-1$ derivatives are also zero at $x^*$,
\[f(x^*)=f'(x^*)=f''(x^*) = \cdots = f^{(m-1)}(x^*)=0.\]

\lgcond{
Proof: for some function $t^{(0)}(x)$, we have that
\begin{align*}
f(x) &= (x-x^*)^mt^{(0)}(x), \\
f'(x) &= m(x-x^*)^{m-1}t^{(0)}(x) + (x-x^*)^mt^{(0)'}(x) \\
&\equiv (x-x^*)^{m-1} t^{(1)}(x), \\
f^{(m-1)}(x) &=  (x-x^*)t^{(m-1)}(x),
\end{align*}
where $t^{(i)} = (m-i+1)t^{(i-1)}(x) - (x-x^*)t^{(i-1)'}(x)$.
}

\item Increased multiplicity affects conditioning and convergence:

\lgcond{
\begin{itemize}
\item When a root $x^*$ not \coloremph{simple}, i.e. $m>1$, then $f'(x^*)=0$, so the problem of finding that root is ill-posed as $1/|f'(x^*)| = \infty$.
\sitem In practice, this means we have multiple roots at the same $x^*$ which are impossible to distinguish and may need to reformulate problem/algorithms.
\end{itemize}
}

\end{itemize}

\end{frame}
\section{Algorithms for Single-Variate Problems}

\subsection{Bisection}

\begin{frame}{Bisection Algorithm}

\urcornerlinkdemo{05-nonlinear-equations}{Bisection Method}

\begin{itemize}
\item Assume we know the desired root exists in a bracket $[a,b]$ and $\mathop{sign}(f(a))\neq\mathop{sign}(f(b))$:

\lgcond{
\begin{itemize}
\item if $f$ is continuous, by the intermediate value theorem, the bracket contains a root
\sitem can proceed to narrow interval to find a root
\sitem one caveat is that multiple roots may exist in $[a,b]$
\sitem another caveat is that we've imposed a restrictive condition, it can be difficult to find two points where the function has opposite sign
\end{itemize}
}

\item Bisection subdivides the interval by a factor of two at each step by considering $f(c_k)$ at $c_k=(a_k+b_k)/2$:

\lgcond{
\[[a_{k+1},b_{k+1}] = \begin{cases} [c_k,b_k] & : \mathop{sign}(f(a_k))=\mathop{sign}(f(c_k))   \\  [a_k, c_k] & : \mathop{sign}(f(b_k))=\mathop{sign}(f(c_k)) \end{cases}\]
}

\end{itemize}

\end{frame}

\subsection{Convergence Rates}

\begin{frame}{Rates of Convergence}

\urcornerlinkdemo{05-nonlinear-equations}{Rates of Convergence}

\begin{itemize}
\item Let $\B{x}_k$ be the $k$th iterate and $\B{e}_k=\B{x}_k=\B{x}^*$ be the error, bisection obtains \coloremph{linear convergence}, $\lim_{k\to \infty} ||\B{e}_k||/||\B{e}_{k-1}||\leq C$ where $C<1$:

\lgcond{
In bisection, working with the natural error bound given by bracket size,
\[e_k = b_k-a_k = \frac{1}{2}(b_{k-1}-a_{k-1}) = \frac{1}{2}e_{k-1},\]
so bisection achieves linear convergence with $C=1/2$.
With linear convergence, error $e_k\leq \epsilon$ is achieved after $O(\log_C(1/\epsilon))$ steps.
}

\item $r$th order convergence implies that $||\B{e}_k||/||\B{e}_{k-1}||^r\leq C$

\lgcond{
\begin{itemize}
\item Convergence of order $r>1$ (\coloremph{superlinear}) implies that the number of digits of correctness increases by a factor of $r$ at each step.
\sitem For $r>1$, error $e_k\leq \epsilon$ is achieved after $O(\log_r(\log(1/\epsilon)))$ steps.
\sitem Having achieved superlinear convergence ($r>1$), methods differ only by constant factors in complexity.
\end{itemize}
}

\end{itemize}

\end{frame}

\begin{frame}{Convergence of Fixed Point Iteration}

\begin{itemize}
\item Fixed point iteration: $x_{k+1}=g(x_k)$ is locally linearly convergent if for
      $x^* =g(x^*)$, we have $|g'(x^*)|< 1$:

\lgcond{
Note that,
\[e_{k+1} = x_{k+1}-x^* = g(x_k) - g(x^*). \]
By taking the Taylor expansion of $g$ at $x^*$ to represent $g(x_k)$, we can observe
\begin{align*}
e_{k+1}&= g'(x^*)(x_k-x^*)+O((x_k-x^*)^2)  \\
        &= g'(x^*)e_k+O((x_k-x^*)^2) ,
%&= g'(\theta_k)e_k, \quad \theta_k\in[x_k,x^*]
\end{align*}
where the asymptotic term decreases as $x_k$ approaches $x^*$.
}

\item It is quadratically convergent if $g'(x^*)=0$:

\lgcond{
Taking the same Taylor expansion, the leading term is now zero and we obtain
%Taylor's theorem allows us to show quadratic convergence,
\begin{align*}
e_{k+1}&= g''(x^*)(x_k-x^*)^2/2+O((x_k-x^*)^3) \\
&= g''(x^*)e_k^2/2+O((x_k-x^*)^3) .
%e_{k+1} &= x_{k+1}-x^* = g(x_k) - g(x^*) \\
%&= g''(\zeta_k)(x_k-x^*)^2/2 \\
%&= g''(\zeta_k)|e_k|^2/2, \quad \zeta_k\in[x_k,x^*]
\end{align*}
%where the asymptotic term decreases as $x_k$ approaches $x^*$.
}

\end{itemize}

\end{frame}

\subsection{Newton's Algorithm}

\begin{frame}{Newton's Method}

\dblurcornerlinkdemo{05-nonlinear-equations}{Newton's Method}{05-nonlinear-equations}{Convergence of Newton's Method}

\begin{itemize}
\item Newton's method is derived from a \coloremph{Taylor series} expansion of $f$ at $x_k$:

\lgcond{
\[f(x) = \underbrace{f(x_k) + f'(x_k)(x-x_k)}_{\text{secant line approximation} } + (1/2!)f''(x_k)(x-x_k)^2 + \cdots\]
}

\item Newton's method is \coloremph{quadratically convergent} if started sufficiently close to $x^*$ so long as $f'(x^*)\neq 0$:

\lgcond{
\begin{itemize}
\item Newton's method corresponds to the fixed point function $g(x)=x-f(x)/f'(x)$.
\mitem It achieves quadratic convergence since $g'(x^*)=0$,
\[g'(x^*)= 1-\underbrace{f'(x^*)/f'(x^*)}_{1} + \underbrace{f(x^*)}_{0}f''(x^*)/f'(x^*)^2.\]
%\[f(x^{*})-f(x_{k+1}) \leq (1/2)f''(x_k)(x-x_k)^2 + \cdots = (1/2)f''(\xi_k)||e_k||^2, \quad \xi_k\in[x_k,x^*]\]
\end{itemize}
}

\end{itemize}

\end{frame}

\subsection{Quasi-Newton Algorithms}

\begin{frame}{Secant Method}

\dblurcornerlinkdemo{05-nonlinear-equations}{Secant Method}{05-nonlinear-equations}{Convergence of the Secant Method}

\begin{itemize}
\item The \coloremph{Secant method} approximates $f'(x_k) \approx \frac{f(x_k)-f(x_{k-1})}{x_k-x_{k-1}}$:

\lgcond{
\begin{itemize}
\item Usually, this method is the cheapest approximation possible, since function values $f(x_k)$ and $f(x_{k-1})$ are already available.
\sitem Approximation quality depends on magnitude $f(x_k)-f(x_{k-1})$ and $x_k-x_{k-1}$.
\sitem If the two points are far apart, the derivative approximation may be bad locally, while if they are very close we have to take care in handling cancellation.
\sitem A well-chosen finite-difference step at each $x_k$ provides a more robust approximation, but requires another function evaluation.
\end{itemize}

}

\item The convergence of the Secant method is \coloremph{superlinear} but not quadratic:

\lgcond{
\begin{itemize}
\item The error will now depend on the previous two errors, since we are using the previous two points.
\sitem In simplified form, the error at the $k$th iteration satisfies \(e_k\leq e_{k-1}e_{k-2}.\)
\sitem Note that $\log(e_k)=\log(e_{k-1})+\log(e_{k-2})$ is the Fibonacci sequence, which grows at a rate of $r=(1+\sqrt{5})/2$.
\sitem Thus the (negative) exponent of the error increases by roughly a factor of $r$ at each step, i.e. the convergence rate is $r$.
\end{itemize}
}

\end{itemize}

\end{frame}

\begin{frame}{Nonlinear Tangential Interpolants}

\begin{itemize}
\item Secant method uses a linear interpolant based on points $f(x_k)$, $f(x_{k-1})$, could use more points and higher-order interpolant:

\mdcond{
Have points $(x_0,f(x_0)),\ldots,(x_{k},f(x_k))$ can fit polynomial to $p(x_i)=f(x_i)$ for some subset of points $x_i\in S\subseteq \{x_0,\ldots x_k\}$.
}

\item Quadratic interpolation (Muller's method) achieves convergence rate $r\approx 1.84$:

\mdcond{
Quadratic interpolation requires three points $x_{k-2}$, $x_{k-1}$, and $x_{k}$.
}

\item Inverse quadratic interpolation resolves the problem of nonexistence/nonuniqueness of roots of polynomial interpolants:

\lgcond{
\begin{itemize}
\item Interpolate quadratic polynomial $q$ so that $q(f(x_i))=x_i$ for $i\in\{k,k-1,k-2\}$.
\sitem Approximate root simply computed by evaluating interpolant at zero $x_{k+1}=q(0)$.
\end{itemize}
}

\end{itemize}

\end{frame}
\section{Global Convergence}

\begin{frame}{Achieving Global Convergence}

\begin{itemize}
\item Hybrid bisection/Newton methods:

\lgcond{
Given a bracket (interval), can proceed with bisection until bracket is small then switch to Newton.
Alternatively, can attempt Newton, check if it stays within bracket (\coloremph{safeguard}) and proceed with change only if it does.
}

\item Bounded (damped) step-size:

\lgcond{
Newton's method gives us a direction. Decreasing the step size in that direction trades off convergence rate for reliability.
We will study how step sizes can be chosen in more detail in the context of optimization.
}

\end{itemize}

\end{frame}

%\begin{frame}{Multivariate Fixed-Point and Newton Iteration}
%
%\begin{itemize}
%\item Fixed-point iteration achieves local convergence so long as $|\lambda_\text{max}(\B{J}_{\B{g}}(\B x^*))|< 1$:
%
%\lgcond{}
%
%\item Newton's method corresponds to the fixed-point iteration $\B g(\B x) = \B x - \B J^{-1}_{\B f}(\B x) \B f(\B x)$
%
%\lgcond{}
%
%\end{itemize}
%
%\end{frame}
%
%\begin{frame}{Cost of Multivariate Newton Iteration}
%
%\begin{itemize}
%\item What is the cost of computing $\B J_{\B f}(\B x)$?
%
%\lgcond{}
%
%\item What is the cost of solving $\B J_{\B f}(\B x)\B x_k = \B f (\B{x})$?
%
%\lgcond{}
%
%\end{itemize}
%
%\end{frame}
%
%
%\begin{frame}{Secant Updating Methods}
%
%\begin{itemize}
%\item Rather than compute $\B J_{\B f}(\B x_k)$ for each $\B{x}_k$, find $\B{B}_{k+1} = \B B_{k}+\B u \B v^T$ so tas to solve or approximate secant equation
%\[\B{B}_{k+1}(\B{x}_{k+1}-\B{x}_k)=\B{f}(\B{x}_{k+1}-\B{x}_{k})\]
%
%\lgcond{}
%
%\item What is the cost of solving $\B J_{\B f}(\B x)\B x_k = \B f (\B{x})$?
%
%\lgcond{}
%
%\end{itemize}
%
%\end{frame}
%
%\begin{frame}{Global Convergence in the Multivariate Case}
%
%\begin{itemize}
%\item Hybrid methods and step-size dampening:
%
%\lgcond{}
%
%\item Methods based on trust regions:
%
%\lgcond{}
%
%\end{itemize}
%
%\end{frame}
%
%
%
%
%
%
%
%
%
%

%

\section{Systems of Nonlinear Equations}

\subsection{Jacobian}

\begin{frame}{Systems of Nonlinear Equations}

\begin{itemize}
\item
Given $\B f(\B x) = \begin{bmatrix} f_1(\B x) & \cdots & f_m(\B x) \end{bmatrix}^T$ for $\B x \in \mathbb{R}^n$, seek $\B x^*$ so that $\B f(\B x^*)=\B 0$

\lgcond{
\begin{itemize}
\item $\B{x}^*$ must simultaneously set to zero all components of $\B f$: $f_1(\B x^*)=\cdots = f_m(\B x^*)=0$.
\sitem We focus on the case of $m=n$, so that the number of equations matches the number of unknowns.
\end{itemize}
}

\item
At a particular point $\B x$, the  \coloremph{Jacobian} of $\B f$, describes how $\B f$ changes in a given direction of change in $\B x$,
\[ \B J_{\B{f}} (\B{x}) = \begin{bmatrix}
     \frac{df_1}{dx_1}(\B{x}) & \cdots & \frac{df_1}{dx_n}(\B{x})\\
     \vdots &  & \vdots \\
     \frac{df_m}{dx_1}(\B{x}) & \cdots & \frac{df_m}{dx_n}(\B{x})
   \end{bmatrix}   \]

\lgcond{
Our local linear approximation is given by
\[\B f(\B x + \B{\delta x})\approx \B f(\B x) + \B J_{\B{f}} (\B{x})\B{\delta x},\]
note that when $m=1$ the Jacobian corresponds to the gradient of $\B f$.
}

\end{itemize}

\end{frame}

\subsection{Newton's Algorithm}

\urcornerlinkdemo{05-nonlinear-equations}{Newton's method in n dimensions}

\begin{frame}{Multivariate Newton Iteration}

\begin{itemize}
\item Fixed-point iteration $\B{x}_{k+1}=\B{g}(\B{x}_k)$ achieves local convergence so long as $|\lambda_\text{max}(\B{J}_{\B{g}}(\B x^*))|< 1$ and quadratic convergence if $\B J_{\B g} = \B O$:

\lgcond{
%Given starting point $\B{x}_0$ close enough to $\B{x}^\star$, we will have $|\lambda_\text{max}(\B{J}_{\B{g}}(\B x_k))|<1$.
Taking a multivariate Taylor expansion of $\B g(\B x_k)$ at center $\B x^{*}$ we get
\begin{align*}
\B e_k &= \B x^* - \B x_{k+1} \\
       &= \B g(\B x^*) - \B g(\B x_k) \\
       &= \underbrace{\B J_{\B g}(\B x^{*})}_{\B O} (\B x^* - \B x_{k})  \\
&\ + \frac{1}{2}\begin{bmatrix} \B H_{\B g}^{(1)}(\B x^*)\cdot  (\B x^* - \B x_{k}) & \cdots & \B H_{\B g}^{(n)}(\B x^*)\cdot (\B x^* - \B x_{k})\end{bmatrix}(\B x^* - \B x_{k})\\
||\B e_{k+1}|| &= O(\max_i||\B H_{\B g}^{(i)}(\B x^*)||\cdot ||\underbrace{\B x^*- \B x_{k}}_{\B e_{k}}||^2) \\
       &= O( ||\B e_k||^2)
%\B g(\B x^*) &= \B x^* - \B J^{-1}_{\B f}(\B x^*) \B f(\B x^*) \\
%\B{J_g}(\B x^*) &= \B I - \B J^{-1}_{\B f}(\B x^*)  \B J_{\B f}(\B x^*) - \sum_{i} \underbrace{f_i(\B x^*)}_{0}\B H_{\B f}^{(i)}(\B x^*) \\
\end{align*}
where $\B{H_g}^{(i)}$ is the $i$th component of the derivative of $\B J_{\B g}(\B x^*)$.
}
\lgcond{}

\end{itemize}

\end{frame}
%
%\begin{frame}{Convergence of Newton Iteration}
%
%\begin{itemize}
%\item Newton's method achieves quadratic local convergence if $||\B J_{\B f}^{-1}(\B x)||$ is bounded near $\B x^*$:
%
%\lgcond{
%\begin{align*}
%\B e_k & = \B x_{k} - \B x^* = \B g(\B x_{k-1}) - \B x^* \\
%       &= \B x_{k-1} - \B J_{\B{f}}^{-1} (\B{x}_{k-1}) \B f(\B x_{k-1}) - \B x^* \\
%       &= \B J_{\B{f}}^{-1} (\B{x}_{k-1}) (\B f(\B x_{k-1}) -\B J_{\B{f}}(\B{x}_{k-1})(\B x^* -\B x_{k-1}))   \\
%||\B e_k|| &\leq ||\B J_{\B{f}}^{-1} (\B{x}_{k-1})|| (||\B f(\B x_{k-1})|| + ||\B J_{\B{f}}(\B{x}_{k-1})||\cdot ||\B x^* -\B x_{k-1}||)   \\
%       &= ||\B J_{\B{f}}^{-1} (\B{x}_{k-1}) ||O(||\B x^* -\B x_{k-1}||^2)   \\
%       &= ||\B J_{\B{f}}^{-1} (\B{x}_{k-1}) ||O(||\B e_{k-1}||^2)
%\end{align*}
%}
%\lgcond{}
%
%\end{itemize}
%
%\end{frame}

\begin{frame}{Multidimensional Newton's Method}

\begin{itemize}

\item Newton's method corresponds to the fixed-point iteration
\[\B g(\B x) = \B x - \B J^{-1}_{\B f}(\B x) \B f(\B x)\]

\lgcond{
\begin{itemize}
\item Note that generally Newton's method iteration has a fixed-point $\B{\bar{x}}$ whenever $\B f(\B{\bar{x}})=\B 0$, i.e. we have found a root of $\B f$, namely $\B{x}^*=\B{\bar{x}}$.

\sitem Generally, we require that $\B J_{\B f}(\B x^*)$ is nonsingular, otherwise we can find nonzero solutions $\B y$ to  $\B J_{\B f}(\B x^*)\B y = \B f(\B x^*)=\B 0$.

%\sitem When $m\neq n$ or $\B J_{\B f}(\B x^*)$ is singular, can instead use pseudoinverse or perform regularization.
\end{itemize}
}

\item Quadratic convergence is achieved when the Jacobian of a fixed-point iteration is zero at the solution, which is true for Newton's method:
\lgcond{
\begin{align*}
\B g(\B x^*) &= \B x^* - \B J^{-1}_{\B f}(\B x^*) \B f(\B x^*) \\
\B{J_g}(\B x^*) &= \B I - \B J^{-1}_{\B f}(\B x^*)  \B J_{\B f}(\B x^*) - \sum_{i} \underbrace{f_i(\B x^*)}_{0}\B H_{\B f}^{(i)}(\B x^*) \\
&= \B I - \B I - \B O = \B O
\end{align*}
where $\B{H_f}^{(i)}$ is the $i$th component of the derivative of $\B J^{-1}_{\B f}(\B x^*)$.
}
\end{itemize}

\end{frame}

\subsection{Quasi-Newton Algorithms}

\begin{frame}{Estimating the Jacobian using Finite Differences}

\begin{itemize}
\item To obtain $\B J_{\B f}(\B x_k)$ at iteration $k$, can use finite differences:

\lgcond{
\begin{itemize}
\item If $\B J_{\B f}(x)\in\mathbb{R}^{m\times 1}$ (single-variate but vector-valued $\B f$), we can estimate
\[\B J_{\B f}(x_k) \approx (1/h)(\B f(x_k+h)- \B f(x_k)).\]

\item
More generally, the $i$th column of $\B{j}_i$ of the Jacobian $\B J_{\B f}(\B x_k)$ can be estimated by
\[\B{j}_i\approx (1/h)(\B f(\B x_k+h \B e_i )- \B f(\B x_k)).\]
\end{itemize}
}

\item $n+1$ function evaluations are needed: $\B f(\B x)$ and $\B f(\B x+h\B e_i), \forall i\in\{1,\ldots,n\}$, which correspond to $m(n+1)$ scalar function evaluations if $\B J_{\B f}(\B x_k)\in\mathbb{R}^{m\times n}$.
\lgcond{}

\end{itemize}

\end{frame}

\begin{frame}{Cost of Multivariate Newton Iteration}

\begin{itemize}

\item What is the cost of solving $\B J_{\B f}(\B x_k)\B s_{k} = \B f (\B{x}_k)$?

\lgcond{$O(n^3)$}

\item What is the cost of Newton's iteration overall?

\lgcond{For $k$ steps, $O(n^3k+kn^2\gamma_\text{func-eval})$.}
\end{itemize}

\end{frame}

\begin{frame}{Quasi-Newton Methods}

\urcornerlinkinclass{inclass-broyden}{Broyden's Method}

In solving a nonlinear equation, seek approximate Jacobian $\B J_{\B f}(\B x_k)$ for each $\B{x}_k$
\begin{itemize}
\item Find $\B{B}_{k+1} = \B B_{k}+\B{\delta B}_k \approx \B J_{\B f}(\B x_{k+1})$, so as to approximate \coloremph{secant equation}
\[\B{B}_{k+1}(\underbrace{\B{x}_{k+1}-\B{x}_k}_{\B{\delta x}})=\underbrace{\B{f}(\B{x}_{k+1})-\B f(\B{x}_{k})}_{\B{\delta f}}\]

\lgcond{
Generally, the secant equation is underdetermined, as we usually need $n$ finite-difference formulas to determine $\B J_{\B f}(\B x_k)$, so
the secant updating methods find only approximate $\B{B}_{k+1}$, usually as a modification of $\B{B}_{k}$.
}

\item \coloremph{Broyden's method} solves the secant equation and minimizes $||\B{\delta B}_{k}||_F$:
\[\B{\delta B}_{k} = \frac{\B{\delta f} - \B{B}_k\B{\delta x}}{||\B{\delta x}||^2}\B{\delta x}^T\]

\lgcond{
Note that $\B{\delta B}_{k}$ is rank-1.
Consequently, we can use the Sherman-Morrison formula to update $\B{B}^{-1}_{k+1}$ with $O(n^2)$ work.
Various other variants exist.
}

\end{itemize}

\end{frame}

\begin{frame}{Safeguarding Methods}

\begin{itemize}
\item Can dampen step-size to improve reliability of Newton or Broyden iteration:

\mdcond{
\[\B x_{k+1} = \B x_k + \alpha_k \B s_k \quad \text{where} \quad \alpha_k\leq 1\]
can pick $\alpha_k$ so to ensure $||\B f (\B x_{k+1})|| < ||\B f (\B x_{k})||$ or by doing a line-search to minimize $||\B f(\B x_k + \alpha_k \B s_k)||.$
}

\item \coloremph{Trust region methods} provide general step-size control:

\mdcond{
Establish/maintain/update region within which step is expected to be accurate.
Pick each step to stay within trust region while minimizing $||\B f (\B x_{k+1})||$.
Observe that the Newton-like generally seek to progress to a minima of $||\B f (\B x_{k+1})||$, and indeed much of the theory of these methods targets optimization.
}
\lgcond{}

\end{itemize}

\end{frame}

%\begin{frame}{Secant Updating Methods}
%
%\begin{itemize}
%\item Rather than compute $\B J_{\B f}(\B x_k)$ for each $\B{x}_k$, find $\B{B}_{k+1} = \B B_{k}+\B{\delta B}_k \approx \B J_{\B f}(\B x_{k+1})$, so as to solve or approximate secant equation
%\[\B{B}_{k+1}(\underbrace{\B{x}_{k+1}-\B{x}_k}_{\B{\delta x}})=\underbrace{\B{f}(\B{x}_{k+1})-\B f(\B{x}_{k})}_{\B{\delta f}}\]
%
%\lgcond{
%}
%
%\item Broyden's method is given by minimizing with minimal $||\B{\delta B}_{k}||_F$:
%\[\B{\delta B}_{k} = \frac{\B{\delta f} - \B{B}_k\B{\delta x}}{||\B{\delta x}||^2}\B{\delta x}^T\]
%
%\lgcond{
%}
%
%\end{itemize}
%
%\end{frame}
%
%\begin{frame}{Trust Region Methods}
%
%\begin{itemize}
%\item Can dampen step-size to improve reliability of Newton's iteration:
%
%\mdcond{}
%
%\item \coloremph{Trust region methods} provide general step-size control:
%
%\mdcond{}
%\lgcond{}
%
%\end{itemize}
%
%\end{frame}
%
%
%
%
%
%

%\end{document}\end{document}


\chapter{Introduction}
\pagenumbering{arabic}
\setcounter{page}{1}

This thesis describes a formalisation of the theory of infinitary term
rewriting in the \Coq proof assistant. The foundation of \Coq is a
constructive type theory with inductive types, whereas infinitary term
rewriting, building on the theory of finitary rewriting, uses notions
from topology, set theory, and analysis, but not necessarily in a
constructive way.

The central question we aim to answer in this thesis is whether the
traditional notions from infinitary term rewriting can be translated
to \Coq in such a way that the resulting definitions are natural for
the \Coq system. Of course, for such a translation to be satisfactory,
it should preserve the semantics of the original notions.

% functions must be total and terminating for coq to be consistent

In the remainder we may simply write `rewriting' instead of
`infinitary rewriting' and `term' instead of `infinite
term'.

Although this text contains a fair amount of \Coq code, it is not our
intention to completely list a development ready for compiling. Rather, the
included code fragments are thought to be the most interesting ones for the
purpose of discussion of our development. In fact, many of the code listings
are simplified and/or typographically enhanced to a form beyond of what the
\Coq compiler will accept. Furthermore, lemmas are stated without proof. The
reader is invited to study the full source code, with proofs, which is
available at \url{http://martijn.vermaat.name/master-project/}.

\section*{Infinitary Rewriting}

The theory of \emph{(finitary) rewriting} is concerned with the
repeated transformation of objects by discrete steps following a
predefined set of rules. Such a set of rules can be understood as
implementing a programming language if we take programs as the objects
to be transformed. Indeed, \emph{term rewriting} is the foundational
model of functional programming. Other examples of rewriting can be
found in the transformation of braids \citep{mellies-95} and the
$\lambda$-calculus. As a matter of fact, $\lambda$-calculus is of
prime importance, both as a model of computation and as a logical
framework.

%with applications as a model of computation or as logical framework.

\emph{Infinitary rewriting} generalises finitary rewriting by
considering infinitely large objects and series of transfinitely many
transformation steps. One could question the validity of this
generalisation, especially in the context of mechanical formalisation
with which this thesis is concerned. After all, the word `mechanical'
implies finite restrictions on the amounts of space and time we can
use.

However, mathematicians (and computer scientists for that matter) have
long had ample reason to include the infinite in their work. In
\emph{The Quadrature of the Parabola}, Archimedes considers the
infinite summation
\begin{align*}
  1 \,+\, \frac{1}{4} \,+\, \frac{1}{16} \,+\, \frac{1}{64} \,+\, \ldots
\end{align*}
in his proof that the area of a parabolic segment is \sfrac{4}{3} that
of a certain inscribed triangle. Of course we cannot carry out the
infinite computation to arrive at the outcome \sfrac{4}{3}, but we can
represent it in finite space and manipulate this representation in
finite time to deduce its outcome.

As another example to motivate the study of infinite objects, consider
the simple \Haskell program
\begin{singlespace}
\begin{coqdoccode}
\coqdocnoindent
\coqdocinductive{f} 0 \coqdocindent{0.2em} \textsf{where}
\coqdocindent{0.2em} \coqdocinductive{f} \coqdocvar{\textsf{n}} =
\coqdocvariable{\textsf{n}} : \coqdocinductive{f}
(\coqdocvar{\textsf{n}} + 1)\coqdoceol
\end{coqdoccode}
\end{singlespace}
that defines the infinite stream of natural numbers. We can inspect
the stream at any position, but by \Haskell's lazy evaluation the
stream is never fully computed. Again, the represented object takes an
infinite amount of space to store and an infinite amount of time to
compute, yet we can perfectly reason about it in finite space and
time.

The theory of infinitary term rewriting is formally introduced in
Chapter~\ref{chap:rewriting}. In that chapter, we define precisely
which infinite objects are allowed and what we understand by
transfinite sequences of rewrite steps.

\section*{Mechanical Formalisation}
\markright{\emph{Mechanical Formalisation}}

The translation of infinitary rewriting to \Coq is an example of the
mechanical formalisation of a mathematical theory. By `mechanical' we
mean that the formalisation must be in a form that can be manipulated
by a machine. Definitions on paper or ideas in one's head do not
qualify as mechanical formalisations. Furthermore, we want the
formalisation to represent the theory's semantics.

The promises of mechanical formalisations include:
\begin{compactdesc}
%  \item[\normalfont{\emph{Confidence}}\hskip .5em]
%  \item[{\makebox[6em][l]{\normalfont{\emph{Confidence}}}}]
  \item[\normalfont{\emph{Confidence}}\hskip .5em]
    Proof-checkers can verify the correctness of proofs in a rigorous
    way. If we trust the implementation of the checker (which is
    usually kept as small as possible) and its execution on a
    computer, we can be confident that a verified proof is correct,
    even if we do not fully comprehend it.
  \item[\normalfont{\emph{Automation}}\hskip .5em]
    Tedious work, whether computationally hard or just boring, is
    often better suited to computers. They are faster than humans and
    precise.
  \item[\normalfont{\emph{Intuition}}\hskip .5em]
    Proofs on paper typically abstract away from seemingly
    uninteresting  details. This is often a good thing, but sometimes
    the level of detail of a mechanical proof gives us that extra bit
    of insight to fully understand its workings. Another way of
    gaining intuition is by building tools on top of the
    formalisation, e.g.\ providing graphical representations of
    definitions.
  \item[\normalfont{\emph{Availability}}\hskip .5em]
    Formalised theories may be searched and browsed semantically using
    a computer instead of just syntactically. Furthermore, the
    internet provides us with excellent methods to share and copy
    these formalisations globally.
\end{compactdesc}

In 1976, the four colour theorem\footnote{`Four colours suffice to
  colour any map such that no two neighbouring countries have the same
  colour.' Posed by Francis Guthrie in 1852. } was proven
\citep{appel-haken-76}. The proof used a computer program to show that
a particular set of 1,936 maps satisfy a certain property by
exhaustive case analysis. This is an
example of automation by translation to a computer. The correctness of
the proof, however, remained debatable because this case analysis by
computer was impossible to perform or verify by hand.

Even though a simpler proof was published by \citet{robertson-97}, it
was not until \citet{gonthier-05} formally verified the entire proof,
including the computer program part, that all remaining doubts were
dispelled. This formalisation thus helped gain confidence in the
validity of the theorem.

Large-scale mechanical formalisation of mathematics goes back to the %late
1960's with de Bruijn's \Automath project
\citep{nederpelt-94}. A complete text book on analysis
\citep{landau-65} was formalised and verified for correctness, but the
system never gained widespread use.

Many formalisation efforts, using many different systems, have since
been undertaken. A list of formally verified proofs for 100
mathematical theorems is maintained by \citet{wiedijk-08}. Ongoing
work is the \Flyspeck project \citep{hales-09} with as goal a formal
proof of the Kepler conjecture,\footnote{`The most efficient packing
  of oranges is in a pyramid.' Posed by Johannes Kepler in 1611.}
expected to take up to 20 work-years to complete.

\section*{Outline}

In Chapter~\ref{chap:rewriting} we introduce ordinal numbers and the
theory of infinitary term rewriting. This is mostly a recapitulation
of \citet{terese-03}, included for self-containment, and can be seen
as preliminaries for the later chapters.

The purpose of Chapter~\ref{chap:implementation} is to present our
formalisation of infinitary term rewriting in the \Coq proof
assistant. We start with a short introduction to \Coq and then review
the main parts of our development.

Our formalisation was used to prove that in infinitary rewriting, weak
orthogonality does not imply uniqueness of normal forms. This
application is discussed in Chapter~\ref{chap:unwo}.

Finally, in Chapter~\ref{chap:discussion} we discuss our results and
draw conclusions.

We include a short introduction to \Coq in Appendix~\ref{chap:coq}.


% -------------------------------------------------------- %
% Filter Lock
% by: Isai Barajas Cicourel

% -------------------------------------------------------- %
% Document Start

\section{\textbf{Filter Lock}}

% -------------------------------------------------------- %
% Particular Caes

\subsection{Particular Case}
\par
In this experiment, the particular case we are trying to study is mutual exclusion where several threads try to use a shared resource.
\par
We are trying to do so using waiting rooms called levels that a thread must traverse before acquiring the lock.
\par

% -------------------------------------------------------- %
% Solution Information

\subsection{Solution}
\par
We now consider two mutual exclusion protocols that work for $n$ threads, where $n$ is greater than $2$. The Filter lock, is a direct generalization of the Peterson lock to multiple threads.
\par
The Filter lock, creates \(n - 1\) ``waiting rooms'', called levels, that a thread must traverse before acquiring the lock. The Peterson lock uses a two-element boolean flag array to indicate whether a thread is trying to enter the critical section. The Filter lock generalizes this notion with an $n$-element integer $level[]$ array, where the value of $level[A]$ indicates the highest level that thread $A$ is trying to enter.
\par

% -------------------------------------------------------- %
% Experiment

\subsection{Experiment Description}
\par
The test creates $8$ threads that need to be coordinate in order to increment a common counter. All threads have to cooperate to increase this counter from 0 to $1024$. Each of the threads will increase by one the counter $128$ times.
The expected result is that regardless of the order in which each thread executes the increment, at the end the counter must stay at $1024$.
If that is not the case, then it means that mutual exclusion did not work.
\par

% -------------------------------------------------------- %
% Results

\subsection{Observations and Interpretations}

\par
When executing the test on a dual core machine there was a a low chance of failure, but when executed on a Quad core and Six core machines the problems where more consistent.
\begin{lstlisting}[frame=single]
Testcase: testParallel(mutex.FilterTest):	FAILED
expected:<1023> but was:<1024>
\end{lstlisting}

% -------------------------------------------------------- %
% Results

\subsection{Proposed changes to fix the problem}

\par
Even do the victim and level arrays are \textit{volatile}, the atomicity is not guarantee and so to fix this I added the \textit{synchronized} reserved word to the \textit{sameOrHigher()} method in order to guarantee atomicity while checking the levels.
\begin{lstlisting}[frame=single,breaklines=true]
// Is there another thread at the same or higher level?
private synchronized boolean
  sameOrHigher(int me, int myLevel) {
  for (int id = 0; id < size; id++)
    if (id != me && level[id] >= myLevel) {
      return true;
    }
    return false;
}
\end{lstlisting}
Once the change is made the execution works fine on every equipment used.
\begin{lstlisting}[frame=single,breaklines=true]
Script Directory: .
Using OS: Linux
Linux Java 6 Runtime: ./jre/linux/bin
Will execute test from input: mutex.FilterTest
Classpath: .:./lib/*:./output/:./build/
Running JUnit using Linux
JUnit version 4.12
.
Time: 0.021

OK (1 test)
\end{lstlisting}

% -------------------------------------------------------- %
% Why?

\subsection{Proposed solution}
\par
Once the comparing of the level was made atomic, the spin made for conflicting threads was properly working and able to cooperate to increase the counter to 1024.
\par
One thing that is worth mentioning is that the \textit{volatile} keyword seems to either have an implementation problem or not documented restriction, since it is not helping guarantee the use of the waiting rooms causing additional increases in the counter, thus ending with a different number rather than the one expected.


\chapter{Equations and Analysis}
\section{Introduction}
\subsection{Topics}
\begin{enumerate}
  \item Mass relationships
  \item Limiting and excess reagents
  \item Percent yield
  \item Chemical analysis
  \item Concentration and solution stoichiometry
  \item Spetctrophotometry
  \item Oxidation-reduction reactions
\end{enumerate}

\section{Stoichiometry}
Stoichiometry involves the use of a balanced chemical equations to determine
the relationship between similar properties of two seperate substances in an
equation. Properties that can be measured using this technique include mass,
volume, moles, pressure, and concentration.

\subsection{Problem Solving}
To solve a problem using stoichometry, implement the following technique:
\begin{enumerate}
  \item Write a balanced equation
  \item Convert the given information into moles
  \item Use the mole ratio to convert between different substances
  \item Take the mole amount of the unknown and convert into a different unit
\end{enumerate}

An example of this technique in action follows below:

First, a chemical equation is written.\\
\ce{CH4 + 2O2 -> CO2 + 2H2O}\\

We are trying to find the amount of \ce{CO2} produced from \SI{50}{\gram} of
\ce{CH4}.

$$\left(\frac{\SI{50}{\gram} \ce{CH4}}{1}\right)\left(\frac{\SI{1}{\mol}
\ce{CH4}}{\SI{16.04}{\gram}}\right)\left(\frac{\SI{1}{\mol} \ce{CO2}}{\SI{1}{\mol}
\ce{CH4}}\right)\left(\frac{\SI{44.01}{\gram} \ce{CO2}}{\SI{1}{\mol}
\ce{CO2}}\right) = \SI{137}{\gram} \ce{CO2}$$

\section{Limiting Reactants}
Sometimes, an excess of one reactant is present as compared to a limiting
amount of another reactant. For example, if you a grilling hot-dogs and there
are 10 dogs per package, but only 8 buns per package, the buns are the limiting
"reagent."

To solves these types of problems, do the stoichometry both ways and see which
can produce less of the same product. Whichever reactant you started with is the
limiting reagent.

An example is shown below:\\

\textit{\SI{100.}{\gram \ce{Xe}} reacts with \SI{100.}{\gram \ce{F2}} to produce
\ce{XeF6}}\\

\ce{Xe + 3F2 -> XeF6}\\

Starting with \SI{100.}{\gram \ce{Xe}}:
$$\left(\SI{100.}{\gram \ce{Xe}}\right)\left(\frac{\SI{1}{\mol
\ce{Xe}}}{\SI{131.29}{\gram \ce{Xe}}}\right)\left(\frac{\SI{1}{\mol
\ce{XeF6}}}{\SI{1}{\mol \ce{Xe}}}\right)\left(\frac{\SI{245.28}{\gram
\ce{XeF6}}}{\SI{1}{\mol \ce{XeF6}}}\right) = \SI{187}{\gram \ce{XeF6}}$$

Starting with \SI{100.}{\gram \ce{F2}}:
$$\left(\SI{100.}{\gram \ce{F2}}\right)\left(\frac{\SI{1}{\mol
\ce{F2}}}{\SI{38.00}{\gram \ce{F2}}}\right)\left(\frac{\SI{1}{\mol
\ce{XeF6}}}{\SI{3}{\mol \ce{F2}}}\right)\left(\frac{\SI{245.28}{\gram
\ce{XeF6}}}{\SI{1}{\mol \ce{XeF6}}}\right) = \SI{215}{\gram \ce{XeF6}}$$

We can determine that \SI{100.}{\gram \ce{Xe}} is the limiting reagent since it
produces less \ce{XeF6}.

\section{Chemical Analysis}
\subsection{Identifying impurities}

Most impurity problems deal with finding the amount of some substance present in
a solution when we know information about how that solution reacts with yet
another substances. From this, we can obtain two equations, and do stoichometry
between the two in order to determine how much of the original substance is
present in the solution.

An example problem follows:\\

\textit{a \SI{275}{\gram} of impure water is treated with dilute \ce{H2CO3}
  solution to test for the presence of calcium chloride. After filtration,
\SI{0.0034}{\gram \ce{CaCO3}} is collected. Determine the mass percentage of
\ce{CaCl2} in the water sample, assuming all of the calcium present is in the
form of \ce{CaCl2}.}\\

\ce{Ca^2+ + CO3^2- -> CaCO3}\\
\ce{CaCl2 -> Ca^2+ + 2Cl-}\\

Stoichometry is done to convert between \ce{CaCO3} and the mass amount of
\ce{CaCl2}. A mass percent is then obtained using the formula from the previous
chapter.

\subsection{Identifying hydrocarbons}
A hydrocarbon comes in the form \ce{C_xH_y} or \ce{C_xH_yO_z}. Hydrocarbons can
be easily identified using the above processes when undergoing combustion. The
problem-solving technique is outlined below:

\begin{enumerate}
  \item Determine the hydrocarbon.
  \item Combust it, and write a balanced chemical equation (\ce{CO2} and
    \ce{H2O} are always produced).
  \item Use the amount of \ce{CO2} to determine how much \ce{C} the hydrocarbon
    contained.
  \item Use the amount of \ce{H2O} produced to determine how much \ce{H} is
.    contained in the hydrocarbon.
  \item Use the mass of the hydrocarbon subtracting away the mass of the \ce{C}
    and \ce{H} to determine the mass of \ce{O} left over.
\end{enumerate}

An example is shown below:

\textit{ex. \SI{14.75}{\gram} of a hydrocarbon with the formula \ce{C_xH_yO_z}
  is combusted. After combustion, \SI{24.1981}{\gram} \ce{CO2} and \SI{9.9055}{\gram} \ce
{H2O} remain. Determine the emperical formula of the hydrocarbon.}

Carbon analysis: \ce{CO2 -> C + 2O}

$$(\SI{24.1981}{\gram \ce{CO2}})\left(\frac{\SI{1}{\mol
\ce{CO2}}}{\SI{44.04}{\gram \ce{CO2}}}\right)\left(\frac{\SI{1}{\mol
\ce{C}}}{\SI{1}{\mol \ce{CO2}}}\right) = \SI{.550}{\mol \ce{C}}$$

Hydrogen analysis: \ce{H2O -> 2H + O}

$$(\SI{9.9055}{\gram \ce{H2O}})\left(\frac{\SI{1}{\mol
\ce{H2O}}}{\SI{18.01}{\gram \ce{H2O}}}\right)\left(\frac{\SI{2}{\mol
\ce{H}}}{\SI{1}{\mol \ce{H2O}}}\right) = \SI{1.10}{\mol \ce{H}}$$

Oxygen analysis:

$$\SI{14.75}{\gram} - (\SI{6.60}{\gram \ce{C}} + \SI{1.11}{\gram \ce{H}}) =
\SI{7.04}{\gram \ce{O}}$$

Then use the tactic outlined in the previous chapter to determine the emperical
formula by simplifying the molar ratio obtained above.

Following these steps, the unknown hydrocarbon is: \ce{C5H10O4}.

\section{Percent Yield}
\begin{equation}
  \text{percent yield} = \frac{\text{actual yield}}{\text{theoretical
  yield}}(100)
\end{equation}

\begin{description}
  \item[Theoretical yield] the amount of product obtained by stoichometric
    ratios.
  \item[Actual yield] the amount of product collected from an experiment.
\end{description}

This is not the same as percent error.


\documentclass[hyperref={colorlinks=true},xcolor=svgnames]{beamer}
\usepackage{pgfpages}
\usepackage{listings}
\usepackage{amsmath}
\setbeamercolor{normal text}{bg=BlanchedAlmond}

\mode<presentation>
{
  \usetheme{Pittsburgh}
  \useoutertheme[right]{sidebar}
  % or ...

  \setbeamercovered{transparent}
  % or whatever (possibly just delete it)
}

\usepackage[english]{babel}
\usepackage{listings}

\usepackage[latin1]{inputenc}

\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\def \lecturenumber {1}
\input{pagenumbering.tex}

\title{Topic 1: Introduction, Vectors}

\AtBeginSubsection[]
{
  \begin{frame}<beamer>
    \frametitle{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
 }

\usepackage{amssymb}
\usepackage{amsmath}

\input{lecture_commands}

\setcounter{topic}{1}

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\section{Preamble}
\begin{frame}
\frametitle{Downloads}
\begin{itemize}
\item
All details for this course can be found on Moodle

\item
\url{http://moodle.rhul.ac.uk/}

\item
I will attempt to create a slidecast of each lecture that will be placed on moodle as well.
\end{itemize}

\end{frame}

\begin{frame}{Who am I ?}
\begin{itemize}
\item
Hugh Shanahan (but you can call me Hugh).

\item
My office is in the Bedford Building.

\item
Here are my office hours - please come by the admin office and ask them to give me a call.

\item Monday 15-16

\item Tuesday 15-16

\item
If you want some guaranteed time with me to answer question etc.,
please email me to arrange an appointment.
% My email address is
%{\tt Hugh.Shanahan@rhul.ac.uk}.
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Assignments}
\begin{itemize}
\item
Three quizzes - each worth 10\% of the final grade.

\item
Each quiz will be 30 minutes in length so it can be done in an hour slot.

\item A practice quiz will be set up this week.

\item
Deadlines are available on

%\url{https://www.royalholloway.ac.uk/computerscience/informationforcurrentstudents/home.aspx}

\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Exam}

\begin{itemize}
%\item
%This is a new course and there will be an example exam script before the end of the course.
%
%\pause

\item
Answer all questions !
\end{itemize}

\end{frame}

\begin{frame}
\frametitle{Labs}

\begin{itemize}
\item Labs will run on a weekly basis.

%\item Two hours once a fortnight.

\item Thursday 10-12, Bedford 0-04 to 0-0.06, PC01.

\item Class will be divided into two; each one taking one hour.

\item No lab this week.

\item We'll be using Python and NumPy for this course.

\item More specifically we will be using Jupyter notebooks and Binder.
%\item First exercise - have a read of your First Year Games notes!!!

\end{itemize}

\end{frame}
\section{Motivation}
\begin{frame}
\frametitle{Motivation}

\begin{itemize}
\item This course will focus on one, very regular class of data structures.

\pause

\item Namely, vectors and matrices with almost invariably floating point entries.

\item Linear Algebra is the branch of Mathematics to deal with this.

\pause

\item Why bother??

\end{itemize}

\end{frame}

\begin{frame}
\frametitle{Linear Algebra}

\begin{itemize}
\item Linear Algebra is a vast branch of Mathematics with hugely powerful tools for us to use.

\item Linear Algebra has a number of direct applications in Computer Science and every Computer Scientist should understand it. For example
\pause
\begin{itemize}
\item Computer Graphics
\item Computer Vision
\item Machine Learning and Artificial Intelligence
\item Graph Theory
\end{itemize}
\end{itemize}

\end{frame}

\begin{frame}
\frametitle{Mathematics}
\begin{itemize}
\item This course is shamelessly Mathematical BUT

\pause

\item I assume no prior knowledge of Linear Algebra.

\item It is very much grounded in concrete examples from CS.
\end{itemize}

\end{frame}
\section{Definitions and Background Mathematics}

\begin{frame}
\frametitle{Definitions}

\begin{table}[htdp]

\begin{center}
\begin{tabular}{|c|c|c|}
\hline
Type & Symbol & Examples \\ \hline
Natural numbers & $\mathbb{N}$ & $0$,$1$,$2$,$\dots$ \\
Integers & $\mathbb{Z}$ & $\dots$,$-2$,$-1$,$0$,$1$,$2$,$\dots$ \\
Reals & $\mathbb{R}$ & $-\pi$,$0$, $e$, $100.03$ \\
Complex numbers & $\mathbb{C}$ &$3.0 + 4.95 i$ \\ \hline
\end{tabular}
\end{center}
\caption{Symbols used in this course.}
\label{Symbols}
\end{table}%

\end{frame}

\begin{frame}
\frametitle{Notation}

\begin{table}[htdp]

\begin{center}
\begin{tabular}{|c|c|}
\hline
Symbol & Meaning  \\ \hline
$\equiv$ & Defines \\
$\implies$ & This Implies \\
iff & If and Only if \\ \hline
\end{tabular}
\end{center}
\caption{Notation used in this course.}
\label{Notation}
\end{table}%

\end{frame}

\begin{frame}
\frametitle{Trigonometry}

%Quick reminder

\begin{center}
\includegraphics[height=3cm]{../Figures/Topic1_preamble.png}
\end{center}

\begin{eqnarray}
\cos{\theta} = \frac{a}{h} \;\; &, &
\sin{\theta} = \frac{o}{h} \;\; , \\
\cos{(-\theta)} = \cos \theta \;\; &,&
\sin{(-\theta)} = -\sin \theta \;\; \\
\cos^2{\theta} + \sin^2{\theta} &=& 1 \;\; , \\
\sin{(a+b)} &=& \sin{a} \cos{b} + \cos{a}\sin{b} \;\; , \\
\cos{(a+b)} &=& \cos{a} \cos{b} - \sin{a} \sin{b} \;\; .
\end{eqnarray}

\end{frame}

\section{The number line}

\begin{frame}
\frametitle{The number line}

First steps in understanding numbers ($\mathbb{Z}$).

\vskip1cm
\includegraphics[height=0.75cm]{../Figures/2000px-Number-line.png}

\end{frame}

\begin{frame}
\frametitle{The reals}

Can add in reals easily in this picture $\dots$ ($\mathbb{R}$).

\vskip1cm
\includegraphics[height=2cm]{../Figures/Real_Number_line.png}

\end{frame}

\begin{frame}
\frametitle{Direction}

Can think of an arrow  from the origin to each  number on the number line.
\vskip1cm
\includegraphics[height=1.5cm]{../Figures/1dvector.png}

Arrow is length 4.5 going in a positive direction.

\end{frame}

\begin{frame}
\frametitle{Direction}

\vskip1cm
\includegraphics[height=1.5cm]{../Figures/1dvectorExample2.png}

Other arrow is length 1.66 going in a negative direction.

\end{frame}

\begin{frame}
\frametitle{Operations - scaling}

Can scale the length of an arrow.

\vskip1cm
\includegraphics[height=1.5cm]{../Figures/1dvectorScaled.png}

Arrow of length 4.5 is scaled by a factor 1.5.

\end{frame}

\begin{frame}
\frametitle{Operations - addition}

Can add arrows - just put "tail to head".

\vskip1cm
\includegraphics[height=1.5cm]{../Figures/1dvectorAddition.png}

Arrow of length 4.5 going in positive direction plus arrow of length 2.5 going in a negative direction results in an arrow of length 2.0 going in a
positive direction.

\end{frame}

\begin{frame}
\frametitle{Operations - product}

Multiplying the signs tells us if the arrows are going in the same or opposite direction.

\end{frame}

\section{Two dimensions}

\begin{frame}
\frametitle{Adding another number line}

Move into 2 dimensions.

\vskip1cm
\begin{center}
\includegraphics[height=6cm]{../Figures/2DGrid.png}
\end{center}

\end{frame}

\begin{frame}
\frametitle{Moving up a dimension}
\begin{itemize}
\item Instead of a position on the number line. You now have {\bf coordinates},
represented by a pair of numbers $(a,b)$.
\pause
\item For the most part we will assume that these numbers are reals $a \in \mathbb{R}$,
$b \in \mathbb{R}$.
\pause
\item Formally, these are elements of the Cartesian product $\mathbb{R} \times \mathbb{R}$
(go and check your CS1860 notes).
\pause
\item But we could have grids which are  $\mathbb{N} \times \mathbb{N}$,
$\mathbb{Z} \times \mathbb{Z}$, $\mathbb{C} \times \mathbb{C}$
and so on.
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{A coordinate}

\vskip1cm
\begin{center}
\includegraphics[height=6cm]{../Figures/2DGrid_plus_coordinate.png}
\end{center}

\end{frame}

\begin{frame}
\frametitle{Vectors}
\begin{itemize}
\item Just as in the 1-d example, we can draw arrows from the origin to points on this grid.
\pause
\item We don't call these arrows, we call them {\bf vectors}.
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Vectors}

\vskip1cm
\begin{center}
\includegraphics[height=6cm]{../Figures/2DGrid_plus_vector.png}
\end{center}

\end{frame}

\begin{frame}
\frametitle{Notation}
For reasons that will become clear we describe them as columns rather than rows.
\pause
\begin{equation}
\vd{1.1}{2.5}, \vd{-3.7}{0.34}
\end{equation}

\pause
As variables we use the following notation
\begin{equation}
\v{v} = \vd{-4.67}{0.76}
\end{equation}

\end{frame}

\begin{frame}
\frametitle{Notation contd.}

In textbooks you will also see the following alternatives ....
\[
\mathbf{v}\;\; , \;\; \vec{v}
\]
they all mean the same thing - a vector !

\pause
If we want a vector in row form then there is an explicit operation to get that.

\begin{equation}
\v{v}^\intercal = \vdt{-4.67}{0.76}
\end{equation}

\end{frame}

\survey{https://moodle.royalholloway.ac.uk/mod/quiz/view.php?id=462536}

\end{document}


\documentclass[12pt]{article}
\begin{document}
\thispagestyle{empty}

\section*{NYU General Physics 1---Estimation problems}

\paragraph{Problem 1:}

Previously this semester, you have computed the power expended by your
car traveling at $55~\mathrm{mi\,h^{-1}}$ by (a) considering fuel
consumption, and, indirectly, by (b) estimating air drag on the moving
car.  Reconcile your estimates; \textit{i.e.,} figure out how they are
related and check that the relation is satisfied, at least to order of
magnitude.

\paragraph{Problem 2:}

How many piano tuners are there in the City of New York?  Estimate
it, and then check your answer with the phone book or WWW.

\paragraph{Problem 3:}

You are stuck in Kansas and you see an airplane flying overhead
between LA and NY.  Estimate the angular speed (radians per second) at
which the plane passes across your field of view.

\paragraph{Problem 4:}

Estimate the mass of a fully loaded commercial airliner, before
take-off.  Don't forget the fuel.  Estimate the minimum total thrust
(in Newtons) of the engines if they can make the plane ascend at an
angle of 20~deg to the horizontal.

\paragraph{Problem 5:}

An airplane has to bank to turn.  What is the radius of curvature of
the trajecrory of a commercial airliner at cruising speed banked at
35~deg?

\paragraph{Problem 6:}

When a bird lands on a power line, it sends a transverse wave down the
line.  Estimate the speed of the wave.  Use things you know about
power lines to estimate the linear mass density of the line and the
tension (remember a problem set you did?).

\paragraph{Problem 7:}

What is the approximate moment of inertia $I$ of a figure skater
spinning with her hands outstretched.  If her period of rotation is
1.5~s, what is her total kinetic energy of rotation?

\paragraph{Problem 8:}

When your car is rolling down the street, what fraction of its kinetic
energy is in the form of translation of the total mass, and what
fraction is in the form of rotation of the wheels?

\paragraph{Problem 9:}

Compare the force of air resistance to the force of gravity acting on
a baseball that has been hit hard enough to fly 300~m if there were no
air resistance.  For the ``formula'', recall a worksheet you did?  Is
the assumption of no air resistance a good assumption or bad one?

\paragraph{Problem 10:}

You walk at a pace that is set, in part, by the natural frequency of
oscillation of your leg, treated as a pendulum.  Estimate this
frequency first by treating your leg as a massless rod with a mass on
the end, and then, more realistically, as a massive rod, pivoted at
one end.  Does your answer seem reasonable?

\paragraph{Problem 11:}

What is the most valuable ingredient of Thanksgiving dinner, in terms
of dollars per kg?  What is its value in dollars per kg?

\paragraph{Problem 12:}

What is the total mass of the students in this class?

\paragraph{Problem 13:}

What is the kinetic energy $K$ of a typical car going at freeway
speeds?  What is the typical power output $P$ of a typical car engine?
What are the dimensions of the ratio $K/P$, and what does that ratio
``mean''?

\paragraph{Problem 14:}

What is the typical thermal speed of a molecule in the air?  Recall
that $k\,T$ is roughly its kinetic energy.  What else do you have to
assume?  Compare your answer to the sound speed.

\paragraph{Problem 15:}

When you boil water it expands in volume by a factor of (very roughly)
1000.  How much work does it take to expand 1 gram of water by this
factor, assuming the expansion happens at atmospheric pressure?  How
does your answer compare to the latent heat of vaporization?  Do you
think these two energies ought to be related in any way?

\end{document}