Ejemplo n.º 1
0
def zernike_variance_von_karman(n, m, R, k0, Cn_squared, wavelength):
	'''Calculate the variance of the Zernike mode (`n`,`m`), using a von Karman turbulence spectrum.

	Parameters
	----------
	n : int
		The radial Zernike order.
	m : int
		The azimuthal Zernike order.
	R : scalar
		The radius of the aperture.
	k0 : scalar
		The spatial frequency of the outer scale (1/L0).
	Cn_squared : scalar
		The integrated Cn^2 profile.
	wavelength : scalar
		The wavelength at which to calculate the variance.
	
	Returns
	-------
	scalar
		The variance of the specific Zernike mode.
	'''
	A = 0.00969 * (2*np.pi / wavelength)**2 * Cn_squared
	coeffs_all = (-1)**(n - m) * 2 * (2 * np.pi)**(11./3) * (n + 1) * A * R**(5./3) / (sqrt(np.pi) * np.sin(np.pi * (n + 1./6)))

	term11 = mpmath.hyper([n + (3./2), n + 2, n + 1],[n + (1./6), n + 2, n + 2, 2 * n + 3], (2*np.pi * R * k0)**2)
	term12 = sqrt(np.pi) * (2*np.pi * R * k0)**(2 * n - 5./3) * scipy.special.gamma(n + 1) / (2**(2 * n + 3) * scipy.special.gamma(11./6) * scipy.special.gamma(n + 1./6) * scipy.special.gamma(n + 2)**2)
	term21 = -1 * scipy.special.gamma(7./3) * scipy.special.gamma(17./6) / (2 * scipy.special.gamma(-n + 11./6) * scipy.special.gamma(17./6)**2 * scipy.special.gamma(n + 23./6))
	term22 = mpmath.hyper([11./6, 7./3, 17./6], [-n + 11./6, 17./6, 17./6, n + 23./6], (2*np.pi * R * k0)**2)

	return coeffs_all * (term11 * term12 + term21 * term22)
Ejemplo n.º 2
0
def prob_L_from_mut(L,ta,ts,phi,N, theta0=theta):
    if L<200000 and L>0:
        if phi>0.01:
            b=0.5+0.25*L*rho*N+0.5*L*theta*N
            c=(0.25+0.5*exp(ta/N)-0.5*exp(2*ta/N))*L*rho*N
            prob1=phi*0.5*exp(0.5*L*((-1.5+exp(-ta/N))*N*rho-2*ta*theta)+c)*hyper(1,b+1,-c)/b
            b+=0.5*theta0*N
            c=(0.25+exp(ta/N)*(0.5-0.5*exp(ta/N)))*L*rho*N
            prob2=-phi*0.5*exp(-0.75*L*rho*N+0.5*exp(-ta/N)*L*rho*N-ta*theta0-L*ta*theta+c)*hyper(1,b+1,-c)/b
        else:
            prob1, prob2 = 0,0
        if phi<0.99:
            b=0.5+0.25*L*rho*N+0.5*L*theta*N
            c=(0.25+0.5*exp(ts/N)-0.5*exp(2*ts/N))*L*rho*N
            prob3=(1-phi)*0.5*exp(0.5*L*((-1.5+exp(-ts/N))*N*rho-2*ts*theta)+c)*hyper(1,b+1,-c)/b
            b+=0.5*theta0*N
            c=(0.25+exp(ts/N)*(0.5-0.5*exp(ts/N)))*L*rho*N
            prob4=-(1-phi)*0.5*exp(-0.75*L*rho*N+0.5*exp(-ts/N)*L*rho*N-ts*theta0-L*ts*theta+c)*hyper(1,b+1,-c)/b
        else:
            prob3, prob4=0,0
        return abs(math.fsum((prob1,prob2,prob3,prob4)))

    else:
        prob=phi*(math.exp(-ta*L*(rho+theta))/(1+L*N*(rho+theta))-math.exp(-ta*(L*(rho+theta)+theta))/(1+L*(rho+theta)*N+theta*N))*(1+L*((-exp(-rho*ta)+1)/(1-rho*N)-rho*N*(1-exp(-ta))/(1-rho*N)))
        prob+=(1-phi)*(math.exp(-ts*L*(rho+theta))/(1+L*(rho+theta)*N)-math.exp(-ts*(L*(rho+theta)+theta))/(1+L*(rho+theta)*N+theta*N))*(1+L*((-exp(-rho*ts)+1)/(1-rho*N)-rho*N*(1-exp(-ts))/(1-rho*N)))
        return prob
Ejemplo n.º 3
0
 def mhyper(self,q,m,n,k):
     u = min(self.tag_length ,n)-1
     A = binomial(m,q)*binomial(n,k-q)
     B = hyper([1,q-k,q-m],[1+q,1-k+n+q], 1)
     C = -binomial(m,1+u)*binomial(n,k-1-u)
     D = hyper([1,1-k+u,1-m+u],[2+u,2-k+n+u], 1)
     return mathlog(float((A*B + C*D) / binomial(m+n, k)))
Ejemplo n.º 4
0
 def _eval_evalf(self, prec):
     z = self.argument._to_mpmath(prec)
     ap = [a._to_mpmath(prec) for a in self.ap]
     bp = [b._to_mpmath(prec) for b in self.bq]
     with mpmath.workprec(prec):
         res = mpmath.hyper(ap, bp, z, eliminate=False)
     return Expr._from_mpmath(res, prec)
