summaryrefslogtreecommitdiff
path: root/odes.org
diff options
context:
space:
mode:
Diffstat (limited to 'odes.org')
-rw-r--r--odes.org25
1 files changed, 9 insertions, 16 deletions
diff --git a/odes.org b/odes.org
index 722febf..42e7975 100644
--- a/odes.org
+++ b/odes.org
@@ -11,40 +11,36 @@
In this tutorial we shall look at solving Ordinary Differential Equations,
ODE henceforth using odeint in Python. In this tutorial we shall be using
- the concepts of arrays, functions and lists which we have covered in various
+ the concepts of arrays, functions and lists which we have covered in
previous tutorials.
Let's consider the classic problem of the spread of an epidemic in a
population.
This is given by the ordinary differential equation dy/dt = ky(L-y)
where L is the total population and k is an arbitrary constant. For our
- problem Let us use L=25000, k=0.00003.
+ problem Let us use L=250000, k=0.00003.
Let the boundary condition be y(0)=250.
Let's now fire up IPython by typing ipython -pylab interpreter.
- As we saw in one of earlier session, sometimes pylab wont 'import' all
- packages. For solving 'ordinary differential equations' also we shall
- have to import 'odeint' function which is a part of the SciPy package.
+ As we saw in one of the earlier sessions, sometimes we will need more than
+ pylab to get our job done. For solving 'ordinary differential equations'
+ we shall have to import 'odeint' function, which is a part of the SciPy package.
So we run the magic command:
In []: from scipy.integrate import odeint
- For now just remember this as a command that does some magic to obtain
- the function odeint in to our program.
The details regarding `import' shall be covered in a subsequent tutorial.
We can represent the given ODE as a Python function.
This function takes the dependent variable y and the independent variable t
as arguments and returns the ODE.
- Our function looks like this:
- (Showing the slide should be sufficient)
Let us now define our function.
In []: def epid(y, t):
.... k = 0.00003
- .... L = 25000
+ .... L = 250000
.... return k*y*(L-y)
Independent variable t can be assigned the values in the interval of
@@ -118,13 +114,10 @@
In []: pend_sol = odeint(pend_int, initial,t)
- In []: plot(pend_sol[0], t) plot theta against t
- In []: plot(pend_sol[1], t) will plot omega against t
- Plotting theta against t and omega against t we obtain the plots as shown
- in the slide.
+ In []: plot(pend_sol)
+ This gives us 2 plots. The green plot is omega vs t and the blue is theta vs t.
- Thus we come to the end of this tutorial on solving ordinary differential
- equations in Python. In this tutorial we have learnt how to solve ordinary
+ Thus we come to the end of this tutorial. In this tutorial we have learnt how to solve ordinary
differential equations of first and second order.
*** Notes