使用python和第二个参数的双重使用取决于第一个

时间:2020-06-23 20:38:51

标签: python

我有这种关系,我使用python编写代码来计算它,我不确定代码是否正确。如果可以,请给我任何建议,或者如何改善代码??

enter image description here

    import matplotlib.pyplot as plt
    import numpy as np
    from scipy.special import comb
    from scipy.constants import k
    from numpy import arange
    p12 = 1 # system initial state 12
    w0 = 1  # system
    wn = 0  # wb/w0 bath
    U = 0.1  
    N = 50 
    n = (N/2)
    a =0.007
    t = 1000# Time
    Z = 2**N * (np.cosh(U*wn/2))**N
    q12 = []
    f11 = []
    def Jrange(start, n, step):
        numelements = int((stop-start)/float(step))
        for i in range(numelements+1):
                yield start + i*step
    def trange(tstart,tstop,tstep):
        tnumelements = int((tstop-tstart)/float(tstep))
        for i in range(tnumelements+1):
                yield tstart + i*tstep
    for t in trange(tstart,tstop,tstep): 
        roh2 = 0
        roh12 = 0
        roh1 = 0
        roh11 = 0
        for J in Jrange (0,stop,1) :    
            Nj = (comb (N,(n+J))) - (comb (N,(n+J+1)))
            for m in arange (-J,J+1):
                r1 = np.sqrt (J*(J + 1) - m*(m + 1)) #r+
                r2 = np.sqrt (J*(J + 1) - m*(m - 1)) #r-
                Omega1 = (w0 - wn) + (4 *a*(m + (1/2)))/(np.sqrt(N))  #Omeg+
                gamma1  = np.sqrt( (Omega1**2 /4)+ (4*a**2 * r1**2)/N) # gamma+
                Omega2 =-(w0 - wn) - (4 *a*(m - (1/2)))/(np.sqrt(N)) #Omega-
                gamma2 =  np.sqrt( (Omega2**2 /4)+ (4*a**2 * r2**2)/N)#gamma-
                A1     = np.cos(gamma1*t) 
                B1     = np.sin(gamma1*t)            
                A2     = np.cos(gamma2*t) 
                B2     = np.sin(gamma2*t)
                C = np.exp(-m*U*wn)
                H12   = C * (A1 - 1j*B1*Omega1/(2*gamma1)) * ((A2 +1j*B2*Omega2/(2*gamma2))
                H2 = r2**2 * B2**2 * ((4*a**2)/ (gamma2**2 * N))
                H1 = A1**2 + B1**2 *((Omega1**2)/ (4 * gamma1**2))
                H11 = C * ((p11*H1) + (p22*H2))
                roh11 = roh11+H11
                roh12 = roh12 + H12
            roh2= roh2 +roh12*Nj
            roh1 = roh1 + roh11*Nj
        Roh12 = roh2*D *p12*np.exp(1j*(w0-wn)*t)
        Roh11 = roh1 *D
        q12.append(Roh12)
        f11.append(Roh11)

0 个答案:

没有答案