day1/session4.tex
changeset 127 44c2f614e321
parent 124 d43a698712e0
child 131 b3a78754c4a9
--- a/day1/session4.tex	Thu Oct 15 11:34:35 2009 +0530
+++ b/day1/session4.tex	Thu Oct 15 15:50:55 2009 +0530
@@ -52,7 +52,7 @@
 \setcounter{time}{0}
 \newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}}
 
-\newcommand{\typ}[1]{\texttt{#1}}
+\newcommand{\typ}[1]{\lstinline{#1}}
 
 \newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}}  }
 
@@ -205,6 +205,9 @@
   \end{lstlisting}
 \end{frame}
 
+\section{Integration}
+
+\subsection{ODEs}
 
 \begin{frame}[fragile]
 \frametitle{ODE Integration}
@@ -214,22 +217,68 @@
 \end{equation*}
 \begin{itemize}
 \item This equation can be written as a system of two first order ODEs
-\item $\dot{\theta} = \omega$
-\item $\dot{\omega} = -\frac{g}{L}sin(\theta)$
-\item At $t = 0$  \\
-$\theta = \theta_0$ \&
-$\omega = 0$
+\end{itemize}
+\begin{align}
+\dot{\theta} &= \omega \\
+\dot{\omega} &= -\frac{g}{L}sin(\theta) \\
+ \text{At}\ t &= 0 : \nonumber \\
+ \theta = \theta_0\quad & \&\quad  \omega = 0 \nonumber
+\end{align}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Solving ODEs using SciPy}
+\begin{itemize}
+\item We use the \typ{odeint} function from scipy to do the integration
+\item Define a function as below
 \end{itemize}
 \begin{lstlisting}
+In []: def pend_int(unknown, t, p):
+  ....     theta, omega = unknown
+  ....     g, L = p
+  ....     f=[omega, -(g/L)*sin(theta)]
+  ....     return f
+  ....
 \end{lstlisting}
 \end{frame}
 
+\begin{frame}[fragile]
+\frametitle{Solving ODEs using SciPy \ldots}
+\begin{itemize}
+\item \typ{t} is the time variable \\ 
+\item \typ{p} has the constants \\
+\item \typ{initial} has the initial values
+\end{itemize}
+\begin{lstlisting}
+In []: t = linspace(0, 10, 101)
+In []: p=(-9.81, 0.2)
+In []: initial = [10*2*pi/360, 0]
+\end{lstlisting}
+\end{frame}
 
+\begin{frame}[fragile]
+\frametitle{Solving ODEs using SciPy \ldots}
+
+\small{\typ{In []: from scipy.integrate import odeint}}
+\begin{lstlisting}
+In []: pend_sol = odeint(pend_int, 
+                         initial,t, 
+                         args=(p,))
+\end{lstlisting}
+\end{frame}
+
+\subsection{Quadrature}
+
+\begin{frame}[fragile]
+\frametitle{Quadrature}
+Calculate the area under $(sin(x) + x^2)$ in the range $(0,1)$
+\small{\typ{In []: from scipy.integrate import quad}}
+  \begin{lstlisting}
+In []: f(x):
+        return sin(x)+x**2
+In []: integrate.quad(f, 0, 1)
+  \end{lstlisting}
+\end{frame}
 
 \end{document}
 
-\begin{frame}[fragile]
-\frametitle{}
-\begin{lstlisting}
-\end{lstlisting}
-\end{frame}