208 In []: allclose(Ax, b) |
208 In []: allclose(Ax, b) |
209 Out[]: True |
209 Out[]: True |
210 \end{lstlisting} |
210 \end{lstlisting} |
211 \end{frame} |
211 \end{frame} |
212 |
212 |
|
213 |
213 \section{Integration} |
214 \section{Integration} |
|
215 |
|
216 \subsection{Quadrature} |
|
217 |
|
218 \begin{frame}[fragile] |
|
219 \frametitle{Quadrature} |
|
220 \begin{itemize} |
|
221 \item We wish to find area under a curve |
|
222 \item Area under $(sin(x) + x^2)$ in $(0,1)$ |
|
223 \item scipy has functions to do that |
|
224 \end{itemize} |
|
225 \small{\typ{In []: from scipy.integrate import quad}} |
|
226 \begin{itemize} |
|
227 \item Inputs - function to integrate, limits |
|
228 \end{itemize} |
|
229 \begin{lstlisting} |
|
230 In []: x = 0 |
|
231 In []: integrate.quad(sin(x)+x**2, 0, 1) |
|
232 \end{lstlisting} |
|
233 \alert{\typ{error:}} |
|
234 \typ{First argument must be a callable function.} |
|
235 \end{frame} |
|
236 |
|
237 \begin{frame}[fragile] |
|
238 \frametitle{Functions - Definition} |
|
239 \begin{lstlisting} |
|
240 In []: def f(x): |
|
241 return sin(x)+x**2 |
|
242 In []: integrate.quad(f, 0, 1) |
|
243 \end{lstlisting} |
|
244 \begin{itemize} |
|
245 \item \typ{def} |
|
246 \item arguments |
|
247 \item \typ{return} |
|
248 \end{itemize} |
|
249 \end{frame} |
|
250 |
|
251 \begin{frame}[fragile] |
|
252 \frametitle{More on functions} |
|
253 \begin{itemize} |
|
254 \item Support default and keyword arguments |
|
255 \item Scope of variables in the function is local |
|
256 \item Mutable items are \alert{passed by reference} |
|
257 \item First line after definition may be a documentation string |
|
258 (\alert{recommended!}) |
|
259 \item Function definition and execution defines a name bound to the |
|
260 function |
|
261 \item You \emph{can} assign a variable to a function! |
|
262 \end{itemize} |
|
263 \end{frame} |
|
264 |
214 |
265 |
215 \subsection{ODEs} |
266 \subsection{ODEs} |
216 |
267 |
217 \begin{frame}[fragile] |
268 \begin{frame}[fragile] |
218 \frametitle{ODE Integration} |
269 \frametitle{ODE Integration} |