2012-02-27 28 views
5

Soy un principiante pitón, actualmente utilizando scipy de odeint para calcular un sistema de ODE acoplada, sin embargo, cuando corro, Python Shell siempre me dicen que¿Cómo hacer que odeint sea exitoso?

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

lo tanto, tengo que cambiar mi paso de tiempo y el tiempo final , para hacerlo integrable. Para hacer esto, necesito probar combinaciones diferentes, lo cual es bastante doloroso. ¿Alguien podría decirme cómo puedo pedir odeint para variar automáticamente el paso de tiempo y el tiempo final para integrar con éxito este sistema de oda?

y aquí es parte del código que ha pedido 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])) 

donde wrapped_bloch3 es la función de cómputo dy/dt.

+2

Podría dar más de su código, especialmente la llamada a odeint? –

+0

Tendrá que agregar muchos más detalles de los que ha proporcionado para obtener ayuda: ¿Con qué tipo de ODE está trabajando? ¿Están rígidos? ¿Estás proporcionando una función jacobiana a 'odeint'? ¿Estás seguro de que es razonable? – talonmies

+0

gracias por repetir, y he actualizado mi pregunta :) – user1233157

Respuesta

1

EDITAR: observo que ya tiene una respuesta aquí: complex ODE systems in scipy

odeint no funciona con las ecuaciones de valor complejo. Consigo

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. 

Puede resolver su ecuación por el otro solucionador ODE:

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) 
Cuestiones relacionadas