diff options
author | Madhusudan.C.S | 2009-10-26 20:29:54 +0530 |
---|---|---|
committer | Madhusudan.C.S | 2009-10-26 20:29:54 +0530 |
commit | 386bbad891f0e55d38441b9e898ac6f8ce1b2e20 (patch) | |
tree | 80bec6811f77c7591f062b63220ee5ecc8f0b71f /day1/session4.tex | |
parent | 4f84c3b041eb6026cd79e7616f506295cf08737b (diff) | |
parent | e742fa25be24aa079515be2139977df22db7fc76 (diff) | |
download | workshops-386bbad891f0e55d38441b9e898ac6f8ce1b2e20.tar.gz workshops-386bbad891f0e55d38441b9e898ac6f8ce1b2e20.tar.bz2 workshops-386bbad891f0e55d38441b9e898ac6f8ce1b2e20.zip |
Merged Madhu and Mainline branches.
Diffstat (limited to 'day1/session4.tex')
-rw-r--r-- | day1/session4.tex | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/day1/session4.tex b/day1/session4.tex index c01c20e..67988de 100644 --- a/day1/session4.tex +++ b/day1/session4.tex @@ -210,8 +210,59 @@ Example problem: Consider the set of equations \end{lstlisting} \end{frame} + \section{Integration} +\subsection{Quadrature} + +\begin{frame}[fragile] +\frametitle{Quadrature} +\begin{itemize} +\item We wish to find area under a curve +\item Area under $(sin(x) + x^2)$ in $(0,1)$ +\item scipy has functions to do that +\end{itemize} +\small{\typ{In []: from scipy.integrate import quad}} +\begin{itemize} +\item Inputs - function to integrate, limits +\end{itemize} +\begin{lstlisting} +In []: x = 0 +In []: integrate.quad(sin(x)+x**2, 0, 1) +\end{lstlisting} +\alert{\typ{error:}} +\typ{First argument must be a callable function.} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Functions - Definition} +\begin{lstlisting} +In []: def f(x): + return sin(x)+x**2 +In []: integrate.quad(f, 0, 1) +\end{lstlisting} +\begin{itemize} +\item \typ{def} +\item arguments +\item \typ{return} +\end{itemize} +\end{frame} + +\begin{frame}[fragile] + \frametitle{More on functions} + \begin{itemize} + \item Support default and keyword arguments + \item Scope of variables in the function is local + \item Mutable items are \alert{passed by reference} + \item First line after definition may be a documentation string + (\alert{recommended!}) + \item Function definition and execution defines a name bound to the + function + \item You \emph{can} assign a variable to a function! + \end{itemize} +\end{frame} + + \subsection{ODEs} \begin{frame}[fragile] @@ -272,18 +323,5 @@ In []: pend_sol = odeint(pend_int, \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} |