# [SciPy-User] Questions about the "ode" differential equation solver

The Helmbolds helmrp@yahoo....
Mon Nov 5 09:56:54 CST 2012

```My questions about the "ode" differential equation sover
are stated after I lay out the specific setups used.

Given the following inputs to "odeint" and to "ode" for the
pair of differential equations:  "xdot = -Dy",  "ydot = -Ax".
(A, D) = (1.0e-2, 1.5e-2)   # Parameters.
params = (A, D)
(x0, y0) = (1000, 1500)   # Initial values.
w0 = np.asarray([x0, y0], dtype = 'float')
def J(w, t, *params):
A, D = params
x, y = w
JJ = [[0, -A], [-D, 0]]
return JJ
def func(w, t, *params):
A, D = params
x, y = w
xdot = -D*y
ydot = -A*x
temp = [xdot, ydot]
return temp
tseq = range(11)
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
First, use "odeint" on this problem.

from scipy import integrate
res = integrate.odeint(func, w0, tseq, args=params, Dfun=J, col_deriv=0,
full_output=0, ml=None, mu=None, rtol=None, atol=None,
tcrit=None, h0=0.0, hmax=0.0, hmin=0.0, ixpr=0, mxstep=0,
mxhnil=0, mxordn=12, mxords=5, printmessg=0)

print res

This yields the values shown here (in a different format)
t         x           y
======== =========== ===========
0.00     1000.00     1500.00
1.00      977.57     1490.11
2.00      955.30     1480.45
3.00      933.16     1471.01
4.00      911.16     1461.78
5.00      889.31     1452.78
6.00      867.58     1444.00
7.00      845.98     1435.43
8.00      824.52     1427.08
9.00      803.17     1418.94
10.00      781.95     1411.01
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Now use "ode" on same problem.
t0 = 0
# Order of variables changed from (w, t) to (t, w).
def f(t, w, params):                    # Note -- no *args !!!
A, D = params
x, y = w
return [-D * y, -A * x]             # Returns a list.
def jac(t, w, params):                  # Note -- no *args !!!
A, D = params
x, y = w
return [ [0, -D], [-A, 0] ]         # Returns a list of lists.

from scipy.integrate import ode
r = ode(f, jac)
r.set_integrator('vode', method = 'adams', with_jacobian = True)
r.set_initial_value(w0, t0)
r.set_f_params(params)                  # Note -- no *args !!!
r.set_jac_params(params)                # Note -- no *args !!!
tf = 10
dt = 1
while r.successful() and r.t < tf:
r.integrate(r.t + dt)
temp = [r.t, r.y]
print 'temp = ', temp

This produces essentially the same values as when using "odeint".

My questions are as follows:
Why the quirky change in the order of the variables?

I'm puzzled by the absence of *args or *params in "ode".
Moreover, if I change any of these to the "*" form,
"ode" crashes with an error of the general form:
"ValueError: need more than 0 values to unpack"
What am I doing wrong?

Bob H
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20121105/f90e5160/attachment.html
```