day1/session3.tex
changeset 268 f978ddc90960
parent 263 8a4a1e5aec85
child 281 ce818f645f6b
equal deleted inserted replaced
267:978d06520462 268:f978ddc90960
   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 %%making vander without vander, simple matrix
       
   585 \subsection{Van der Monde matrix generation}
       
   586 \begin{frame}[fragile]
       
   587 \frametitle{Van der Monde Matrix}
       
   588 \begin{itemize}
       
   589 \item A is also called a Van der Monde matrix
       
   590 \item It can be generated using \typ{vander}
       
   591 \end{itemize}
       
   592 \begin{lstlisting}
       
   593 In []: A = vander(L, 2)
       
   594 \end{lstlisting}
       
   595 Gives the required Van der Monde matrix
       
   596 \begin{equation*}
       
   597   \begin{bmatrix}
       
   598     l_1 & 1 \\
       
   599     l_2 & 1 \\
       
   600     \vdots & \vdots\\
       
   601     l_N & 1 \\
       
   602   \end{bmatrix}
       
   603 \end{equation*}
       
   604 
       
   605 \end{frame}
       
   606 
       
   607 \begin{frame}[fragile]
       
   608 \frametitle{\typ{lstsq} \ldots}
       
   609 \begin{itemize}
       
   610 \item Now use the \typ{lstsq} function
       
   611 \item Along with a lot of things, it returns the least squares solution
       
   612 \end{itemize}
       
   613 \begin{lstlisting}
       
   614 In []: coef, res, r, s = lstsq(A,TSq)
       
   615 \end{lstlisting}
       
   616 \end{frame}
       
   617 
       
   618 \subsection{Plotting}
       
   619 \begin{frame}[fragile]
       
   620 \frametitle{Least Square Fit Line \ldots}
       
   621 We get the points of the line from \typ{coef}
       
   622 \begin{lstlisting}
       
   623 In []: Tline = coef[0]*L + coef[1]
       
   624 \end{lstlisting}
       
   625 \begin{itemize}
       
   626 \item Now plot Tline vs. L, to get the Least squares fit line. 
       
   627 \end{itemize}
       
   628 \begin{lstlisting}
       
   629 In []: plot(L, Tline)
       
   630 \end{lstlisting}
       
   631 \end{frame}
       
   632 
       
   633 \begin{frame}[fragile]
       
   634   \frametitle{What did we learn?}
       
   635   \begin{itemize}
       
   636    \item Least square fit
       
   637    \item Van der Monde matrix generation
       
   638    \item Plotting the least square fit curve
       
   639   \end{itemize}
       
   640 \end{frame}
       
   641 
       
   642 \end{document}
   530 \end{document}