summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJovina2011-06-08 10:38:50 +0530
committerJovina2011-06-08 10:38:50 +0530
commit1991e1981563e59bce37205114c7b5c67f544333 (patch)
treeb892236a29deffaf09c815d21511330985b65e01
parentb81d258b3bea2eef876d007e7dcff5f8b6ad1751 (diff)
downloadst-scripts-1991e1981563e59bce37205114c7b5c67f544333.tar.gz
st-scripts-1991e1981563e59bce37205114c7b5c67f544333.tar.bz2
st-scripts-1991e1981563e59bce37205114c7b5c67f544333.zip
Major changes to script & slides of least_square_fit.
-rw-r--r--least_square_fit/script.rst104
-rw-r--r--least_square_fit/slides.org70
-rw-r--r--least_square_fit/slides.tex110
3 files changed, 212 insertions, 72 deletions
diff --git a/least_square_fit/script.rst b/least_square_fit/script.rst
index e0cfe2b..4aa5630 100644
--- a/least_square_fit/script.rst
+++ b/least_square_fit/script.rst
@@ -17,40 +17,46 @@
Checklist OK? : <put date stamp here, not OK> [2010-10-05]
-.. #[Puneeth: Add pre-requisites.]
-
Script
------
-Hello friends and welcome to the tutorial on Least Square Fit
+{{{ Show the first slide containing title, name of the production
+team along with the logo of MHRD }}}
+
+Hello friends and welcome to the tutorial on 'Least Square Fit'.
+
+{{{ Show the slide containing objectives }}}
-{{{ Show the slide containing title }}}
+At the end of this tutorial, you will be able to,
-{{{ Show the slide containing the outline slide }}}
+ 1. Generate the least square fit line for a
+ given set of points.
-In this tutorial, we shall look at generating the least square fit line for a
-given set of points.
+{{{ Switch to the pre-requisite slide }}}
-First let us have a look at the problem.
+Before beginning this tutorial,we would suggest you to complete the
+tutorial on "Using plot interactively", "Loading data from files"
+and "Getting started with arrays".
-{{{ Show the slide containing problem statement. }}}
+Let us start this tutorial with the help of an example.
+
+{{{ Show the slide containing exercise 1 }}}
We have an input file generated from a simple pendulum experiment.
+{{{ Open the file 'pendulum.txt' and show }}}
+
It contains two columns of data. The first column is the length of the
pendulum and the second is the corresponding time period of the pendulum.
As we know, the square of time period of a pendulum is directly proportional to
its length, we shall plot l vs t^2 and verify this.
-.. #[Puneeth:] removed the explanation about loadtxt and unpack
-.. option. It's been done in another LO already. simple dependency
-.. should work?
-
To read the input file and parse the data, we are going to use the
-loadtxt function. Type
+loadtxt function.Switch to the terminal.
::
-
+
+ ipython -pylab
l, t = loadtxt("/home/fossee/pendulum.txt", unpack=True)
l
t
@@ -58,7 +64,7 @@ loadtxt function. Type
We can see that l and t are two sequences containing length and time values
correspondingly.
-Let us first plot l vs t^2. Type
+Let us first plot l vs t^2.
::
tsq = t * t
@@ -66,22 +72,20 @@ Let us first plot l vs t^2. Type
{{{ switch to the plot window }}}
-.. #[Puneeth:] Moved explanation of least square fit here. seems more
-.. apt.
-
We can see that there is a visible linear trend, but we do not get a
straight line connecting them. We shall, therefore, generate a least
square fit line.
-{{{ show the slide containing explanation on least square fit }}}
-
-As shown in the slide, we are first going to generate the two matrices
-tsq and A. Then we are going to use the ``lstsq`` function to find the
+We will first generate the two matrices tsq and A.
+Then we will use the ``lstsq`` function to find the
values of m and c.
+{{{ Switch to the terminal }}}
+
let us now generate the A matrix with l values.
We shall first generate a 2 x 90 matrix with the first row as l values and the
second row as ones. Then take the transpose of it. Type
+
::
inter_mat = array((l, ones_like(l)))
@@ -114,35 +118,47 @@ Now that we have m and c, we need to generate the fitted values of t^2. Type
plot(l, tsq, 'bo')
plot(l, tsq_fit, 'r')
-We get the least square fit of l vs t^2
+We get the least square fit of l vs t^2.
-{{{ Pause here and try out the following exercises }}}
+{{{ Show summary slide }}}
-%% 2 %% change the label on y-axis to "y" and save the lines of code
- accordingly
+This brings us to the end of the tutorial.In this tutorial,
+we have learnt to,
-{{{ continue from paused state }}}
+ 1. Generate a least square fit using matrices.
+ #. Use the function ``lstsq()`` to generate a least square fit line.
-{{{ Show summary slide }}}
+{{{Show self assessment questions slide}}}
+
+Here are some self assessment questions for you to solve
+
+1. What does ones_like([1, 2, 3]) produce
-This brings us to the end of the tutorial.
-we have learnt
+ - array([1, 1, 1])
+ - [1, 1, 1]
+ - [1.0, 1.0, 1.0]
+ - Error
+
+2. The plot of ``u`` vs ``v`` is a bunch of scattered points that show a
+ linear trend. How do you find the least square fit line of ``u`` vs ``v``.
- * how to generate a least square fit
-{{{ Show the "sponsored by FOSSEE" slide }}}
+{{{solution of self assessment questions on slide}}}
-.. #[Nishanth]: Will add this line after all of us fix on one.
-.. This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+And the answers,
+
+1. The function ``ones_like([1, 2, 3])`` will generate 'array([1, 1, 1])'.
+
+2. The following set of commands will produce the least square fit line of ``u`` vs ``v``
+::
+
+ A = array(u, ones_like(u)).T
+ result = lstsq(A, v)
+ m, c = result[0]
+ lst_line = m * u + c
-Hope you have enjoyed and found it useful.
-Thank you
+{{{ Show the thank you slide }}}
+Hope you have enjoyed this tutorial and found it useful.
+Thank you!
-..
- Local Variables:
- mode: rst
- indent-tabs-mode: nil
- sentence-end-double-space: nil
- fill-column: 75
- End:
diff --git a/least_square_fit/slides.org b/least_square_fit/slides.org
index d32f5c6..ccb7d7f 100644
--- a/least_square_fit/slides.org
+++ b/least_square_fit/slides.org
@@ -18,7 +18,7 @@
#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries}
-#+TITLE: Least square fit
+#+TITLE:
#+AUTHOR: FOSSEE
#+EMAIL:
#+DATE:
@@ -29,22 +29,70 @@
#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
-* Outline
- - Plotting a Least square fit line
+*
+#+begin_latex
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Least Square Fit}
+\end{center}
+\vspace{18pt}
+\begin{center}
+\vspace{10pt}
+\includegraphics[scale=0.95]{../images/fossee-logo.png}\\
+\vspace{5pt}
+\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\
+\scriptsize Funded by National Mission on Education through ICT\\
+\scriptsize MHRD,Govt. of India\\
+\includegraphics[scale=0.30]{../images/iitb-logo.png}\\
+\end{center}
+#+end_latex
+* Objectives
+ At the end of this tutorial, you will be able to,
+
+ - Generate the least square fit line for a
+ given set of points.
+* Pre-requisite
+ Spoken tutorial on -
+ - Using plot interactively.
+ - Loading data from files.
+ - Getting started with arrays.
+* Exercise 1
+ - Generate a least square fit line for l v/s t^2 using the data in the file
+ 'pendulum.txt'.
* Summary
- You should now be able to --
- - Plot a least square fit line.
-* Thank you!
+ In this tutorial,we have learnt to,
+
+ - Generate a least square fit using matrices.
+ - Use the function ``lstsq()`` to generate a least square fit line.
+* Evaluation
+ 1. What does ones_like([1, 2, 3]) produce
+
+ - array([1, 1, 1])
+ - [1, 1, 1]
+ - [1.0, 1.0, 1.0]
+ - Error
+
+ 2. The plot of ``u`` vs ``v`` is a bunch of scattered points that show a
+ linear trend. How do you find the least square fit line of ``u`` v/s ``v``.
+
+* Solutions
+ 1. array([1, 1, 1])
+
+ 2. A = array(u, ones\_like(u)).T
+ result = lstsq(A, v)
+ m, c = result[ 0 ]
+ lst\_line = m * u + c
+*
#+begin_latex
\begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
#+end_latex
diff --git a/least_square_fit/slides.tex b/least_square_fit/slides.tex
index 5f07014..86a68e9 100644
--- a/least_square_fit/slides.tex
+++ b/least_square_fit/slides.tex
@@ -1,4 +1,4 @@
-% Created 2010-10-10 Sun 19:02
+% Created 2011-06-08 Wed 10:17
\documentclass[presentation]{beamer}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
@@ -23,14 +23,14 @@ commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\providecommand{\alert}[1]{\textbf{#1}}
-\title{Least square fit}
+\title{}
\author{FOSSEE}
\date{}
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
\begin{document}
-\maketitle
+
@@ -41,37 +41,113 @@ showstringspaces=false, keywordstyle=\color{blue}\bfseries}
\begin{frame}
-\frametitle{Outline}
-\label{sec-1}
+
+\begin{center}
+\vspace{12pt}
+\textcolor{blue}{\huge Least Square Fit}
+\end{center}
+\vspace{18pt}
+\begin{center}
+\vspace{10pt}
+\includegraphics[scale=0.95]{../images/fossee-logo.png}\\
+\vspace{5pt}
+\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\
+\scriptsize Funded by National Mission on Education through ICT\\
+\scriptsize MHRD,Govt. of India\\
+\includegraphics[scale=0.30]{../images/iitb-logo.png}\\
+\end{center}
+\end{frame}
+\begin{frame}
+\frametitle{Objectives}
+\label{sec-2}
+
+ At the end of this tutorial, you will be able to,
+
\begin{itemize}
-\item Plotting a Least square fit line
+\item Generate the least square fit line for a
+ given set of points.
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Pre-requisite}
+\label{sec-3}
+
+ Spoken tutorial on -
+
+\begin{itemize}
+\item Using plot interactively.
+\item Loading data from files.
+\item Getting started with arrays.
+\end{itemize}
+\end{frame}
+\begin{frame}
+\frametitle{Exercise 1}
+\label{sec-4}
+
+
+\begin{itemize}
+\item Generate a least square fit line for l v/s t$^2$ using the data in the file
+ `pendulum.txt'.
\end{itemize}
\end{frame}
\begin{frame}
\frametitle{Summary}
-\label{sec-2}
+\label{sec-5}
+
+ In this tutorial,we have learnt to,
+
- You should now be able to --
\begin{itemize}
-\item Plot a least square fit line.
+\item Generate a least square fit using matrices.
+\item Use the function ``lstsq()'' to generate a least square fit line.
\end{itemize}
\end{frame}
\begin{frame}
-\frametitle{Thank you!}
-\label{sec-3}
+\frametitle{Evaluation}
+\label{sec-6}
+
+
+\begin{enumerate}
+\item What does ones$\_{\mathrm{like}}$([1, 2, 3]) produce
+\begin{itemize}
+\item array([1, 1, 1])
+\item ~[1, 1, 1]~
+\item ~[1.0, 1.0, 1.0]~
+\item Error
+\end{itemize}
+\vspace{10pt}
+\item The plot of ``u'' vs ``v'' is a bunch of scattered points that show a
+ linear trend. How do you find the least square fit line of ``u'' v/s ``v''.
+\end{enumerate}
+\end{frame}
+\begin{frame}
+\frametitle{Solutions}
+\label{sec-7}
+
+
+\begin{enumerate}
+\item array([1, 1, 1])
+\vspace{15pt}
+\item A = array(u, ones\_like(u)).T\\
+ result = lstsq(A, v)\\
+ m, c = result[ 0 ]\\
+ lst\_line = m * u + c
+\end{enumerate}
+\end{frame}
+\begin{frame}
\begin{block}{}
\begin{center}
- This spoken tutorial has been produced by the
- \textcolor{blue}{FOSSEE} team, which is funded by the
+ \textcolor{blue}{\Large THANK YOU!}
\end{center}
+ \end{block}
+\begin{block}{}
\begin{center}
- \textcolor{blue}{National Mission on Education through \\
- Information \& Communication Technology \\
- MHRD, Govt. of India}.
+ For more Information, visit our website\\
+ \url{http://fossee.in/}
\end{center}
\end{block}
\end{frame}
-\end{document}
+\end{document} \ No newline at end of file