Ejemplo n.º 5
0
 def _eval_evalf(self, prec):
     z = self.argument._to_mpmath(prec)
     ap = [a._to_mpmath(prec) for a in self.ap]
     bp = [b._to_mpmath(prec) for b in self.bq]
     with mpmath.workprec(prec):
         res = mpmath.hyper(ap, bp, z, eliminate=False)
     return Expr._from_mpmath(res, prec)
def _f(q,γ,ϵ):
    ''' The distribution function. Checked with Mathematica on 2018-06-20
    '''
    
    a1 = [1/2]
    b1 = [3/2,3/2-γ**2/2]
    a2 = [γ**2/2]
    b2 = [γ**2/2 + 1/2,γ**2/2+1]
    zm = π*ϵ - q
    zp = π*ϵ + q
    
    p1 = Γ((γ**2-1)/2)/(2*np.sqrt(π)*Γ(γ**2/2))
    p2 = Γ(-γ**2)*np.sin(π*γ**2 / 2) / π
    
    t1 = p1*(zm*hyper(a1,b1,zm**2/4) + zp*hyper(a1,b1,zp**2/4))
    t2 = p2*(np.sign(zm)*(np.abs(zm)**(γ**2))*hyper(a2,b2,zm**2/4) + zp**(γ**2) * hyper(a2,b2,zp**2/4))
    
    cf = np.float(t1-t2)
    if cf > 1.0E-16:
        return np.float(t1-t2)
    else:
        return 0.0
Ejemplo n.º 7
0
def t2z_convert(t, nu):
    t = mpf(t)
    nu = mpf(nu)

    z = sqrt(mpf("2")) * erfinv(  # inverse normal cdf
        mpf("2") * t *
        gamma((mpf("1") / mpf("2")) * nu + mpf("1") / mpf("2")) * hyper(
            (mpf("1") / mpf("2"),
             (mpf("1") / mpf("2")) * nu + mpf("1") / mpf("2")),
            (mpf("3") / mpf("2"), ),
            -power(t, mpf("2")) / nu,
        ) / (sqrt(pi) * sqrt(nu) * gamma((mpf("1") / mpf("2")) * nu)))

    return z
Ejemplo n.º 8
0
def fingerprint(p):
    ret = np.log(p[0]**2)  ## A constant factor
    ret += s_values * np.log(
        p[1]**
        2)  ## C^s for some C, together with previous cover most prefactors
    ret += loggamma(p[2] + p[3] * s_values)  ## A flexible gamma
    ret += loggamma(p[4] + p[5] * s_values)  ## A flexible gamma
    hyp = [
        complex(
            hyper([p[6] * s + p[7], p[8] + p[9] * s], [p[10] + p[11] * s],
                  p[12])) for s in s_values
    ]  ## slow generalised_hypergeom
    ret += np.log(hyp)
    # s_values**2 * np.log(p[6]**2) #+ s**3 * np.log(p[3]**2) + s**4 * np.log(p[4]**2)  ## Strange series temrs
    #ret += np.log(1 + p[5]*s_values + p[6]*s_values**2 + p[7]*s_values**3 + p[8]*s_values**4) ## Log of polynomial
    return ret
Ejemplo n.º 9
0
def f02(a, b, z):
    return mp.hyper([], [a, b], z)
Ejemplo n.º 10
0
class Turbines(object):
    def __init__(self, x, y, HH, yaw, a, RD, W, ground):
        self.loc = loc # Location in Space
        self.RD  = RD  # Rotor Diameter
        self.W   = W   # Width of influence


from scipy.special import gamma
from mpmath import hyper

T_norm = 2.0*gamma(7.0/6.0)
D_norm = 2.0*gamma(7.0/6.0)
S_norm = (2.0+pi)/(2.0*pi)

h1 = float(hyper([],[1/3, 2/3, 5/6, 7/6],-(np.pi**6/46656)))
h2 = float(hyper([],[2/3, 7/6, 4/3, 3/2],-(np.pi**6/46656)))
h3 = float(hyper([],[4/3, 3/2, 5/3, 11/6],-(np.pi**6/46656)))
SD_norm = (1/3*np.pi**(3/2)*h1 - 1/15*np.pi**3*gamma(11/6)*h2 + gamma(7/6)*(1 + 1/360*np.pi**5*h3))/(.81831)
volNormalization = T_norm*SD_norm*W*R**(self.problem.dom.dim)
#!/usr/bin/env python

'''
program:     hypergeometric_functions_with_mpmath.py
author:      tc
created:     2015-10-17 -- 11 CEST
description: computes some hypergeometric functions with mpmath, and checks
             with Mathematica values.
notes:       hyp0f1(a, z) fails at a=0, while the Mathematica version does not.
'''

import mpmath

a = [1, 1]
b = [3, 3, 3]
z = 2.0
res1 = float(mpmath.hyper(a, b, z))
res2 = float(mpmath.hyp0f1(1, 2))
print 'HypergeometricPFQ[{1, 1}, {3, 3, 3}, 2.0]: 1.07893'
print 'mpmath.hyper([1, 1], [3, 3, 3], 2.0):      %f' % res1
print 'Hypergeometric0F1Regularized[1, 2]: 4.25235'
print 'mpmath.hyp0f1(1, 2):                %f' % res2