Пример #1
0
def set_transmission_coefficient(rayon):
    # change le coefficient de transmission des points de transmissions du rayon
    points_transmissions = rayon.get_points_transmission()

    for pt_trans in points_transmissions:
        mur = pt_trans.mur
        alpha = mur.alpha
        beta = mur.beta
        gamma = complex(alpha, beta)

        if (pt_trans.direction != None):
            direction = abs(pt_trans.direction)
        else:
            direction = None

        theta_i = get_theta_i(direction, pt_trans)
        theta_t = get_theta_t(theta_i, mur.epsilon)
        s = get_s(theta_t, mur.epaisseur)
        Z1 = sqrt(UO / EPS_0)
        Z2 = sqrt(UO / mur.epsilon)
        r = get_reflexion_perpendiculaire(Z1, Z2, theta_i, theta_t)

        num = (1 - pow(r, 2)) * cexp(-gamma * s)
        den = 1 - (pow(r, 2) *
                   cexp((-2 * gamma * s) +
                        (gamma * 2 * s * sin(theta_t) * sin(theta_i))))

        coeff_abs = polar(num / den)[0]  #module
        pt_trans.set_coefficient_value(coeff_abs)
Пример #2
0
def set_reflexion_coefficient(rayon):

    #effectue le calcul des coefficients de reflexion

    points_reflexion = rayon.get_points_reflexions()
    
    for pt_reflexion in points_reflexion:
        mur = pt_reflexion.mur
        alpha = mur.alpha
        beta = mur.beta
        gamma = complex(alpha,beta)
        if(pt_reflexion.direction != None):
            direction = abs(pt_reflexion.direction)
        else: 
            direction = None
        theta_i = get_theta_i(direction,pt_reflexion)
        theta_t = get_theta_t(theta_i,mur.epsilon)
        s = get_s(theta_t,mur.epaisseur)
        Z1 = sqrt(UO/EPS_0)
        Z2 = sqrt(UO/mur.epsilon)
        r = get_reflexion_perpendiculaire(Z1,Z2,theta_i,theta_t)
        num = (1-pow(r,2))* r *cexp(-2*gamma*s)*cexp(2*gamma*s*sin(theta_t)*sin(theta_i))
        den = 1-(pow(r,2)*cexp((-2*gamma*s)+(gamma*2*s*sin(theta_t)*sin(theta_i))))
        coeff_abs = polar(r + num/den)[0]  #module
        pt_reflexion.set_coefficient_value(coeff_abs)
Пример #3
0
def integrant(t, delG, lamT, delr, expn, etal):

    npol = len(expn)
    gt = (1.J*(delG+lamT)+delr)*t  \
           + sum(etal[k]/expn[k] for k in xrange(npol))*t \
           - sum(etal[k]/expn[k]**2*(1-cexp(-expn[k]*t)) for k in xrange(npol))
    result = cexp(-gt).real
    return result
Пример #4
0
 def _get_coordonnees(self):
     k = self.__rapport
     a = self.__angle.radian
     zA = self.__point1.z
     zB = self.__point2.z
     zE = k*cexp(1j*a)*(zB - zA) + zA
     print "HHeLiBeBCNOFNe", k*cexp(1j*a), (zB - zA), zA, zE
     return zE.real, zE.imag
Пример #5
0
 def _get_coordonnees(self):
     k = self.__rapport
     a = self.__angle.radian
     zA = self.__point1.z
     zB = self.__point2.z
     zE = k * cexp(1j * a) * (zB - zA) + zA
     print "HHeLiBeBCNOFNe", k * cexp(1j * a), (zB - zA), zA, zE
     return zE.real, zE.imag
Пример #6
0
def pyget_su2():
    phi = asin(sqrt(random()))
    psi = random() * 2 * pi
    chi = random() * 2 * pi
    return np.matrix(
        [[cexp(1j * psi) * cos(phi),
          cexp(1j * chi) * sin(phi)],
         [-1 * cexp(-1j * chi) * sin(phi),
          cexp(-1j * psi) * cos(phi)]],
        dtype=np.complex_)
Пример #7
0
 def transmission(self, energy):
     k = np.sqrt(2 * self.m * (energy - self.v)) / self.hbar * self.dx
     matrix = np.identity(2, dtype=np.complex)
     for n in range(0, len(self.v) - 1):
         if k[n] == 0:
             continue
         t = np.zeros((2, 2), dtype=np.complex)
         t[0, 0] = (k[n] + k[n + 1]) / 2 / k[n] * cexp(-1j * k[n])
         t[0, 1] = (k[n] - k[n + 1]) / 2 / k[n] * cexp(-1j * k[n])
         t[1, 0] = (k[n] - k[n + 1]) / 2 / k[n] * cexp(1j * k[n])
         t[1, 1] = (k[n] + k[n + 1]) / 2 / k[n] * cexp(1j * k[n])
         matrix = np.dot(matrix, t)
     return matrix[0][0].__abs__()**-2
Пример #8
0
def blit(frequency, sharpness=1.0, shift=0.0, phase=0.0, srate=None):
    srate = get_srate(srate)
    nyquist = 0.5 * srate
    l = len(frequency)
    sharpness = to_sequence(sharpness, l)
    frequency_shift = to_sequence(shift, l)
    fs = (s * f for s, f in zip(frequency_shift, frequency))
    phase_shift = to_iterable(phase)
    phase = integrate_gen(frequency, srate=srate)
    frequency_shift_phase = integrate_gen(fs, srate=srate)
    zs = (s * cexp(two_pi_j * p) for p, s in zip(phase, sharpness))
    ms = (cexp(two_pi_j * (p + theta)) for p, theta in zip(frequency_shift_phase, phase_shift))
    return [(m * z * constant_series_n_mu(z, nyquist / f - 1 - fs)).real / s for z, m, f, s, fs in zip(zs, ms, frequency, sharpness, frequency_shift)]
