修訂 | 4f04f941fd6963a4874023ca5925fc8d5292b6b0 (tree) |
---|---|
時間 | 2007-03-23 00:27:38 |
作者 | iselllo |
Commiter | iselllo |
I added the code Python-codes/ode4_solver_test.py. It is a very easy
examples about how to use the Python integrate.odeint to solve this time
for a 1st order ODE. As shown in Python-codes/ode3_solver_test.py,
higher order ODE's are solved as a system of 1st order ODE's.
@@ -0,0 +1,36 @@ | ||
1 | +#! /usr/bin/env python | |
2 | +from scipy import * | |
3 | +import pylab # used to read the .csv file | |
4 | + | |
5 | + | |
6 | +from scipy.special import * # to be able to use the error function | |
7 | + | |
8 | +def func(y, t): | |
9 | + return y+3.*t | |
10 | + | |
11 | + | |
12 | +y0 = 1. | |
13 | + | |
14 | +t = arange(0,4.0, 0.01) | |
15 | + | |
16 | + | |
17 | +y = integrate.odeint(func, y0, t,printmessg=1) | |
18 | + | |
19 | + | |
20 | +print 'the shape of the solution is', shape(y) | |
21 | + | |
22 | + | |
23 | +pylab.plot(t,y[:,0]) | |
24 | +pylab.xlabel('Time') | |
25 | +pylab.ylabel('y(t)') | |
26 | +pylab.title('solution') | |
27 | +pylab.grid(True) | |
28 | +pylab.savefig('solution_1st_order_ODE') | |
29 | + | |
30 | +pylab.hold(False) | |
31 | + | |
32 | + | |
33 | + | |
34 | + | |
35 | + | |
36 | +print 'So far so good' | |
\ No newline at end of file |