Merged heads manually.
authorPuneeth Chaganti <punchagan@fossee.in>
Fri, 20 Nov 2009 00:42:56 +0530
changeset 324 2361df479844
parent 323 4e44d7741c94 (diff)
parent 322 54fb746c1565 (current diff)
child 325 0cde91487637
Merged heads manually.
day1/cheatsheet6.tex
--- a/day1/cheatsheet6.tex	Fri Nov 20 00:35:16 2009 +0530
+++ b/day1/cheatsheet6.tex	Fri Nov 20 00:42:56 2009 +0530
@@ -15,6 +15,7 @@
 \usepackage{ae,aecompl}
 \usepackage{mathpazo,courier,euler}
 \usepackage[scaled=.95]{helvet}
+\usepackage{amsmath}
 \begin{document}
 \date{}
 \vspace{-1in}
@@ -27,7 +28,7 @@
   \begin{align*}
     3x + 2y - z  & = 1 \\
     2x - 2y + 4z  & = -2 \\
-    -x + $\frac{1}{2}$y -z & = 0
+    -x + \frac{1}{2}y -z & = 0
   \end{align*}\\
 The matrix representation is:\\
 \begin{center}
@@ -84,7 +85,7 @@
 \subsection{Roots of non-linear eqations}
 For Finding the roots of a non linear equation(defined as $f(x)=0$), around a starting estimate we use \typ{fsolve}:\\
 \typ{In []: from scipy.optimize import fsolve}\\
-\typ{fsolve} is not part of \typ{pylab}, instead it is part of \textbf{optimize} package of \textbf{scipy}, and hence we \textbf{import} it.\\
+\typ{fsolve} is not a part of \typ{pylab}, instead is a function in the \textbf{optimize} module of \textbf{scipy}, and hence we \textbf{import} it.\\
 %\typ{fsolve} takes first argument as name of function, which evaluates $f(x)$, whose roots one wants to find. And second argument is starting estimate, around which roots are found.
 For illustration, we want to find roots of equation:
 \begin{center}
@@ -103,18 +104,29 @@
 \end{lstlisting}
 
 \section{ODE}
+
+We wish to solve an (a system of) Ordinary Differential Equation. For this purpose, we shall use \typ{odeint}.\\
+\typ{In []: from scipy.integrate import odeint}\\
+\typ{odeint} is a function in the \textbf{integrate} module of \textbf{scipy}.\\
+As an illustration, let us solve the ODE below:\\
+$\frac{dy}{dt} = ky(L-y)$, L = 25000, k = 0.00003, y(0) = 250\\
+We define a function (as below) that takes $y$ and time as arguments and returns the right hand side of the ODE.
 \begin{lstlisting}
-  In []: def epid(y, t):
+In []: def f(y, t):
   ....     k, L = 0.00003, 25000
   ....     return k*y*(L-y)
   ....
-  
-  In []: t = arange(0, 12, 0.2)
-
-  In []: y = odeint(epid, 250, t)
-
-  In []: plot(t, y)
+\end{lstlisting}
+Next we define the time over which we wish to solve the ODE. We also note the initial conditions given to us.
+\begin{lstlisting}
+In []: t = linspace(0, 12, 61)
+In []: y0 = 250
 \end{lstlisting}
+To solve the ODE, we call the \typ{odeint} function with three arguments - the function \typ{f}, initial conditions and the time vector. 
+\begin{lstlisting}
+In []: y = odeint(f, y0, t)
+\end{lstlisting}
+Note: To solve a system of ODEs, we need to change the function to return the right hand side of all the equations and the system and the pass the required number of initial conditions to the \typ{odeint} function.
 \section{Links and References}
 \begin{itemize}
 \item Documentation for Numpy and Scipy is available at: \url{http://docs.scipy.org/doc/}