summaryrefslogtreecommitdiff
path: root/day1/session4.tex
diff options
context:
space:
mode:
Diffstat (limited to 'day1/session4.tex')
-rw-r--r--day1/session4.tex69
1 files changed, 59 insertions, 10 deletions
diff --git a/day1/session4.tex b/day1/session4.tex
index b2175ad..eec7e85 100644
--- a/day1/session4.tex
+++ b/day1/session4.tex
@@ -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 @@ Example problem: Consider the set of equations
\end{lstlisting}
\end{frame}
+\section{Integration}
+
+\subsection{ODEs}
\begin{frame}[fragile]
\frametitle{ODE Integration}
@@ -214,22 +217,68 @@ We shall use the simple ODE of a simple pendulum.
\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}
-
-
-\end{document}
+\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{}
+\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}
+