From 31e5331f054cc4168c8c676ce04bddd113f9a563 Mon Sep 17 00:00:00 2001
From: Puneeth Chaganti
Date: Wed, 4 Nov 2009 22:08:13 +0530
Subject: Moved least square fitting to session 4; removed vander function.

---
 day1/session4.tex | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

(limited to 'day1/session4.tex')

diff --git a/day1/session4.tex b/day1/session4.tex
index 7981771..c126cbf 100644
--- a/day1/session4.tex
+++ b/day1/session4.tex
@@ -306,6 +306,102 @@ Out[]:
 \inctime{15}
 \end{frame}
 
+\section{Least Squares Fit}
+\begin{frame}[fragile]
+\frametitle{Least Squares Fit}
+\vspace{-0.15in}
+\begin{figure}
+\includegraphics[width=4in]{data/L-Tsq-Line.png}
+\end{figure}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Least Squares Fit}
+\vspace{-0.15in}
+\begin{figure}
+\includegraphics[width=4in]{data/L-Tsq-points.png}
+\end{figure}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Least Squares Fit}
+\vspace{-0.15in}
+\begin{figure}
+\includegraphics[width=4in]{data/least-sq-fit.png}
+\end{figure}
+\end{frame}
+
+\begin{frame}
+\frametitle{Least Square Fit Curve}
+\begin{itemize}
+\item $T^2$ and $L$ have a linear relationship
+\item Hence, Least Square Fit Curve is a line
+\item we shall use the \typ{lstsq} function
+\end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{\typ{lstsq}}
+\begin{itemize}
+\item We need to fit a line through points for the equation $T^2 = m \cdot L+c$
+\item The equation can be re-written as $T^2 = A \cdot p$
+\item where A is   
+  $\begin{bmatrix}
+  L_1 & 1 \\
+  L_2 & 1 \\
+  \vdots & \vdots\\
+  L_N & 1 \\
+  \end{bmatrix}$
+  and p is 
+  $\begin{bmatrix}
+  m\\
+  c\\
+  \end{bmatrix}$
+\item We need to find $p$ to plot the line
+\end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Generating $A$}
+\begin{lstlisting}
+In []: A = array([L, ones_like(L)])
+In []: A = A.T
+\end{lstlisting}
+%% \begin{itemize}
+%% \item A is also called a Van der Monde matrix
+%% \item It can also be generated using \typ{vander}
+%% \end{itemize}
+%% \begin{lstlisting}
+%% In []: A = vander(L, 2)
+%% \end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{\typ{lstsq} \ldots}
+\begin{itemize}
+\item Now use the \typ{lstsq} function
+\item Along with a lot of things, it returns the least squares solution
+\end{itemize}
+\begin{lstlisting}
+In []: coef, res, r, s = lstsq(A,TSq)
+\end{lstlisting}
+\end{frame}
+
+\subsection{Plotting}
+\begin{frame}[fragile]
+\frametitle{Least Square Fit Line \ldots}
+We get the points of the line from \typ{coef}
+\begin{lstlisting}
+In []: Tline = coef[0]*L + coef[1]
+\end{lstlisting}
+\begin{itemize}
+\item Now plot Tline vs. L, to get the Least squares fit line. 
+\end{itemize}
+\begin{lstlisting}
+In []: plot(L, Tline)
+\end{lstlisting}
+\end{frame}
+
 \section{Solving linear equations}
 
 \begin{frame}[fragile]
@@ -476,6 +572,7 @@ Use \kwrd{solve()}
       \item Norms
       \item Singular Value Decomposition
     \end{itemize}
+  \item Least Square Curve fitting
   \item Solving linear equations
   \end{itemize}
 \end{frame}
-- 
cgit 