Пример #9
0
def Z(beta):
    n = 30
    q = 2
    J1 = -2
    J2 = -1

    v1 = cexp(J1*beta)-1
    v2 = cexp(J2*beta)-1
    
    f = v2+q
    Z1 = q*v1 + q**2
    Z2 = q**2*v1**2 + q**2*v2**2 + q*v1**2*v2**2 + 2*q*v1*v2**2 + 2*q*v2*v1**2 + 4*v1*v2*q**2 + 2*v1*q**3 + 2*v2*q**3 + q**4

    zx = (-3*v1**2*v2**2*f**2*Z1-3*v1**3*v2**3*f*Z1-v1**3*v2**3*Z1-3*v1**3*v2**4*Z1+v1**2*v2**2*Z2-3*v1**4*v2**4*Z1+f**4*Z2-f**6*Z1-3*v1**3*v2**4*f**2*Z1-3*v1**2*v2**3*f**2*Z1-4*v1**3*v2**3*f**3*Z1+2*v1**2*v2**3*Z2+2*v1**3*v2**3*Z2-3*v1**3*v2**5*Z1-6*v1**4*v2**5*Z1-3*v1**5*v2**5*Z1+v1**2*v2**4*Z2+2*v1**3*v2**4*Z2-v1**3*v2**6*Z1-3*v1**4*v2**6*Z1-3*v1**5*v2**6*Z1+v1**4*v2**4*Z2-v1**6*v2**6*Z1-3*v1**4*v2**4*f**2*Z1+v1**2*v2**2*f**2*Z2-6*v1**3*v2**3*f**2*Z1-3*v1**2*v2**2*f**4*Z1+2*v1*v2*Z2*f**2+2*v1**2*v2**2*Z2*f-6*v1**3*v2**4*Z1*f-6*v1**4*v2**4*Z1*f+2*v1**2*v2**3*Z2*f-3*v1**3*v2**5*Z1*f-6*v1**4*v2**5*Z1*f+2*v1**3*v2**3*Z2*f-3*v1**5*v2**5*Z1*f-3*f**4*v1*v2*Z1-6*f**3*v1**2*v2**2*Z1-3*f**5*v1*v2*Z1-3*f**3*v1**2*v2**3*Z1+2*v1*v2*f**3*Z2-2*v1**2*v2**3*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**3*v2**3*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1**4*v2**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**2*v2**2*f**2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1*v2**2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1*v2**2*f**2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*f**2*v1*v2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1**2*v2**2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1*v2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1**2*v2**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**3*v2**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-f**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**2*v2**3*f*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**3*v2**3*f*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*f**3*v1*v2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1**2*v2**2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**2*v2**2*f*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1*v2*f*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+f**2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4))*(-(2*v1*v2**2*f**2+2*v1**2*v2**2*f**2)/(-v1*v2*f-v1*v2**2-f**2-v1*v2-v1**2*v2**2-sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)))**n/(sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)*v1*v2**2*f**2*(1+v1)*(-v1*v2*f-v1*v2**2-f**2-v1*v2-v1**2*v2**2-sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)))+(3*v1**2*v2**2*f**2*Z1+3*v1**3*v2**3*f*Z1+v1**3*v2**3*Z1+3*v1**3*v2**4*Z1-v1**2*v2**2*Z2+3*v1**4*v2**4*Z1-f**4*Z2+f**6*Z1+3*v1**3*v2**4*f**2*Z1+3*v1**2*v2**3*f**2*Z1+4*v1**3*v2**3*f**3*Z1-2*v1**2*v2**3*Z2-2*v1**3*v2**3*Z2+3*v1**3*v2**5*Z1+6*v1**4*v2**5*Z1+3*v1**5*v2**5*Z1-v1**2*v2**4*Z2-2*v1**3*v2**4*Z2+v1**3*v2**6*Z1+3*v1**4*v2**6*Z1+3*v1**5*v2**6*Z1-v1**4*v2**4*Z2+v1**6*v2**6*Z1+3*v1**4*v2**4*f**2*Z1-v1**2*v2**2*f**2*Z2+6*v1**3*v2**3*f**2*Z1+3*v1**2*v2**2*f**4*Z1-2*v1*v2*Z2*f**2-2*v1**2*v2**2*Z2*f+6*v1**3*v2**4*Z1*f+6*v1**4*v2**4*Z1*f-2*v1**2*v2**3*Z2*f+3*v1**3*v2**5*Z1*f+6*v1**4*v2**5*Z1*f-2*v1**3*v2**3*Z2*f+3*v1**5*v2**5*Z1*f+3*f**4*v1*v2*Z1+6*f**3*v1**2*v2**2*Z1+3*f**5*v1*v2*Z1+3*f**3*v1**2*v2**3*Z1-2*v1*v2*f**3*Z2-2*v1**2*v2**3*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**3*v2**3*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1**4*v2**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**2*v2**2*f**2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1*v2**2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1*v2**2*f**2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*f**2*v1*v2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1**2*v2**2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1*v2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-v1**2*v2**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**3*v2**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-f**4*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**2*v2**3*f*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**3*v2**3*f*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*f**3*v1*v2*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1**2*v2**2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)-2*v1**2*v2**2*f*Z1*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+v1*v2*f*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)+f**2*Z2*sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4))*(-(2*v1*v2**2*f**2+2*v1**2*v2**2*f**2)/(-f**2-v1*v2-v1*v2*f-v1*v2**2-v1**2*v2**2+sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)))**n/(sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)*v1*v2**2*f**2*(1+v1)*(-f**2-v1*v2-v1*v2*f-v1*v2**2-v1**2*v2**2+sqrt(2*f**2*v1*v2+2*f**3*v1*v2+2*v1**2*v2**2*f+2*v1**2*v2**3*f+2*v1**3*v2**3*f-2*v1*v2**2*f**2-v1**2*v2**2*f**2+v1**2*v2**2+f**4+2*v1**2*v2**3+2*v1**3*v2**3+v1**2*v2**4+v1**4*v2**4+2*v1**3*v2**4)))
    return zx
Пример #10
0
def Z(beta):
    n = 200
    q = 2
    J1 = -1
    v1 = cexp(J1*beta)-1
    zx = q*(v1+q)**(n-1)
    return zx
def build_state_vector(populated, ns):
    """
    Return a 1D np.array of complex of length 2 * ns, which represents a ket of
    a normalised state, with the `populated` motional levels populated in equal
    amounts.  For example,
        build_state_vector([0, (2, 'e', 0.5), 3], 5)
    will produce
        array([0, 0, i/sqrt(3), 0, 0, 1/sqrt(3), 0, 0, 1/sqrt(3), 0]).
              |-------excited-------|------------ground------------|

    Arguments:
    populated: 1D list of state_specifier --
        The states to be populated in equal amounts in the output state.
        
    ns: unsigned int --
        The number of motional levels which are being considered.  The output
        vector will have length `2 * ns`.
    """
    assert len(populated) > 0,\
        "There must be at least one populated motional state."
    out = np.zeros(2 * ns, dtype=np.complex128)
    n = 1.0 / sqrt(len(populated))
    for ss in populated:
        out[state.idx(ss, ns)] = cexp(1.0j * pi * state.phase(ss)) * n
    return out
Пример #12
0
 def _get_coordonnees(self):
     k = self.__rapport
     a = self.__angle.radian
     zA = self.__point1.z
     zB = self.__point2.z
     zE = k*cexp(1j*a)*(zB - zA) + zA
     return zE.real, zE.imag
Пример #13
0
def random_image(kernel, xmi, xma, ymi, yma, log_scale_min, log_scale_max,
                 log_lambda_min, log_lambda_max, log_julia_min, log_julia_max):

    scale = 10**rnd.uniform(log_scale_min, log_scale_max)
    xc = rnd.uniform(xmi, xma)
    yc = rnd.uniform(ymi, yma)
    xmin = xc - scale / 2
    ymax = yc + scale / 2
    nx = 1000
    ny = 1000
    xstride = scale / nx
    ystride = scale / ny
    topleft = nb.complex128(xmin + 1j * ymax)
    rot = rnd.uniform(0, 360)
    max_iter = 1000
    lambd = 10**rnd.uniform(log_lambda_min, log_lambda_max)
    julia = lambd * 10 * rnd.uniform(log_julia_min, log_julia_max) * cexp(
        1j * rnd.uniform(0, 360))

    image_array = np.zeros((ny, nx), dtype=np.uint16)
    run_kernel(kernel, image_array, topleft, xstride, ystride, max_iter, lambd,
               julia, rot)

    print(xc, yc, scale, lambd, abs(julia))
    return image_array
Пример #14
0
def Z(beta):
    n = 200
    q = 2
    J1 = -1
    v1 = cexp(J1 * beta) - 1
    zx = q * (v1 + q)**(n - 1)
    return zx
def build_state_vector(populated, ns):
    """
    Return a 1D np.array of complex of length 2 * ns, which represents a ket of
    a normalised state, with the `populated` motional levels populated in equal
    amounts.  For example,
        build_state_vector([0, (2, 'e', 0.5), 3], 5)
    will produce
        array([0, 0, i/sqrt(3), 0, 0, 1/sqrt(3), 0, 0, 1/sqrt(3), 0]).
              |-------excited-------|------------ground------------|

    Arguments:
    populated: 1D list of state_specifier --
        The states to be populated in equal amounts in the output state.
        
    ns: unsigned int --
        The number of motional levels which are being considered.  The output
        vector will have length `2 * ns`.
    """
    assert len(populated) > 0,\
        "There must be at least one populated motional state."
    out = np.zeros(2 * ns, dtype = np.complex128)
    n = 1.0 / sqrt(len(populated))
    for ss in populated:
        out[state.idx(ss, ns)] = cexp(1.0j * pi * state.phase(ss)) * n
    return out
