diff options
Diffstat (limited to 'day1/session4.tex')
-rw-r--r-- | day1/session4.tex | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/day1/session4.tex b/day1/session4.tex index 67988de..fb8e2e4 100644 --- a/day1/session4.tex +++ b/day1/session4.tex @@ -249,9 +249,55 @@ In []: integrate.quad(f, 0, 1) \end{frame} \begin{frame}[fragile] +\frametitle{Functions - Calling them} +\begin{lstlisting} +In [15]: f() +--------------------------------------- +\end{lstlisting} +\alert{\typ{TypeError:}}\typ{f() takes exactly 1 argument} +\typ{(0 given)} +\begin{lstlisting} +In []: f(0) +Out[]: 0.0 +In []: f(1) +Out[]: 1.8414709848078965 +\end{lstlisting} +\end{frame} + + +\begin{frame}[fragile] +\frametitle{Functions - Default Arguments} +\begin{lstlisting} +In []: def f(x=1): + return sin(x)+x**2 +In []: f(10) +Out[]: 99.455978889110625 +In []: f(1) +Out[]: 1.8414709848078965 +In []: f() +Out[]: 1.8414709848078965 +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Functions - Keyword Arguments} +\begin{lstlisting} +In []: def f(x=1, y=pi): + return sin(y)+x**2 +In []: f() +Out[]: 1.0000000000000002 +In []: f(2) +Out[]: 4.0 +In []: f(y=2) +Out[]: 1.9092974268256817 +In []: f(y=pi/2,x=0) +Out[]: 1.0 +\end{lstlisting} +\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 @@ -262,6 +308,13 @@ In []: integrate.quad(f, 0, 1) \end{itemize} \end{frame} +\begin{frame}[fragile] +\frametitle{Quadrature \ldots} +\begin{lstlisting} +In []: integrate.quad(f, 0, 1) +\end{lstlisting} +Returns the integral and an estimate of the absolute error in the result. +\end{frame} \subsection{ODEs} |