[SciPy-user] Additional output from scipy.integrate.ode[int]

gyro gyromagnetic@gmail....
Tue Mar 3 14:40:11 CST 2009

I was wondering if it is possible to specify additional outputs that
are calculated in the function specifying the rhs of the odes.

As an trivial example (adapting the example in the documentation):


from scipy.integrate import ode

y0, t0 = [1.0j, 2.0], 0

def f(t, y, arg1):
    extra = y[0]*t - y[1]
    rhs = [1j*arg1*y[0] + y[1], -arg1*y[1]**2]
    return (rhs,extra)

def jac(t, y, arg1):
    return [[1j*arg1, 1], [0, -arg1*2*y[1]]]

r = ode(f, jac).set_integrator('zvode', method='bdf', with_jacobian=True)
r.set_initial_value(y0, t0).set_f_params(2.0).set_jac_params(2.0)
t1 = 10
dt = 1
while r.successful() and r.t < t1:
    print r.t, r.y, r.extra


I realize that I can calculate the 'extra' after I have the complete
solution, but it would be convenient to have the ability to get this
information directly from the solver.

If this capability is not currently available, is it of interest to
have it implemented?



More information about the SciPy-user mailing list