71 % postbreak = \space\dots |
71 % postbreak = \space\dots |
72 % } |
72 % } |
73 |
73 |
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
75 % Title page |
75 % Title page |
76 \title[Solving Equations \& ODEs]{Python for Science and Engg:\\Solving Equations \& ODEs} |
76 \title[Solving Equations \& ODEs]{Python for Science and Engg:\\SciPy} |
77 |
77 |
78 \author[FOSSEE] {FOSSEE} |
78 \author[FOSSEE] {FOSSEE} |
79 |
79 |
80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
81 \date[] {SciPy 2010, Introductory tutorials\\Day 1, Session 6} |
81 \date[] {SciPy 2010, Tutorials} |
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
83 |
83 |
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
85 %\logo{\pgfuseimage{iitmlogo}} |
85 %\logo{\pgfuseimage{iitmlogo}} |
86 |
86 |
120 %% \begin{frame} |
120 %% \begin{frame} |
121 %% \frametitle{Outline} |
121 %% \frametitle{Outline} |
122 %% \tableofcontents |
122 %% \tableofcontents |
123 %% % You might wish to add the option [pausesections] |
123 %% % You might wish to add the option [pausesections] |
124 %% \end{frame} |
124 %% \end{frame} |
|
125 |
|
126 \section{Least Squares Fit} |
|
127 \begin{frame}[fragile] |
|
128 \frametitle{$L$ vs. $T^2$ - Scatter} |
|
129 Linear trend visible. |
|
130 \vspace{-0.1in} |
|
131 \begin{figure} |
|
132 \includegraphics[width=4in]{data/L-Tsq-points} |
|
133 \end{figure} |
|
134 \end{frame} |
|
135 |
|
136 \begin{frame}[fragile] |
|
137 \frametitle{$L$ vs. $T^2$ - Line} |
|
138 This line does not make any mathematical sense. |
|
139 \vspace{-0.1in} |
|
140 \begin{figure} |
|
141 \includegraphics[width=4in]{data/L-Tsq-Line} |
|
142 \end{figure} |
|
143 \end{frame} |
|
144 |
|
145 \begin{frame}[fragile] |
|
146 \frametitle{$L$ vs. $T^2$ - Least Square Fit} |
|
147 This is what our intention is. |
|
148 \vspace{-0.1in} |
|
149 \begin{figure} |
|
150 \includegraphics[width=4in]{data/least-sq-fit} |
|
151 \end{figure} |
|
152 \end{frame} |
|
153 |
|
154 \begin{frame}[fragile] |
|
155 \frametitle{Matrix Formulation} |
|
156 \begin{itemize} |
|
157 \item We need to fit a line through points for the equation $T^2 = m \cdot L+c$ |
|
158 \item In matrix form, the equation can be represented as $T_{sq} = A \cdot p$, where $T_{sq}$ is |
|
159 $\begin{bmatrix} |
|
160 T^2_1 \\ |
|
161 T^2_2 \\ |
|
162 \vdots\\ |
|
163 T^2_N \\ |
|
164 \end{bmatrix}$ |
|
165 , A is |
|
166 $\begin{bmatrix} |
|
167 L_1 & 1 \\ |
|
168 L_2 & 1 \\ |
|
169 \vdots & \vdots\\ |
|
170 L_N & 1 \\ |
|
171 \end{bmatrix}$ |
|
172 and p is |
|
173 $\begin{bmatrix} |
|
174 m\\ |
|
175 c\\ |
|
176 \end{bmatrix}$ |
|
177 \item We need to find $p$ to plot the line |
|
178 \end{itemize} |
|
179 \end{frame} |
|
180 |
|
181 \begin{frame}[fragile] |
|
182 \frametitle{Getting $L$ and $T^2$} |
|
183 %If you \alert{closed} IPython after session 2 |
|
184 \begin{lstlisting} |
|
185 In []: L, T = loadtxt('pendulum.txt', |
|
186 unpack=True) |
|
187 In []: tsq = T*T |
|
188 \end{lstlisting} |
|
189 \end{frame} |
|
190 |
|
191 \begin{frame}[fragile] |
|
192 \frametitle{Generating $A$} |
|
193 \begin{lstlisting} |
|
194 In []: A = array([L, ones_like(L)]) |
|
195 In []: A = A.T |
|
196 \end{lstlisting} |
|
197 \end{frame} |
|
198 |
|
199 \begin{frame}[fragile] |
|
200 \frametitle{\typ{lstsq} \ldots} |
|
201 \begin{itemize} |
|
202 \item Now use the \typ{lstsq} function |
|
203 \item Along with a lot of things, it returns the least squares solution |
|
204 \end{itemize} |
|
205 \begin{lstlisting} |
|
206 In []: result = lstsq(A,tsq) |
|
207 In []: coef = result[0] |
|
208 \end{lstlisting} |
|
209 \end{frame} |
|
210 |
|
211 \begin{frame}[fragile] |
|
212 \frametitle{Least Square Fit Line \ldots} |
|
213 We get the points of the line from \typ{coef} |
|
214 \begin{lstlisting} |
|
215 In []: Tline = coef[0]*L + coef[1] |
|
216 |
|
217 In []: Tline.shape |
|
218 \end{lstlisting} |
|
219 \begin{itemize} |
|
220 \item Now plot \typ{Tline} vs. \typ{L}, to get the Least squares fit line. |
|
221 \end{itemize} |
|
222 \begin{lstlisting} |
|
223 In []: plot(L, Tline, 'r') |
|
224 |
|
225 In []: plot(L, tsq, 'o') |
|
226 \end{lstlisting} |
|
227 \end{frame} |
|
228 |
|
229 \begin{frame}[fragile] |
|
230 \frametitle{Least Squares Fit} |
|
231 \vspace{-0.15in} |
|
232 \begin{figure} |
|
233 \includegraphics[width=4in]{data/least-sq-fit} |
|
234 \end{figure} |
|
235 \end{frame} |
125 |
236 |
126 \section{Solving linear equations} |
237 \section{Solving linear equations} |
127 |
238 |
128 \begin{frame}[fragile] |
239 \begin{frame}[fragile] |
129 \frametitle{Solution of equations} |
240 \frametitle{Solution of equations} |