Пример #16
0
def fBose (x,pole,resi,rn,tn,sign=0):
    if sign == 0:
        return 1/x+0.5+rn*x+tn*x**3+sum(2.0*resi[i]*x/(x**2+pole[i]**2) for i in xrange(len(pole)))
    else:
        if isinstance(x,complex):
            return 1.0/(1-cexp(-x))
        else:
            return 1.0/(1-exp(-x))
Пример #17
0
 def sphHar(l, m, cosTheta, phi):
     m1 = abs(m)
     c = sqrt(
         (2 * l + 1) * gamma(l - m1 + 1.) / (4 * pi * gamma(l + m1 + 1.)))
     c *= legendre(l, m1, cosTheta)
     y = cexp(m * phi * 1j)
     if fmod(m, 2) == -1.:
         y *= -1
     return y * c + 0j
 def __update_distance_phase_derivatives(self):
     pref = 2.0 / math.sqrt(len(self.target))
     u_start = np.dot(self.__u, self.start)
     for i, pre_phase in enumerate(self.__phases):
         phase = cexp(1.0j * math.pi * (0.5 - pre_phase))
         # we can calculate the inner product <g n_j|U|start> by
         # precalculating U|start>, then indexing to the relevant element.
         idx = state.idx(self.target[i + 1], self.ns)
         self.__d_dist_phases[i] =\
             pref * (phase * u_start[idx] * np.conj(self.__tus)).real
Пример #19
0
 def _get_coordonnees(self):
     a = self.__angle.radian
     zA = self.__sommet_principal.z
     zB = self.__point2.z
     if contexte['exact'] and issympy(a, zA, zB):
         zC = (zB - zA)*sexp(1j*a) + zA
         return zC.expand(complex=True).as_real_imag()
     else:
         zC = (zB - zA)*cexp(1j*a) + zA
         return zC.real, zC.imag
Пример #20
0
 def _get_coordonnees(self):
     a = self.__angle.radian
     zA = self.__sommet_principal.z
     zB = self.__point2.z
     if contexte['exact'] and issympy(a, zA, zB):
         zC = (zB - zA) * sexp(1j * a) + zA
         return zC.expand(complex=True).as_real_imag()
     else:
         zC = (zB - zA) * cexp(1j * a) + zA
         return zC.real, zC.imag
Пример #21
0
 def _get_coordonnees(self):
     a = self.__angle.radian
     zA = self.__point1.z
     zB = self.__point2.z
     zI = (zA + zB)/2
     if contexte['exact'] and issympy(a, zI):
         zC = (zB - zI)*sexp(I*2*a) + zI
         return zC.expand(complex=True).as_real_imag()
     else:
         zC = (zB - zI)*cexp(1j*2*a) + zI
         return zC.real, zC.imag
Пример #22
0
 def _get_coordonnees(self):
     a = self.__angle.radian
     zA = self.__point1.z
     zB = self.__point2.z
     zI = (zA + zB) / 2
     if contexte['exact'] and issympy(a, zI):
         zC = (zB - zI) * sexp(I * 2 * a) + zI
         return zC.expand(complex=True).as_real_imag()
     else:
         zC = (zB - zI) * cexp(1j * 2 * a) + zI
         return zC.real, zC.imag
Пример #23
0
def GammaComplex(z):
    z = complex(z)
    if z.real < 0.5:
        return pi / (csin(pi*z)*GammaComplex(1-z))
    else:
        z -= 1
        x = lanczos_coef[0] + \
            sum(lanczos_coef[i]/(z+i)
                for i in range(1, g+2))
        t = z + g + 0.5
        return csqrt(2*pi) * t**(z+0.5) * cexp(-t) * x
Пример #24
0
    def set_value(self, value):
        """Set Dial needle to point at the given value."""

        if value is None:
            value = self.min
        # only perform an update if the value has changed
        # -----------------------------------------------
        if self.value != value:
            self.value = value
            angle = (value - self.min) * (self.end - self.start) / (self.max - self.min) + self.start

            # if dial is bound, check if value is out of bounds
            # -------------------------------------------------
            self.outofbounds = False
            if self.bound:
                if self.min < self.max:  # scale is increasing (1,2,3,...)
                    if value < self.min:
                        angle = self.start
                        self.outofbounds = True
                    elif value > self.max:
                        angle = self.end
                        self.outofbounds = True
                else:  # scale is decreasing (3,2,1,...)
                    if value > self.min:
                        angle = self.start
                        self.outofbounds = True
                    elif value < self.max:
                        angle = self.end
                        self.outofbounds = True

            # rotate needle (via complex numbers)
            # for more info on algorithm see:
            # http://www.effbot.org/zone/tkinter-complex-canvas.htm
            # -----------------------------------------------------
            newxy = []
            offset = complex(self.xm, self.ym)
            for x, y in self.needlecoords:
                v = cexp(math.radians(-angle) * 1j) * (complex(x, y) - offset) + offset
                newxy.append(v.real)
                newxy.append(v.imag)
            self.coords(self.needle, *newxy)

            # update the readout display (if enabled)
            # ---------------------------------------
            if self.display:
                if self.displayroundto > 0:
                    displayvalue = round(value, self.displayroundto)
                else:
                    displayvalue = int(round(value))
                displaycolor = self.displaycolor[self.outofbounds]
                self.itemconfig(self.display, text=displayvalue, fill=displaycolor)
