2014-11-04 95 views
3

我有一個馮·諾依曼式看起來像: 博士/ DT = - I [H,R],其中r和H是複數和I的平方matricies需要使用python腳本查找r(t)。解決賦在python複雜矩陣作爲初始值

是否有任何標準儀器來整合這些方程?

當我解決另一個水合作用矢量作爲初始值,如薛定諤方程: DY/DT = - I Hÿ,我用scipy.integrate.ode函數( 'zvode'),但試圖用同樣的功能馮·諾依曼方程給了我以下錯誤:

**scipy/integrate/_ode.py:869: UserWarning: zvode: Illegal input detected. (See printed message.) 
ZVODE-- ZWORK length needed, LENZW (=I1), exceeds LZW (=I2) 
self.messages.get(istate, 'Unexpected istate=%s' % istate)) 
    In above message, I1 =  72 I2 =  24** 

這裏是代碼:

def integrate(r, t0, t1, dt): 
    e = linspace(t0, t1, (t1 - t0)/dt + 10) 
    g = linspace(t0, t1, (t1 - t0)/dt + 10) 
    u = linspace(t0, t1, (t1 - t0)/dt + 10) 
    while r.successful() and r.t < t1: 
    r.integrate(r.t + dt) 
    e[r.t/dt] = abs(r.y[0][0]) ** 2 
    g[r.t/dt] = abs(r.y[1][1]) ** 2 
    u[r.t/dt] = abs(r.y[2][2]) ** 2 
    return e, g, u 


# von Neumann equation's 
def right_part(t, rho): 
    hamiltonian = (h/2) * array(
    [[delta, omega_s, omega_p/2.0 * sin(t * w_p)], 
    [omega_s, 0.0, 0.0], 
    [omega_p/2.0 * sin(t * w_p), 0.0, 0.0]], 
    dtype=complex128) 
    return (dot(hamiltonian, rho) - dot(rho, hamiltonian))/(1j * h) 


def create_integrator(): 
    r = ode(right_part).set_integrator('zvode', method='bdf', with_jacobian=False) 
    psi_init = array([[1.0, 0.0, 0.0], 
        [0.0, 0.0, 0.0], 
        [0.0, 0.0, 0.0]], dtype=complex128) 
    t0 = 0 
    r.set_initial_value(psi_init, t0) 
    return r, t0 


def main(): 
    r, t0 = create_integrator() 
    t1 = 10 ** -6 
    dt = 10 ** -11 
    e, g, u = integrate(r, t0, t1, dt) 

main() 

回答

0

我創建的包裝調用odeintw可以處理這樣的復矩陣方程。有關矩陣微分方程的另一個問題見How to plot the Eigenvalues when solving matrix coupled differential equations in PYTHON?

下面是您的代碼的簡化版本,顯示如何使用它。 (爲了簡單起見,我擺脫了你例子中的大部分常量)。

import numpy as np 
from odeintw import odeintw 


def right_part(rho, t, w_p): 
    hamiltonian = (1./2) * np.array(
     [[0.1, 0.01, 1.0/2.0 * np.sin(t * w_p)], 
     [0.01, 0.0, 0.0], 
     [1.0/2.0 * np.sin(t * w_p), 0.0, 0.0]], 
     dtype=np.complex128) 
    return (np.dot(hamiltonian, rho) - np.dot(rho, hamiltonian))/(1j) 


psi_init = np.array([[1.0, 0.0, 0.0], 
        [0.0, 0.0, 0.0], 
        [0.0, 0.0, 0.0]], dtype=np.complex128) 


t = np.linspace(0, 10, 101) 
sol = odeintw(right_part, psi_init, t, args=(0.25,)) 

sol將是一個複雜numpy的陣列形狀(101, 3, 3),保持所述溶液rho(t)。第一個索引是時間索引,另外兩個索引是3x3矩陣。

1

QuTiP有一些很好的集成商爲了做到這一點,使用諸如Master方程和Lindblad阻尼項。 QuTiP本身只是scipy.odeint的一個簡單包裝,但它使許多機制更好,特別是因爲它有很好的文檔。

+0

看起來它可以在張量操作方面取代numpy!很酷! – krems 2015-07-06 15:04:47