8 ********* working knowledge of functions |
8 ********* working knowledge of functions |
9 *** Script |
9 *** Script |
10 Welcome friends. |
10 Welcome friends. |
11 |
11 |
12 In this tutorial we shall look at solving Ordinary Differential Equations, |
12 In this tutorial we shall look at solving Ordinary Differential Equations, |
13 ODE henceforth using odeint in Python. |
13 ODE henceforth using odeint in Python. In this tutorial we shall be using |
|
14 the concepts of arrays, functions and lists which we have covered in various |
|
15 previous tutorials. |
14 |
16 |
15 Let's consider the classic problem of the spread of an epidemic in a |
17 Let's consider the classic problem of the spread of an epidemic in a |
16 population. |
18 population. |
17 This is given by the ordinary differential equation dy/dt = ky(L-y) |
19 This is given by the ordinary differential equation dy/dt = ky(L-y) |
18 where L is the total population and k is an arbitrary constant. For our |
20 where L is the total population and k is an arbitrary constant. For our |
19 problem Let us use L=25000, k=0.00003. |
21 problem Let us use L=25000, k=0.00003. |
20 Let the boundary condition be y(0)=250. |
22 Let the boundary condition be y(0)=250. |
21 |
23 |
22 Lets fire up IPython by typing ipython -pylab interpreter. |
24 Let's now fire up IPython by typing ipython -pylab interpreter. |
23 |
25 |
24 As we saw in one of earlier session, sometimes pylab wont 'import' all |
26 As we saw in one of earlier session, sometimes pylab wont 'import' all |
25 packages. For solving 'ordinary differential equations' also we shall |
27 packages. For solving 'ordinary differential equations' also we shall |
26 have to import 'odeint' function which is a part of the SciPy package. |
28 have to import 'odeint' function which is a part of the SciPy package. |
27 So we run the magic command: |
29 So we run the magic command: |
120 In []: plot(pend_sol[1], t) will plot omega against t |
122 In []: plot(pend_sol[1], t) will plot omega against t |
121 Plotting theta against t and omega against t we obtain the plots as shown |
123 Plotting theta against t and omega against t we obtain the plots as shown |
122 in the slide. |
124 in the slide. |
123 |
125 |
124 Thus we come to the end of this tutorial on solving ordinary differential |
126 Thus we come to the end of this tutorial on solving ordinary differential |
125 equations in Python. In this tutorial we have learnt, |
127 equations in Python. In this tutorial we have learnt how to solve ordinary |
|
128 differential equations of first and second order. |
126 |
129 |
127 *** Notes |
130 *** Notes |