Пример #25
0
def rfft(x):
    N = len(x)
    if N <= 1:
        return x
    if N & (N - 1) != 0:
        raise ValueError("Only power of two lengths supported.")
    even = fft(x[0::2])
    odd =  fft(x[1::2])
    if N in _twiddle_factors:
        twiddle = _twiddle_factors[N]
    else:
        twiddle = [cexp(-2j * pi * k / N) for k in range(N // 2)]
        _twiddle_factors[N] = twiddle
    return [even[k] + twiddle[k] * odd[k] for k in range(N // 2)] + [even[0] - odd[0]]
Пример #26
0
def Lastovka_Shaw_Indefinite_Integral_Over_T(T, MW, similarity_variable, term):
    a = similarity_variable
    a2 = a * a
    B11 = 0.73917383
    B12 = 8.88308889
    C11 = 1188.28051
    C12 = 1813.04613
    B21 = 0.0483019
    B22 = 4.35656721
    C21 = 2897.01927
    C22 = 5987.80407
    S = (term * clog(T) +
         (-B11 - B12 * a) * clog(cexp((-C11 - C12 * a) / T) - 1.) +
         (-B11 * C11 - B11 * C12 * a - B12 * C11 * a - B12 * C12 * a2) /
         (T * cexp((-C11 - C12 * a) / T) - T) -
         (B11 * C11 + B11 * C12 * a + B12 * C11 * a + B12 * C12 * a2) / T)
    S += ((-B21 - B22 * a) * clog(cexp((-C21 - C22 * a) / T) - 1.) +
          (-B21 * C21 - B21 * C22 * a - B22 * C21 * a - B22 * C22 * a2) /
          (T * cexp((-C21 - C22 * a) / T) - T) -
          (B21 * C21 + B21 * C22 * a + B22 * C21 * a + B22 * C22 * a**2) / T)
    # There is a non-real component, but it is only a function of similariy
    # variable and so will always cancel out.
    return MW * S.real
Пример #27
0
def theta_formant(phase, ratio, width):
    """Formant waveform with energy concentrated on the fractional harmonic specified by ratio."""
    if width < epsilon:
        width = epsilon
    if width < 7:
        x = two_pi * phase
        q = exp(-pi_squared / width)
        q2 = q * q
        q4 = q2 * q2
        q8 = q4 * q4
        q9 = q8 * q
        q16 = q8 * q8
        q25 = q16 * q9
        norm = 1 + 2 * (q + q4 + q9 + q25)
        floor_ratio = floor(ratio)
        ratio -= floor_ratio
        cn = cos(x * (floor_ratio - 5))
        cn1 = cos(x * (floor_ratio - 4))
        c = cos(x)
        s = cn1 * q ** (4 + ratio) ** 2
        for n in range(-3, 5):
            cn1, cn = 2 * c * cn1 - cn, cn1
            s += cn1 * q ** (n - ratio) ** 2
        return s / norm
    elif width < 100:
        x = phase - floor(phase + 0.5)
        ratio *= two_pi
        z = from_polar(1, ratio * (x + 2))
        m = cexp(2 * width * x - 1j * ratio)
        b = exp(-width)
        b4 = b ** 4

        z0 = z.real
        z *= m
        z1 = z.real
        z *= m
        s = z.real
        z *= m
        s += (z.real + z1) * b
        z *= m
        s += (z.real + z0) * b4

        return exp(-width * x * (x + 4)) * s / (1 + 2 * (b + b4))
    else:
        x = phase - floor(phase + 0.5)
        return exp(-width * x * x) * cos(two_pi * x * ratio)
Пример #28
0
import multiprocessing
import numpy as np

from bitarray import bitarray
from cmath import exp as cexp #Differentiate from real-valued exp
from copy import deepcopy
from math import acos, cos, exp, sin, sqrt
from math import pow as fpow #Differentiate from stdlib pow
from random import randrange, random
from qutip import basis, sigmaz, tensor
from Utils import do_anneal, format_for_output, write_string

BETA = acos(1/sqrt(3)) /2
PI = acos(0.)*2
H = (cos(PI/8)*basis(2,0) + sin(PI/8)*basis(2,1)).unit()
F = (cos(BETA)*basis(2,0) + cexp(1j*PI/4)*sin(BETA)*basis(2,1)).unit()
PLUS = (basis(2,0)+basis(2,1)).unit()
S = sigmaz().sqrtm()
Tmat = S.sqrtm()
T = Tmat * PLUS
RT = Tmat.sqrtm() * PLUS
RRT = Tmat.sqrtm().sqrtm() * PLUS

STATES = {'T':T,
          'RT':RT,
          'RRT':RRT,
          'F':F,
          'H':H}

def run_analysis(state, n, chi):
    job = {'ostring': write_string,
Пример #29
0
 def oddtwiddles(self):
     # return a generator for odd-indexed twiddles
     freq = self.freq
     return (cexp(freq * n) for n in xrange(1, len(self.twiddles) * 2, 2))
Пример #30
0
    def calc(point_a, point_b, tangent_a, tangent_b, p, planar_tolerance=1e-6):
        xx = point_b - point_a
        xx /= np.linalg.norm(xx)
        tangent_normal = np.cross(tangent_a, tangent_b)
        volume = np.dot(xx, tangent_normal)
        if abs(volume) > planar_tolerance:
            raise Exception(
                f"Provided tangents are not coplanar, volume={volume}")

        zz_a = np.cross(tangent_a, xx)
        zz_b = np.cross(tangent_b, xx)
        zz = (zz_a + zz_b)
        zz /= np.linalg.norm(zz)
        yy = np.cross(zz, xx)

        c = np.linalg.norm(point_b - point_a) * 0.5

        tangent_a /= np.linalg.norm(tangent_a)
        tangent_b /= np.linalg.norm(tangent_b)

        to_center_a = np.cross(zz, tangent_a)
        to_center_b = -np.cross(zz, tangent_b)

        matrix_inv = np.stack((xx, yy, zz))
        matrix = np.linalg.inv(matrix_inv)

        # TODO: sin(arccos(...)) = ...
        alpha = acos(np.dot(tangent_a, xx))
        beta = acos(np.dot(tangent_b, xx))
        if np.dot(tangent_a, yy) > 0:
            alpha = -alpha
        if np.dot(tangent_b, yy) > 0:
            beta = -beta
        #print("A", alpha, "B", beta)

        omega = (alpha + beta) * 0.5
        r1 = c / (sin(alpha) + sin(omega) / p)
        r2 = c / (sin(beta) + p * sin(omega))
        #print("R1", r1, "R2", r2)
        theta1 = 2 * arg(cexp(-1j * alpha) + cexp(-1j * omega) / p)
        theta2 = 2 * arg(cexp(1j * beta) + p * cexp(1j * omega))
        #print("T1", theta1, "T2", theta2)

        vectorx_a = r1 * to_center_a
        center1 = point_a + vectorx_a
        center2 = point_b + r2 * to_center_b

        arc1 = SvCircle(  #radius = r1,
            center=center1,
            normal=-zz,
            vectorx=point_a - center1)
        if theta1 > 0:
            arc1.u_bounds = (0.0, theta1)
        else:
            theta1 = -theta1
            arc1.u_bounds = (0.0, theta1)
            arc1.set_normal(-arc1.normal)

        junction = arc1.evaluate(theta1)
        #print("J", junction)

        arc2 = SvCircle(  #radius = r2,
            center=center2,
            normal=-zz,
            vectorx=junction - center2)
        if theta2 > 0:
            arc2.u_bounds = (0.0, theta2)
        else:
            theta2 = -theta2
            arc2.u_bounds = (0.0, theta2)
            arc2.set_normal(-arc2.normal)

        curve = SvBiArc(arc1, arc2)
        curve.p = p
        curve.junction = junction

        return curve
Пример #31
0
def simple_electric_piano(note):
    time_ = time(note.duration + 1)
    zs = [cexp(2j * pi * f * t) for t, f in zip(time_, note.get_frequency_gen())]
    zs = [(0.1 * z * cexp(0.9 * exp(-t * 2) * z) + 0.025 * z ** 5 * constant_series(0.8 * exp(-t * 10) * z ** 2)) * (1 + tanh((note.duration - t) * 20)) * tanh(t * 200) for t, z in zip(time_, zs)]
    return [z.real for z in zs]
Пример #32
0
def reference_splitradix_fft(x):
    """
    A very simple refernce implementation of the decimate in time FFT
    algorithm for the DFT.

    The length of the (possibly complex) array must be a power of two.

    >>> def scale_it(array): return tuple(int(round(abs(item) * 1000)) for item in array)

    >>> reference_splitradix_fft([])
    ()

    >>> reference_splitradix_fft([1])
    (1,)

    >>> scale_it(reference_splitradix_fft([1] * 2))
    (2000, 0)

    >>> scale_it(reference_splitradix_fft([1] * 2 + [0] * 2))
    (2000, 1414, 0, 1414)

    >>> scale_it(reference_splitradix_fft([1] * 2 + [complex(0,1)] * 2 + [0] * (32 - 4)))
    (2828, 3310, 3625, 3754, 3696, 3460, 3073, 2571, 2000, 1410, 850, 368, 0, 227, 299, 218, 0, 326, 721, 1139, 1531, 1849, 2053, 2110, 2000, 1718, 1273, 688, 0, 747, 1501, 2212)

    >>> scale_it(reference_splitradix_fft([1] * 1 + [0] * (16 - 1)))
    (1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000)

    >>> scale_it(reference_splitradix_fft([1] * 8 + [0] * (32 - 8)))
    (8000, 7214, 5126, 2436, 0, 1500, 1800, 1115, 0, 915, 1203, 802, 0, 739, 1020, 711, 0, 711, 1020, 739, 0, 802, 1203, 915, 0, 1115, 1800, 1500, 0, 2436, 5126, 7214)

    >>> scale_it(reference_splitradix_fft(sin(2 * PI * n * 3 / 32) for n in xrange(32)))
    (0, 0, 0, 16000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16000, 0, 0)

    >>> scale_it(reference_splitradix_fft([1] * 2 + [complex(0,1)] * 2 + [0] * (16 - 4)))
    (2828, 3625, 3696, 3073, 2000, 850, 0, 299, 0, 721, 1531, 2053, 2000, 1273, 0, 1501)

    >>> tuple(complex(int(round(x.real)), int(round(x.imag))) for x in fft([-1000] * 2 + [-1000j] * 2 + [0] * (16 - 4)))
    ((-2000-2000j), (-3555-707j), (-3414+1414j), (-1707+2555j), 2000j, (472+707j), 0j, (-293+58j), 0j, (141-707j), (-586-1414j), (-1707-1141j), (-2000+0j), (-1058+707j), 0j, (-293-1472j))


    >>> for i in xrange(8):
    ...   scale_it(reference_splitradix_fft(range(1 << i)))
    (0,)
    (1000, 1000)
    (6000, 2828, 2000, 2828)
    (28000, 10453, 5657, 4330, 4000, 4330, 5657, 10453)
    (120000, 41007, 20905, 14400, 11314, 9622, 8659, 8157, 8000, 8157, 8659, 9622, 11314, 14400, 20905, 41007)
    (496000, 163237, 82013, 55118, 41810, 33942, 28799, 25221, 22627, 20698, 19243, 18142, 17318, 16720, 16313, 16077, 16000, 16077, 16313, 16720, 17318, 18142, 19243, 20698, 22627, 25221, 28799, 33942, 41810, 55118, 82013, 163237)
    (2016000, 652161, 326474, 218087, 164027, 131698, 110237, 94987, 83620, 74844, 67883, 62244, 57598, 53718, 50442, 47650, 45255, 43188, 41397, 39840, 38486, 37308, 36284, 35399, 34637, 33987, 33440, 32989, 32627, 32350, 32155, 32039, 32000, 32039, 32155, 32350, 32627, 32989, 33440, 33987, 34637, 35399, 36284, 37308, 38486, 39840, 41397, 43188, 45255, 47650, 50442, 53718, 57598, 62244, 67883, 74844, 83620, 94987, 110237, 131698, 164027, 218087, 326474, 652161)
    (8128000, 2607856, 1304321, 869984, 652947, 522830, 436174, 374352, 328053, 292102, 263396, 239959, 220473, 204028, 189973, 177830, 167240, 157931, 149688, 142345, 135767, 129844, 124489, 119627, 115197, 111148, 107437, 104026, 100884, 97983, 95301, 92815, 90510, 88368, 86375, 84521, 82793, 81183, 79681, 78279, 76972, 75753, 74616, 73556, 72569, 71651, 70797, 70006, 69273, 68596, 67973, 67402, 66880, 66405, 65977, 65594, 65254, 64956, 64700, 64485, 64310, 64174, 64077, 64019, 64000, 64019, 64077, 64174, 64310, 64485, 64700, 64956, 65254, 65594, 65977, 66405, 66880, 67402, 67973, 68596, 69273, 70006, 70797, 71651, 72569, 73556, 74616, 75753, 76972, 78279, 79681, 81183, 82793, 84521, 86375, 88368, 90510, 92815, 95301, 97983, 100884, 104026, 107437, 111148, 115197, 119627, 124489, 129844, 135767, 142345, 149688, 157931, 167240, 177830, 189973, 204028, 220473, 239959, 263396, 292102, 328053, 374352, 436174, 522830, 652947, 869984, 1304321, 2607856)

    """

    x = tuple(x)
    if len(x) < 2:
        return x

    negtwopireciplength = -2j * PI / len(x)
    twiddles = tuple(cexp(n * negtwopireciplength) for n in xrange(3 * len(x) // 4))
    # twiddles = tuple(cexp(n * negtwopireciplength) for n in xrange(len(x)))    
    twiddler = partial(islice, twiddles, 0, None)

    def fft_recursive(xx, twiddle_stride):
        if len(xx) == 1:
            return xx
        evens = fft_recursive(xx[::2], twiddle_stride * 2)
        if len(evens) >= 4:
            # we can do the split radix work
            odds1 = fft_recursive(xx[1::4], 4 * twiddle_stride)
            odds3 = fft_recursive(xx[3::4], 4 * twiddle_stride)
            if len(odds1) != len(odds3):
                raise ValueError("expected a power of two, got len(x) %d" % (len(x),))

            twodds1 = tuple(twiddle * odd1 for twiddle, odd1 in izip(twiddler(twiddle_stride), odds1))
            twodds3 = tuple(twiddle * odd3 for twiddle, odd3 in izip(twiddler(3 * twiddle_stride), odds3))
            assert len(twodds1) == len(twodds3)

            twoddsums = tuple(twodd1 + twodd3 for twodd1, twodd3 in izip(twodds1, twodds3))
            jtwodddiffs = tuple(1j * (twodd1 - twodd3) for twodd1, twodd3 in izip(twodds1, twodds3))

            return tuple(chain((even + twoddsum for even, twoddsum in izip(evens, twoddsums)),
                               (even - jtwodddiff for even, jtwodddiff in izip(islice(evens, len(evens)//2, None), jtwodddiffs)),
                               (even - twoddsum for even, twoddsum in izip(evens, twoddsums)),
                               (even + jtwodddiff for even, jtwodddiff in izip(islice(evens, len(evens)//2, None), jtwodddiffs))))

        odds = fft_recursive(xx[1::2], twiddle_stride * 2)
        if len(evens) != len(odds):
            raise ValueError("expected a power of two, got len(x) %d" % (len(x),))

        twodds = tuple(twiddle * odd for twiddle, odd in izip(twiddler(twiddle_stride), odds))

        return tuple(chain((even + twodd for even, twodd in izip(evens, twodds)),
                           (even - twodd for even, twodd in izip(evens, twodds))))

    return fft_recursive(x, 1)
Пример #33
0
def u_wawe(z):
    return ((((e / m) * beta * gamma0**-3 * 0.5 * Eii *
              (-i * w + delta_w - i * kii * uii)) /
             ((-i * w + delta_w + kii * uii)**2 + Omega**2)) * 2 *
            cexp(i * kii * z)).real * 2
Пример #34
0
def extrapAndImaging(ns, nvel, nz, nextrap, nt, nw, nx, \
    dz, w, kx, vel_model, pulse_forw_fs, pulse_back_fs, \
    path_to_output):

    image = np.zeros(shape=(ns, nz, nx), dtype=np.float32)

    # proagating wavefields for all reference velocities, shots, and pulses
    ref_channel_forw = np.zeros(shape=(ns, nvel, nw, nx), dtype=np.complex64)
    ref_channel_back = np.zeros(shape=(ns, nvel, nw, nx), dtype=np.complex64)

    for l in range(nextrap):

        vmin = np.min(vel_model[l, :])
        vmax = np.max(vel_model[l, :])
        dvel = (vmax - vmin) / (nvel - 1)
        refVel = np.array([vmin + i * dvel for i in range(nvel)])

        # savefigures for more in-depth analysis and/or debug
        depth = round((l + 1) * dz, 1)
        print("  - depth:", depth, "refvel:", refVel)
        if l == 0 or l % 10 == 0:
            sIdx = 2  # just a hard-coded choice (index)
            filenameForw = path_to_output + "/forw_s" + str(
                sIdx) + "_depth" + str(depth) + "_.png"
            filenameBack = path_to_output + "/back_s" + str(
                sIdx) + "_depth" + str(depth) + "_.png"
            filenameImage = path_to_output + "/image_s" + str(
                sIdx) + "_depth" + str(depth) + "_.png"
            plotWavefield(pulse_forw_fs[sIdx, :, :], filenameForw)
            plotWavefield(pulse_back_fs[sIdx, :, :], filenameBack)
            plotImage(image[sIdx, :, :], filenameImage)

        # Phase-shift in f-x domain
        for j in range(nw):
            for i in range(nx):
                u = vel_model[l, i]
                k = w[j] / u
                Q1 = cexp(-1j * k * dz)
                Q2 = cexp(+1j * k * dz)
                for s in range(ns):
                    pulse_forw_fs[s, j, i] *= Q1
                    pulse_back_fs[s, j, i] *= Q2

        # FFT -> f-kx domain
        for s in range(ns):
            pulse_forw_fs[s, :, :] = spfft.fft(pulse_forw_fs[s, :, :], axis=1)
            pulse_back_fs[s, :, :] = spfft.fft(pulse_back_fs[s, :, :], axis=1)

        # Propagate with all reference velocities in f-kx domain
        for j in range(nw):
            for i in range(nx):
                for n in range(nvel):
                    k = w[j] / refVel[n]
                    if np.abs(k) > np.abs(kx[i]):
                        kz = +np.sqrt(k**2 - kx[i]**2)
                        Q1 = cexp(-1j * (kz - k) * dz)
                        Q2 = cexp(+1j * (kz - k) * dz)
                        for s in range(ns):
                            ref_channel_forw[s, n, j,
                                             i] = pulse_forw_fs[s, j, i] * Q1
                            ref_channel_back[s, n, j,
                                             i] = pulse_back_fs[s, j, i] * Q2

        # IFFT -> f-x domain
        for s in range(ns):
            for n in range(nvel):
                ref_channel_forw[s, n, :, :] = spfft.ifft(
                    ref_channel_forw[s, n, :, :], axis=1)
                ref_channel_back[s, n, :, :] = spfft.ifft(
                    ref_channel_back[s, n, :, :], axis=1)

        # Find coefficients for interpolation and then normalize them
        coeff = find_coeff(vel_model[l, :], refVel)
        coeff = norm_coefficients(coeff)

        # Interpolation
        pulse_forw_fs[:, :, :] = 0
        pulse_back_fs[:, :, :] = 0
        for s in range(ns):
            for i in range(nx):
                for n in range(nvel):
                    pulse_forw_fs[s, :,
                                  i] += coeff[i, n] * ref_channel_forw[s, n, :,
                                                                       i]
                    pulse_back_fs[s, :,
                                  i] += coeff[i, n] * ref_channel_back[s, n, :,
                                                                       i]

        # Imaging condition (cross-correlation)
        for s in range(ns):
            image[s,l,:] = np.add.reduce( (pulse_forw_fs[s,:,:] * \
                np.conj(pulse_back_fs[s,:,:]) ).real, axis=0)

    return image
Пример #35
0
"""Module to hold useful matrices"""

from cmath import exp as cexp
from math import pi, sqrt

from .haar_random import get_so2, get_su2
from .py_haar_random import pyget_su2

import numpy as np

__all__ = ['qeye', 'X', 'Y', 'Z', 'S', 'H', 'T']


def qeye(n):
    return np.eye(n, dtype=np.complex_)


X = np.matrix([[0, 1], [1, 0]], dtype=np.complex_)

Y = np.matrix([[0, -1j], [1j, 0]], dtype=np.complex_)

Z = np.matrix([[1, 0], [0, -1]], dtype=np.complex_)

H = (1 / sqrt(2.)) * np.matrix([[1, 1], [1, -1]], dtype=np.complex_)

S = np.matrix([[1, 0], [0, 1j]], dtype=np.complex_)

T = np.matrix([[1, 0], [0, cexp(1j * pi / 4)]], dtype=np.complex_)
Пример #36
0
    return np.eye(n, dtype=np.complex_)


Id = np.eye(2, dtype=np.complex_)

X = np.matrix([[0, 1], [1, 0]], dtype=np.complex_)

Y = np.matrix([[0, -1j], [1j, 0]], dtype=np.complex_)

Z = np.matrix([[1, 0], [0, -1]], dtype=np.complex_)

H = (1 / sqrt(2.)) * np.matrix([[1, 1], [1, -1]], dtype=np.complex_)

S = np.matrix([[1, 0], [0, 1j]], dtype=np.complex_)

T = np.matrix([[1, 0], [0, cexp(1j * pi / 4)]], dtype=np.complex_)

ROOT_T = np.matrix([[1, 0], [0, cexp(1j * pi / 8)]], dtype=np.complex_)

ROOT_ROOT_T = np.matrix([[1, 0], [0, cexp(1j * pi / 16)]], dtype=np.complex_)

CS = np.matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1j]],
               dtype=np.complex_)

CCZ = np.matrix([[1, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0],
                 [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0],
                 [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0],
                 [0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, -1]],
                dtype=np.complex_)

Пример #37
0
import numpy as np
import qutip as qt

from cmath import exp as cexp
from itertools import product, combinations
from math import acos, cos, sin, sqrt
from Utils import SL0, n_stab

## Magic state definitions
pi = 2*acos(0.)
beta = acos(1/sqrt(3)) / 2
I, X, Y, Z = qt.qeye(2), qt.sigmax(), qt.sigmay(), qt.sigmaz()
H = (cos(pi/8)*qt.basis(2,0)+sin(pi/8)*qt.basis(2,1)).unit()
F = (cos(beta)*qt.basis(2,0) + cexp(1j*pi/4)*sin(beta)*qt.basis(2,1)).unit()
plus = (qt.basis(2,0)+qt.basis(2,1)).unit()
S = Z.sqrtm()
T = S.sqrtm()
magic_states = [H, S*H, Z*H, S.dag()*H, X*H, S*X*H, Z*X*H, S.dag()*X*H, T*plus,
                S*T*plus, S.dag()*T.dag()*plus,T.dag()*plus]
face_states = [F]# S*F, Z*F, S.dag()*F, X*F, S*X*F, S*Z*F, S.dag()*X*F]

##

## Helpful funcitons
def commutator(A,B):
    return A*B - B*A

def test_equality(g1,g2):
    return all([any([np.allclose(_g1, _g2) for _g2 in g2]) for _g1 in g1])

def projector(group):
Пример #38
0
def init(inidic):

    try:
        exbe = inidic['exbe']
    except:
        exbe = 0

    npsd = inidic['npsd']
    pade = inidic['pade']
    temp = inidic['temp']
    jomg = inidic['jomg']
    nmod = len(jomg)

    nind = 0
    mode = []
    for m in xrange(nmod):
        try:
            ndru = len(jomg[m]['jdru'])
        except:
            ndru = 0
        try:
            nsdr = len(jomg[m]['jsdr'])
        except:
            nsdr = 0
        nper = ndru + 2 * nsdr + npsd
        nind += nper
        mode.extend([m for i in xrange(nper)])
    mode = np.array(mode)
    delr = np.zeros(nmod, dtype=float)
    expn = np.zeros(nind, dtype=complex)
    etal = np.zeros(nind, dtype=complex)
    etar = np.zeros(nind, dtype=complex)
    etaa = np.zeros(nind, dtype=float)

    pole, resi, rn, tn = PSD(npsd, BoseFermi=1, pade=pade)

    iind = 0

    for m in xrange(nmod):

        try:
            jdru = jomg[m]['jdru']
        except:
            jdru = []

        try:
            jsdr = jomg[m]['jsdr']
        except:
            jsdr = []

        ndru = len(jdru)
        nsdr = len(jsdr)

        for idru in xrange(ndru):

            if len(jdru[idru]) != 2:
                raise ValueError('Invalid drude input')

            lamd, gamd = jdru[idru][0], jdru[idru][1]
            expn[iind] = gamd
            etal[iind] = -2.J * lamd * gamd * fBose(-1.J * gamd / temp, pole,
                                                    resi, rn, tn, exbe)
            etar[iind] = etal[iind].conj()
            etaa[iind] = abs(etal[iind])
            delr[m] += 2. * lamd * gamd / temp * rn

            iind += 1

        for isdr in xrange(nsdr):

            if len(jsdr[isdr]) != 3:
                raise ValueError('Invalid BO input')

            lams, omgs, gams = jsdr[isdr][0], jsdr[isdr][1], jsdr[isdr][2]
            jind = iind + 1
            etaBO = 2. * lams * omgs * omgs * gams
            Delta = omgs * omgs - gams * gams / 4.0
            delr[m] += etaBO * tn / (temp**3)
            if Delta > 0:
                OmgB = sqrt(Delta)
                expn[iind] = 0.5 * gams + 1.J * OmgB
                expn[jind] = 0.5 * gams - 1.J * OmgB
            elif Delta < 0:
                OmgB = sqrt(-Delta)
                expn[iind] = 0.5 * gams + OmgB
                expn[jind] = 0.5 * gams - OmgB
            else:
                raise ValueError("Not prepared for Delta=0")
            z1, z2 = -1.J * expn[iind], -1.J * expn[jind]

            etal[iind] = -2.J * etaBO * z1 / (
                2. * z1 * (z1 + z2) *
                (z1 - z2)) * fBose(z1 / temp, pole, resi, rn, tn, exbe)
            etal[jind] = -2.J * etaBO * z2 / (
                2. * z2 * (z2 + z1) *
                (z2 - z1)) * fBose(z2 / temp, pole, resi, rn, tn, exbe)
            if Delta > 0:
                etar[iind] = etal[jind].conj()
                etar[jind] = etal[iind].conj()
                etaa[iind] = etaa[jind] = sqrt(
                    abs(etal[iind]) * abs(etal[jind]))
            elif Delta < 0:
                etar[iind] = etal[iind].conj()
                etar[jind] = etal[jind].conj()
                etaa[iind] = abs(etal[iind])
                etaa[jind] = abs(etal[jind])
            else:
                raise ValueError("Not prepared for Delta=0")

            iind += 2

        for ipsd in xrange(npsd):
            zomg = -1.J * pole[ipsd] * temp
            jsmd = sum(jwdru(zomg, x) for x in jdru)
            jsms = sum(jwsdr(zomg, x) for x in jsdr)
            jsum = jsmd + jsms
            expn[iind] = pole[ipsd] * temp
            etal[iind] = -2.J * resi[ipsd] * temp * jsum
            etar[iind] = etal[iind].conj()
            etaa[iind] = abs(etal[iind])

            iind += 1

    delr_img = delr
    mode_img = np.zeros(2 * nind, dtype=int)
    expn_img = np.zeros(2 * nind, dtype=complex)
    etal_img = np.zeros(2 * nind, dtype=complex)
    etar_img = np.zeros(2 * nind, dtype=complex)
    etaa_img = np.zeros(2 * nind, dtype=float)
    for i in xrange(nind):
        mode_img[2 * i] = mode_img[2 * i + 1] = mode[i]
        expn_img[2 * i] = expn[i]
        expn_img[2 * i + 1] = -expn[i]
        etal_img[2 * i] = 0.5 * etal[i]
        etal_img[2 * i + 1] = 0.5 * etal[i] * cexp(1.J * expn[i] / temp)
        etar_img[2 * i] = 0.5 * etar[i]
        etar_img[2 * i + 1] = 0.5 * etar[i] * cexp(-1.J * expn[i] / temp)
        etaa_img[2 * i] = etaa_img[2 * i + 1] = etaa[i] * 0.5

    arma.save(mode_img, inidic['modeFile'])
    arma.save(etal_img, inidic['etalFile'])
    arma.save(etar_img, inidic['etarFile'])
    arma.save(etaa_img, inidic['etaaFile'])
    arma.save(expn_img, inidic['expnFile'])
    arma.save(delr_img, inidic['delrFile'])

    return etal, expn
        seq.add_block(rf_td, gx_td, gz_td)

        # Read out block
        slice = iz
        ileaf = (
            ((iframe % fmri['nLeafs']) + iz) %
            fmri['nLeafs']) + 1  # rotate leaf every frame and every kz platter
        phi = 2 * pi * (ileaf -
                        1) / fmri['nLeafs']  # leaf rotation angle in radians

        # Rotate the spiral arm if necessary
        if phi != 0:
            g = np.zeros(gx_ro_wav_orig.shape, dtype=complex)
            for i in range(gx_ro_wav_orig.shape[0]):
                g[i] = complex(gx_ro_wav_orig[i], gy_ro_wav_orig[i])
                g[i] = g[i] * cexp(phi * 1j)
            gx_ro_wav = np.real(g)
            gy_ro_wav = np.imag(g)

        else:
            gx_ro_wav = gx_ro_wav_orig
            gy_ro_wav = gy_ro_wav_orig

        gx_ro = make_arbitrary_grad(channel='x',
                                    system=system,
                                    waveform=np.squeeze(gx_ro_wav))

        gy_ro = make_arbitrary_grad(channel='y',
                                    system=system,
                                    waveform=np.squeeze(gy_ro_wav))
Пример #40
0
import matplotlib.pylab as plt
import numpy as np
import pandas as pd
from scipy.stats import norm
import seaborn as sns
from math import cos, sin, log, tan, gamma, pi, exp, sqrt, cosh, sinh
from cmath import exp as cexp, log as clog
N = 7500
f = lambda n: n / 11 + n**2 / 21 + n**3 / 31
S = np.cumsum([cexp(f(n) * complex(0, 2 * pi)) for n in range(1, N)])

p = plt.figure(figsize=(14, 14), facecolor='black', dpi=100)
p = plt.axis('off')
for k in range(440):
    plt.ylim(-25, 35)
    plt.xlim(-40, 20)
    plt.plot([S[i].real for i in range(N - 1)][k * 20:(k + 1) * 20 + 1],
             [S[i].imag for i in range(N - 1)][k * 20:(k + 1) * 20 + 1],
             lw=1,
             color='w',
             alpha=0.8)
    p = plt.savefig(
        f'C:/Users/Alejandro/Pictures/RandomPlots/29022020/plot{k}.PNG',
        facecolor='black')
Пример #41
0
def reference_splitradix_fft(x):
    """
    A very simple refernce implementation of the decimate in time FFT
    algorithm for the DFT.

    The length of the (possibly complex) array must be a power of two.

    >>> def scale_it(array): return tuple(int(round(abs(item) * 1000)) for item in array)

    >>> reference_splitradix_fft([])
    ()

    >>> reference_splitradix_fft([1])
    (1,)

    >>> scale_it(reference_splitradix_fft([1] * 2))
    (2000, 0)

    >>> scale_it(reference_splitradix_fft([1] * 2 + [0] * 2))
    (2000, 1414, 0, 1414)

    >>> scale_it(reference_splitradix_fft([1] * 2 + [complex(0,1)] * 2 + [0] * (32 - 4)))
    (2828, 3310, 3625, 3754, 3696, 3460, 3073, 2571, 2000, 1410, 850, 368, 0, 227, 299, 218, 0, 326, 721, 1139, 1531, 1849, 2053, 2110, 2000, 1718, 1273, 688, 0, 747, 1501, 2212)

    >>> scale_it(reference_splitradix_fft([1] * 1 + [0] * (16 - 1)))
    (1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000)

    >>> scale_it(reference_splitradix_fft([1] * 8 + [0] * (32 - 8)))
    (8000, 7214, 5126, 2436, 0, 1500, 1800, 1115, 0, 915, 1203, 802, 0, 739, 1020, 711, 0, 711, 1020, 739, 0, 802, 1203, 915, 0, 1115, 1800, 1500, 0, 2436, 5126, 7214)

    >>> scale_it(reference_splitradix_fft(sin(2 * PI * n * 3 / 32) for n in xrange(32)))
    (0, 0, 0, 16000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16000, 0, 0)

    >>> scale_it(reference_splitradix_fft([1] * 2 + [complex(0,1)] * 2 + [0] * (16 - 4)))
    (2828, 3625, 3696, 3073, 2000, 850, 0, 299, 0, 721, 1531, 2053, 2000, 1273, 0, 1501)

    >>> tuple(complex(int(round(x.real)), int(round(x.imag))) for x in fft([-1000] * 2 + [-1000j] * 2 + [0] * (16 - 4)))
    ((-2000-2000j), (-3555-707j), (-3414+1414j), (-1707+2555j), 2000j, (472+707j), 0j, (-293+58j), 0j, (141-707j), (-586-1414j), (-1707-1141j), (-2000+0j), (-1058+707j), 0j, (-293-1472j))


    >>> for i in xrange(8):
    ...   scale_it(reference_splitradix_fft(range(1 << i)))
    (0,)
    (1000, 1000)
    (6000, 2828, 2000, 2828)
    (28000, 10453, 5657, 4330, 4000, 4330, 5657, 10453)
    (120000, 41007, 20905, 14400, 11314, 9622, 8659, 8157, 8000, 8157, 8659, 9622, 11314, 14400, 20905, 41007)
    (496000, 163237, 82013, 55118, 41810, 33942, 28799, 25221, 22627, 20698, 19243, 18142, 17318, 16720, 16313, 16077, 16000, 16077, 16313, 16720, 17318, 18142, 19243, 20698, 22627, 25221, 28799, 33942, 41810, 55118, 82013, 163237)
    (2016000, 652161, 326474, 218087, 164027, 131698, 110237, 94987, 83620, 74844, 67883, 62244, 57598, 53718, 50442, 47650, 45255, 43188, 41397, 39840, 38486, 37308, 36284, 35399, 34637, 33987, 33440, 32989, 32627, 32350, 32155, 32039, 32000, 32039, 32155, 32350, 32627, 32989, 33440, 33987, 34637, 35399, 36284, 37308, 38486, 39840, 41397, 43188, 45255, 47650, 50442, 53718, 57598, 62244, 67883, 74844, 83620, 94987, 110237, 131698, 164027, 218087, 326474, 652161)
    (8128000, 2607856, 1304321, 869984, 652947, 522830, 436174, 374352, 328053, 292102, 263396, 239959, 220473, 204028, 189973, 177830, 167240, 157931, 149688, 142345, 135767, 129844, 124489, 119627, 115197, 111148, 107437, 104026, 100884, 97983, 95301, 92815, 90510, 88368, 86375, 84521, 82793, 81183, 79681, 78279, 76972, 75753, 74616, 73556, 72569, 71651, 70797, 70006, 69273, 68596, 67973, 67402, 66880, 66405, 65977, 65594, 65254, 64956, 64700, 64485, 64310, 64174, 64077, 64019, 64000, 64019, 64077, 64174, 64310, 64485, 64700, 64956, 65254, 65594, 65977, 66405, 66880, 67402, 67973, 68596, 69273, 70006, 70797, 71651, 72569, 73556, 74616, 75753, 76972, 78279, 79681, 81183, 82793, 84521, 86375, 88368, 90510, 92815, 95301, 97983, 100884, 104026, 107437, 111148, 115197, 119627, 124489, 129844, 135767, 142345, 149688, 157931, 167240, 177830, 189973, 204028, 220473, 239959, 263396, 292102, 328053, 374352, 436174, 522830, 652947, 869984, 1304321, 2607856)

    """

    x = tuple(x)
    if len(x) < 2:
        return x

    negtwopireciplength = -2j * PI / len(x)
    twiddles = tuple(
        cexp(n * negtwopireciplength) for n in xrange(3 * len(x) // 4))
    # twiddles = tuple(cexp(n * negtwopireciplength) for n in xrange(len(x)))
    twiddler = partial(islice, twiddles, 0, None)

    def fft_recursive(xx, twiddle_stride):
        if len(xx) == 1:
            return xx
        evens = fft_recursive(xx[::2], twiddle_stride * 2)
        if len(evens) >= 4:
            # we can do the split radix work
            odds1 = fft_recursive(xx[1::4], 4 * twiddle_stride)
            odds3 = fft_recursive(xx[3::4], 4 * twiddle_stride)
            if len(odds1) != len(odds3):
                raise ValueError("expected a power of two, got len(x) %d" %
                                 (len(x), ))

            twodds1 = tuple(
                twiddle * odd1
                for twiddle, odd1 in izip(twiddler(twiddle_stride), odds1))
            twodds3 = tuple(
                twiddle * odd3
                for twiddle, odd3 in izip(twiddler(3 * twiddle_stride), odds3))
            assert len(twodds1) == len(twodds3)

            twoddsums = tuple(twodd1 + twodd3
                              for twodd1, twodd3 in izip(twodds1, twodds3))
            jtwodddiffs = tuple(1j * (twodd1 - twodd3)
                                for twodd1, twodd3 in izip(twodds1, twodds3))

            return tuple(
                chain((even + twoddsum
                       for even, twoddsum in izip(evens, twoddsums)),
                      (even - jtwodddiff for even, jtwodddiff in izip(
                          islice(evens,
                                 len(evens) // 2, None), jtwodddiffs)),
                      (even - twoddsum
                       for even, twoddsum in izip(evens, twoddsums)),
                      (even + jtwodddiff for even, jtwodddiff in izip(
                          islice(evens,
                                 len(evens) // 2, None), jtwodddiffs))))

        odds = fft_recursive(xx[1::2], twiddle_stride * 2)
        if len(evens) != len(odds):
            raise ValueError("expected a power of two, got len(x) %d" %
                             (len(x), ))

        twodds = tuple(
            twiddle * odd
            for twiddle, odd in izip(twiddler(twiddle_stride), odds))

        return tuple(
            chain((even + twodd for even, twodd in izip(evens, twodds)),
                  (even - twodd for even, twodd in izip(evens, twodds))))

    return fft_recursive(x, 1)
Пример #42
0
 def oddtwiddles(self):
     # return a generator for odd-indexed twiddles
     freq = self.freq
     return (cexp(freq * n) for n in xrange(1, len(self.twiddles) * 2, 2))
Пример #43
0
def setSystem(dt,p,q,m,aList,bList,A,B,F,Q):
	for i in xrange(len(aList)):
		A[i,0]=-1.0*aList[i]

	for i in xrange(len(bList)):
		B[m-1-i,0] = bList[q-i];

	F=expm(A*dt)

	lam,vr = eig(A)
	vr = matrix(vr)
	vrTrans = transpose(vr)
	vrInv = inv(vr)

	C = vrInv*B*transpose(B)*transpose(vrInv)

	Q=zeros((m,m))
	for i in xrange(m):
		for j in xrange(m):
			for k in xrange(m):
				for l in xrange(m):
					Q[i,j] += vr[i,k]*C[k,l]*vrTrans[l,j]*((cexp((lam[k] + lam[l])*dt) - 1.0)/(lam[k] + lam[l]))

	T=cholesky(Q)

	X=zeros((m,1))
	Sigma=zeros((m,m))
	P=zeros((m,m))
	for i in xrange(m):
		for j in xrange(m):
			for k in xrange(m):
				for l in xrange(m):
					Sigma[i,j] += vr[i,k]*C[k,l]*vrTrans[l,j]*(-1.0/(lam[k] + lam[l]))
			P[i,j] = Sigma[i,j]

	XMinus=zeros((m,1))
	PMinus=zeros((m,m))

	'''print 'A'
	print A
	print
	print 'B'
	print B
	print
	print 'F'
	print F
	print
	print 'C'
	print C
	print
	print 'Q'
	print Q
	print
	print 'T'
	print T
	print
	print 'Sigma'
	print Sigma
	print
	print 'X'
	print X
	print
	print 'P'
	print P'''

	return (X,P,XMinus,PMinus,F,Q)