2012-02-27 9 views
5

io sono un principiante pitone, attualmente in uso SciPy di ​​odeint per calcolare un sistema di ODE accoppiato, tuttavia, quando corro, shell Python mi dicono sempre cheCome rendere efficace l'odeint?

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

Quindi, devo cambiare il mio passo il tempo e il tempo finale , per renderlo integrabile. Per fare questo, ho bisogno di provare una combinazione diversa, che è piuttosto un dolore. Qualcuno potrebbe dirmi come posso chiedere a odeint di variare automaticamente il passo temporale e l'ora finale per integrare con successo questo sistema ode?

e qui fa parte del codice che ha chiamato 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])) 

dove wrapped_bloch3 è la funzione di calcolo dy/dt.

+2

Potrebbe fornire più del vostro codice, in particolare la chiamata a odeint? –

+0

Dovrai aggiungere molti più dettagli di quelli forniti per ottenere aiuto: che tipo di ODE stai lavorando? Sono rigidi? Stai fornendo una funzione Jacobiana a 'odeint'? Sei sicuro che sia ragionevole? – talonmies

+0

grazie per la riproduzione, e ho aggiornato la mia domanda :) – user1233157

risposta

1

EDIT: faccio notare che già ottenuto una risposta qui: complex ODE systems in scipy

odeint non funziona con equazioni complesse valori. Ottengo

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. 

È possibile risolvere l'equazione per l'altra ode risolutore:

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)