修订版 | 647f7300fbc055886066d17c5278bf4481604e97 (tree) |
---|---|
时间 | 2007-03-30 02:45:44 |
作者 | iselllo |
Commiter | iselllo |
I added the code Python-codes/ode5_solver_test.py which solves a system
of 2 coupled equations for a trivial prey-predator system. Something
along these lines could be used to study and solve numerically the eqs
for nucleation and accumulation mode presented in the paper by Vouitsis.
@@ -0,0 +1,50 @@ | ||
1 | +#! /usr/bin/env python | |
2 | +from scipy import * | |
3 | +import pylab # used to read the .csv file | |
4 | + | |
5 | + | |
6 | + | |
7 | + | |
8 | +#the purpose of this code is now to solve a system of 1st order ode's which are necessary for a prey-predator system | |
9 | + | |
10 | + | |
11 | +def population(y,t,a,b,c,p): | |
12 | + | |
13 | + return [a*y[0]-b*y[0]*y[1],-c*y[1]+p*y[0]*y[1]] | |
14 | + | |
15 | + | |
16 | +a=2. | |
17 | +b=1.e-1 | |
18 | +c=1.e-1 | |
19 | +p=1.e-2 | |
20 | + | |
21 | +y0_0=15. | |
22 | +y1_0=15. | |
23 | + | |
24 | +y0 = [y0_0, y1_0] | |
25 | + | |
26 | + | |
27 | +t=arange(0.,100.,0.01) | |
28 | + | |
29 | +print 't is', t | |
30 | + | |
31 | +y = integrate.odeint(population, y0, t,args=(a,b,c,p),printmessg=1) | |
32 | + | |
33 | + | |
34 | + | |
35 | + | |
36 | +pylab.plot(t,y[:,0],t,y[:,1]) | |
37 | +pylab.xlabel('Time') | |
38 | +pylab.ylabel('y(t)') | |
39 | +pylab.legend(('prey population','predator population')) | |
40 | +pylab.title('solution') | |
41 | +pylab.grid(True) | |
42 | +pylab.savefig('preyandpredator') | |
43 | + | |
44 | +pylab.hold(False) | |
45 | + | |
46 | + | |
47 | + | |
48 | + | |
49 | + | |
50 | +print 'So far so good' | |
\ No newline at end of file |