302 [-0. , 0.89442719, -0.4472136 ], |
302 [-0. , 0.89442719, -0.4472136 ], |
303 [-0.74535599, 0.2981424 , 0.59628479]])) |
303 [-0.74535599, 0.2981424 , 0.59628479]])) |
304 \end{lstlisting} |
304 \end{lstlisting} |
305 \end{small} |
305 \end{small} |
306 \inctime{15} |
306 \inctime{15} |
|
307 \end{frame} |
|
308 |
|
309 \section{Least Squares Fit} |
|
310 \begin{frame}[fragile] |
|
311 \frametitle{Least Squares Fit} |
|
312 \vspace{-0.15in} |
|
313 \begin{figure} |
|
314 \includegraphics[width=4in]{data/L-Tsq-Line.png} |
|
315 \end{figure} |
|
316 \end{frame} |
|
317 |
|
318 \begin{frame}[fragile] |
|
319 \frametitle{Least Squares Fit} |
|
320 \vspace{-0.15in} |
|
321 \begin{figure} |
|
322 \includegraphics[width=4in]{data/L-Tsq-points.png} |
|
323 \end{figure} |
|
324 \end{frame} |
|
325 |
|
326 \begin{frame}[fragile] |
|
327 \frametitle{Least Squares Fit} |
|
328 \vspace{-0.15in} |
|
329 \begin{figure} |
|
330 \includegraphics[width=4in]{data/least-sq-fit.png} |
|
331 \end{figure} |
|
332 \end{frame} |
|
333 |
|
334 \begin{frame} |
|
335 \frametitle{Least Square Fit Curve} |
|
336 \begin{itemize} |
|
337 \item $T^2$ and $L$ have a linear relationship |
|
338 \item Hence, Least Square Fit Curve is a line |
|
339 \item we shall use the \typ{lstsq} function |
|
340 \end{itemize} |
|
341 \end{frame} |
|
342 |
|
343 \begin{frame}[fragile] |
|
344 \frametitle{\typ{lstsq}} |
|
345 \begin{itemize} |
|
346 \item We need to fit a line through points for the equation $T^2 = m \cdot L+c$ |
|
347 \item The equation can be re-written as $T^2 = A \cdot p$ |
|
348 \item where A is |
|
349 $\begin{bmatrix} |
|
350 L_1 & 1 \\ |
|
351 L_2 & 1 \\ |
|
352 \vdots & \vdots\\ |
|
353 L_N & 1 \\ |
|
354 \end{bmatrix}$ |
|
355 and p is |
|
356 $\begin{bmatrix} |
|
357 m\\ |
|
358 c\\ |
|
359 \end{bmatrix}$ |
|
360 \item We need to find $p$ to plot the line |
|
361 \end{itemize} |
|
362 \end{frame} |
|
363 |
|
364 \begin{frame}[fragile] |
|
365 \frametitle{Generating $A$} |
|
366 \begin{lstlisting} |
|
367 In []: A = array([L, ones_like(L)]) |
|
368 In []: A = A.T |
|
369 \end{lstlisting} |
|
370 %% \begin{itemize} |
|
371 %% \item A is also called a Van der Monde matrix |
|
372 %% \item It can also be generated using \typ{vander} |
|
373 %% \end{itemize} |
|
374 %% \begin{lstlisting} |
|
375 %% In []: A = vander(L, 2) |
|
376 %% \end{lstlisting} |
|
377 \end{frame} |
|
378 |
|
379 \begin{frame}[fragile] |
|
380 \frametitle{\typ{lstsq} \ldots} |
|
381 \begin{itemize} |
|
382 \item Now use the \typ{lstsq} function |
|
383 \item Along with a lot of things, it returns the least squares solution |
|
384 \end{itemize} |
|
385 \begin{lstlisting} |
|
386 In []: coef, res, r, s = lstsq(A,TSq) |
|
387 \end{lstlisting} |
|
388 \end{frame} |
|
389 |
|
390 \subsection{Plotting} |
|
391 \begin{frame}[fragile] |
|
392 \frametitle{Least Square Fit Line \ldots} |
|
393 We get the points of the line from \typ{coef} |
|
394 \begin{lstlisting} |
|
395 In []: Tline = coef[0]*L + coef[1] |
|
396 \end{lstlisting} |
|
397 \begin{itemize} |
|
398 \item Now plot Tline vs. L, to get the Least squares fit line. |
|
399 \end{itemize} |
|
400 \begin{lstlisting} |
|
401 In []: plot(L, Tline) |
|
402 \end{lstlisting} |
307 \end{frame} |
403 \end{frame} |
308 |
404 |
309 \section{Solving linear equations} |
405 \section{Solving linear equations} |
310 |
406 |
311 \begin{frame}[fragile] |
407 \begin{frame}[fragile] |