diff options
author | Puneeth Chaganti | 2009-11-05 23:50:35 +0530 |
---|---|---|
committer | Puneeth Chaganti | 2009-11-05 23:50:35 +0530 |
commit | 542263d2b9d88e27de2244071b894a7438219ed1 (patch) | |
tree | 24884a2e8926b404e8f14b3b8aaff1ae8f446465 /day1/session6.tex | |
parent | 82969f158c93d4faed88c7567ff86f66a1ada2ed (diff) | |
download | workshops-542263d2b9d88e27de2244071b894a7438219ed1.tar.gz workshops-542263d2b9d88e27de2244071b894a7438219ed1.tar.bz2 workshops-542263d2b9d88e27de2244071b894a7438219ed1.zip |
Added functions to session6.
Diffstat (limited to 'day1/session6.tex')
-rwxr-xr-x | day1/session6.tex | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/day1/session6.tex b/day1/session6.tex index 3db3b5a..5323f0e 100755 --- a/day1/session6.tex +++ b/day1/session6.tex @@ -302,8 +302,61 @@ Use \kwrd{solve()} \item Input arguments - Function and initial estimate \item Returns the solution \end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{\typ{fsolve}} +Find the root of $sin(x)+cos^2(x)$ nearest to $0$ +\begin{lstlisting} +In []: fsolve(sin(x)+cos(x)**2, 0) +NameError: name 'x' is not defined +In []: x = linspace(-pi, pi) +In []: fsolve(sin(x)+cos(x)**2, 0) +\end{lstlisting} +\begin{small} +\alert{\typ{TypeError:}} +\typ{'numpy.ndarray' object is not callable} +\end{small} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Functions - Definition} +We have been using them all along. Now let's see how to define them. +\begin{lstlisting} +In []: def f(x): + return sin(x)+cos(x)**2 +\end{lstlisting} +\begin{itemize} +\item \typ{def} +\item name +\item arguments +\item \typ{return} +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Functions - Calling them} \begin{lstlisting} - In []: fsolve(our_f, -pi/2) +In [15]: f() +--------------------------------------- +\end{lstlisting} +\alert{\typ{TypeError:}}\typ{f() takes exactly 1 argument} +\typ{(0 given)} +\begin{lstlisting} +In []: f(0) +Out[]: 1.0 +In []: f(1) +Out[]: 1.1333975665343254 +\end{lstlisting} +More on Functions later \ldots +\end{frame} + +\begin{frame}[fragile] +\frametitle{\typ{fsolve} \ldots} +Find the root of $sin(x)+cos^2(x)$ nearest to $0$ +\begin{lstlisting} +In []: fsolve(f, 0) +Out[]: -0.66623943249251527 \end{lstlisting} \end{frame} @@ -381,8 +434,10 @@ In []: pend_sol = odeint(pend_int, \begin{frame} \frametitle{Things we have learned} \begin{itemize} - \item Solving ODEs + \item Solving Linear Equations + \item Defining Functions \item Finding Roots + \item Solving ODEs \end{itemize} \end{frame} |