day1/session3.tex
changeset 276 4555c3814dd4
parent 268 f978ddc90960
child 281 ce818f645f6b
equal deleted inserted replaced
275:71e50184d482 276:4555c3814dd4
   525 In []: T = array(T)
   525 In []: T = array(T)
   526 In []: TSq = T*T
   526 In []: TSq = T*T
   527 \end{lstlisting}
   527 \end{lstlisting}
   528 \end{frame}
   528 \end{frame}
   529 
   529 
   530 \begin{frame}[fragile]
       
   531 \frametitle{Least Squares Fit}
       
   532 \vspace{-0.15in}
       
   533 \begin{figure}
       
   534 \includegraphics[width=4in]{data/L-Tsq-Line.png}
       
   535 \end{figure}
       
   536 \end{frame}
       
   537 
       
   538 \begin{frame}[fragile]
       
   539 \frametitle{Least Squares Fit}
       
   540 \vspace{-0.15in}
       
   541 \begin{figure}
       
   542 \includegraphics[width=4in]{data/L-Tsq-points.png}
       
   543 \end{figure}
       
   544 \end{frame}
       
   545 
       
   546 \begin{frame}[fragile]
       
   547 \frametitle{Least Squares Fit}
       
   548 \vspace{-0.15in}
       
   549 \begin{figure}
       
   550 \includegraphics[width=4in]{data/least-sq-fit.png}
       
   551 \end{figure}
       
   552 \end{frame}
       
   553 
       
   554 \begin{frame}
       
   555 \frametitle{Least Square Fit Curve}
       
   556 \begin{itemize}
       
   557 \item $T^2$ and $L$ have a linear relationship
       
   558 \item Hence, Least Square Fit Curve is a line
       
   559 \item we shall use the \typ{lstsq} function
       
   560 \end{itemize}
       
   561 \end{frame}
       
   562 
       
   563 \begin{frame}[fragile]
       
   564 \frametitle{\typ{lstsq}}
       
   565 \begin{itemize}
       
   566 \item We need to fit a line through points for the equation $T^2 = m \cdot L+c$
       
   567 \item The equation can be re-written as $T^2 = A \cdot p$
       
   568 \item where A is   
       
   569   $\begin{bmatrix}
       
   570   L_1 & 1 \\
       
   571   L_2 & 1 \\
       
   572   \vdots & \vdots\\
       
   573   L_N & 1 \\
       
   574   \end{bmatrix}$
       
   575   and p is 
       
   576   $\begin{bmatrix}
       
   577   m\\
       
   578   c\\
       
   579   \end{bmatrix}$
       
   580 \item We need to find $p$ to plot the line
       
   581 \end{itemize}
       
   582 \end{frame}
       
   583 
       
   584 \subsection{Van der Monde matrix generation}
       
   585 \begin{frame}[fragile]
       
   586 \frametitle{Van der Monde Matrix}
       
   587 \begin{itemize}
       
   588 \item A is also called a Van der Monde matrix
       
   589 \item It can be generated using \typ{vander}
       
   590 \end{itemize}
       
   591 \begin{lstlisting}
       
   592 In []: A = vander(L, 2)
       
   593 \end{lstlisting}
       
   594 Gives the required Van der Monde matrix
       
   595 \begin{equation*}
       
   596   \begin{bmatrix}
       
   597     l_1 & 1 \\
       
   598     l_2 & 1 \\
       
   599     \vdots & \vdots\\
       
   600     l_N & 1 \\
       
   601   \end{bmatrix}
       
   602 \end{equation*}
       
   603 
       
   604 \end{frame}
       
   605 
       
   606 \begin{frame}[fragile]
       
   607 \frametitle{\typ{lstsq} \ldots}
       
   608 \begin{itemize}
       
   609 \item Now use the \typ{lstsq} function
       
   610 \item Along with a lot of things, it returns the least squares solution
       
   611 \end{itemize}
       
   612 \begin{lstlisting}
       
   613 In []: coef, res, r, s = lstsq(A,TSq)
       
   614 \end{lstlisting}
       
   615 \end{frame}
       
   616 
       
   617 \subsection{Plotting}
       
   618 \begin{frame}[fragile]
       
   619 \frametitle{Least Square Fit Line \ldots}
       
   620 We get the points of the line from \typ{coef}
       
   621 \begin{lstlisting}
       
   622 In []: Tline = coef[0]*L + coef[1]
       
   623 \end{lstlisting}
       
   624 \begin{itemize}
       
   625 \item Now plot Tline vs. L, to get the Least squares fit line. 
       
   626 \end{itemize}
       
   627 \begin{lstlisting}
       
   628 In []: plot(L, Tline)
       
   629 \end{lstlisting}
       
   630 \end{frame}
       
   631 
       
   632 \begin{frame}[fragile]
       
   633   \frametitle{What did we learn?}
       
   634   \begin{itemize}
       
   635    \item Least square fit
       
   636    \item Van der Monde matrix generation
       
   637    \item Plotting the least square fit curve
       
   638   \end{itemize}
       
   639 \end{frame}
       
   640 
       
   641 \end{document}
   530 \end{document}