5

I am a python beginner, currently using scipy's odeint to compute a coupled ODE system, however, when I run, python shell always tell me that

>>> Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information. >>> 

So, I have to change my time step and final time, in order to make it integratable. To do this, I need to try a different combinations, which is quite a pain. Could anyone tell me how can I ask odeint to automatically vary the time step and final time to successfully integrate this ode system?

and here is part of the code which has called odeint:

def main(t, init_pop_a, init_pop_b, *args, **kwargs): """ solve the obe for a given set of parameters """ # construct initial condition # initially, rho_ee = 0 rho_init = zeros((16,16))*1j ######## rho_init[1,1] = init_pop_a rho_init[2,2] = init_pop_b rho_init[0,0] = 1 - (init_pop_a + init_pop_b)######## rho_init_ravel, params = to_1d(rho_init) # perform the integration result = odeint(wrapped_bloch3, rho_init_ravel, t, args=args) # BUG: need to pass kwargs # rewrap the result return from_1d(result, params, prepend=(len(t),)) things = [2*pi, 20*pi, 0,0, 0,0, 0.1,100] Omega_a, Omega_b, Delta_a, Delta_b, \ init_pop_a, init_pop_b, tstep, tfinal = things args = ( Delta_a, Delta_b, Omega_a, Omega_b ) t = arange(0, tfinal + tstep, tstep) data = main(t, init_pop_a, init_pop_b, *args) plt.plot(t,abs(data[:,4,4])) 

where wrapped_bloch3 is the function compute dy/dt.

5
  • 2
    Could you provide more of your code, especially the call to odeint? Commented Feb 27, 2012 at 14:05
  • You are going to have to add quite a lot more detail than you have provided to get help: What type of ODEs are you working with? Are they stiff? Are you providing a Jacobian function to odeint? Are you sure it is reasonable? Commented Feb 27, 2012 at 14:07
  • thanks for replaying, and i have updated my question:) Commented Feb 27, 2012 at 14:40
  • @user1233157: the most obvious thing to do is define a jacobian term for the solver. That should greatly accelerate convergence. Commented Feb 27, 2012 at 15:30
  • @talonmies: thank you for the suggestion, however, my coupled ode system have 16*16 number of equations which could take me a very long time to write theirs Jacobian. i have looked the documentation of odeint, they have someting like while successful, looks like may be able to solve my problem, but i just couldnt understand that. Commented Feb 27, 2012 at 15:41

1 Answer 1

1

EDIT: I note you already got an answer here: complex ODE systems in scipy

odeint does not work with complex-valued equations. I get

from scipy.integrate import odeint import numpy as np def func(t, y): return 1 + 1j t = np.linspace(0, 1, 200) y = odeint(func, 0, t) # -> This outputs: # # TypeError: can't convert complex to float # odepack.error: Result from function call is not a proper array of floats. 

You can solve your equation by the other ode solver:

from scipy.integrate import ode import numpy as np def myodeint(func, y0, t): y0 = np.array(y0, complex) func2 = lambda t, y: func(y, t) # odeint has these the other way :/ sol = ode(func2).set_integrator('zvode').set_initial_value(y0, t=t[0]) y = [sol.integrate(tp) for tp in t[1:]] y.insert(0, y0) return np.array(y) def func(y, t, alpha): return 1j*alpha*y alpha = 3.3 t = np.linspace(0, 1, 200) y = myodeint(lambda y, t: func(y, t, alpha), [1, 0, 0], t) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.