Example #1
0
 def mplegenp(nu, mu, x):
     if mu == int(mu) and x == 1:
         # mpmath 0.17 gets this wrong
         if mu == 0:
             return 1
         else:
             return 0
     return mpmath.legenp(nu, mu, x)
Example #2
0
 def mplegenp(nu, mu, x):
     if mu == int(mu) and x == 1:
         # mpmath 0.17 gets this wrong
         if mu == 0:
             return 1
         else:
             return 0
     return mpmath.legenp(nu, mu, x)
Example #3
0
def make_assoc_legendre_p_vals():
    from mpmath import legenp

    l = range(5)
    m = range(-4, 5)
    x = linspace('-0.99', '0.99', 67)

    l, m, x = zip(*(vals for vals in outer(l, m, x) if abs(vals[1]) <= vals[0]))
    p = [legenp(*vals, zeroprec = 1024) for vals in zip(l, m, x)]

    return make_special_vals('assoc_legendre_p_vals', ('l', l), ('m', m), ('x', x), ('p', p))
Example #4
0
def make_assoc_legendre_p_vals():
    from mpmath import legenp

    l = list(range(5))
    m = list(range(-4, 5))
    x = linspace('-0.99', '0.99', 67)

    l, m, x = zip(*(vals for vals in outer(l, m, x) if abs(vals[1]) <= vals[0]))
    p = [legenp(*vals, zeroprec = 1024) for vals in zip(l, m, x)]

    return make_special_vals('assoc_legendre_p_vals', ('l', l), ('m', m), ('x', x), ('p', p))
Example #5
0
def test_lpmv():
    pts = []
    for x in [-0.99, -0.557, 1e-6, 0.132, 1]:
        pts.extend([
            (1, 1, x),
            (1, -1, x),
            (-1, 1, x),
            (-1, -2, x),
            (1, 1.7, x),
            (1, -1.7, x),
            (-1, 1.7, x),
            (-1, -2.7, x),
            (1, 10, x),
            (1, 11, x),
            (3, 8, x),
            (5, 11, x),
            (-3, 8, x),
            (-5, 11, x),
            (3, -8, x),
            (5, -11, x),
            (-3, -8, x),
            (-5, -11, x),
            (3, 8.3, x),
            (5, 11.3, x),
            (-3, 8.3, x),
            (-5, 11.3, x),
            (3, -8.3, x),
            (5, -11.3, x),
            (-3, -8.3, x),
            (-5, -11.3, x),
        ])

    dataset = [p + (mpmath.legenp(p[1], p[0], p[2]), ) for p in pts]
    dataset = np.array(dataset, dtype=np.float_)

    evf = lambda mu, nu, x: sc.lpmv(mu.astype(int), nu, x)

    olderr = np.seterr(invalid='ignore')
    try:
        FuncData(evf, dataset, (0, 1, 2), 3, rtol=1e-10, atol=1e-14).check()
    finally:
        np.seterr(**olderr)
Example #6
0
def test_lpmv():
    pts = []
    for x in [-0.99, -0.557, 1e-6, 0.132, 1]:
        pts.extend([
            (1, 1, x),
            (1, -1, x),
            (-1, 1, x),
            (-1, -2, x),
            (1, 1.7, x),
            (1, -1.7, x),
            (-1, 1.7, x),
            (-1, -2.7, x),
            (1, 10, x),
            (1, 11, x),
            (3, 8, x),
            (5, 11, x),
            (-3, 8, x),
            (-5, 11, x),
            (3, -8, x),
            (5, -11, x),
            (-3, -8, x),
            (-5, -11, x),
            (3, 8.3, x),
            (5, 11.3, x),
            (-3, 8.3, x),
            (-5, 11.3, x),
            (3, -8.3, x),
            (5, -11.3, x),
            (-3, -8.3, x),
            (-5, -11.3, x),
        ])

    dataset = [p + (mpmath.legenp(p[1], p[0], p[2]),) for p in pts]
    dataset = np.array(dataset, dtype=np.float_)

    evf = lambda mu,nu,x: sc.lpmv(mu.astype(int), nu, x)

    olderr = np.seterr(invalid='ignore')
    try:
        FuncData(evf, dataset, (0,1,2), 3, rtol=1e-10, atol=1e-14).check()
    finally:
        np.seterr(**olderr)
Example #7
0
def eqn42_solve( geom, Nmax ):
    # eqn 4.2 
    NMAX = Nmax         # where to truncate the infinite system of eqns
    S = geom['S']
    distanceqp = geom['distanceqp']
    thetaqp = geom['thetaqp']
    phiqp = geom['phiqp']
    radii = geom['radii']

    # coefficient matrix
    if USEMPMATH:
        CM = mpmath.zeros( S*NMAX*(2*NMAX+1) )
    else:
        CM = np.zeros( (S*NMAX*(2*NMAX+1), S*NMAX*(2*NMAX+1)) )

    for sprimei,sprime in enumerate(range(S)):
        for nprimei,nprime in enumerate(range(NMAX)):
            for mprimei,mprime in enumerate(range(-nprime,nprime+1)):

                # row index
                ri = sprimei*NMAX*(2*NMAX+1) + nprimei*(2*NMAX+1) + mprimei
                # row prefactors
                prefac = (-1)**(nprime+mprime) * radii[sprimei]**(nprime+1) \
                         * 1./factorial(nprime+mprime)

                for si,s in enumerate(range(S)):
                    if sprimei != si:
                        for ni,n in enumerate(range(NMAX)):
                            for mi,m in enumerate(range(-n,n+1)):

                                # column index
                                ci = si*NMAX*(2*NMAX+1) + ni*(2*NMAX+1) + mi

                                f1 = distanceqp[sprimei,si]**(-(n+1))
                                f2 = (radii[sprimei]/distanceqp[sprimei,si])**nprime
                                f3 = factorial(n-m+nprime+mprime)/factorial(n-m)
                                if USEMPMATH:
                                    f4 = mpmath.legenp( n+nprime, m-mprime, \
                                                        np.cos(thetaqp[sprimei,si]) )
                                else:
                                    f4 = scipy.special.lpmv( m-mprime, n+nprime, \
                                                             np.cos(thetaqp[sprimei,si]) )
                                f5 = np.exp( 1j*(m-mprime)*phiqp[sprimei,si] )

                                CM[ri,ci] = prefac*f1*f2*f3*f4*f5


    if USEMPMATH:
        CM += mpmath.diag(np.ones(S*NMAX*(2*NMAX+1)))
        Qs = mpmath.zeros(S)
    else:
        CM += np.diag(np.ones(S*NMAX*(2*NMAX+1)))
        Qs = np.zeros((S,S))              


    for si in range(S):
        if USEMPMATH:
            rhs = mpmath.zeros( S*NMAX*(2*NMAX+1), 1 )
        else:          
            rhs = np.zeros((CM.shape[0],))
        rhs[si*NMAX*(2*NMAX+1):(si*NMAX+1)*(2*NMAX+1)] = radii[si]
        if USEMPMATH:     
            sol = mpmath.lu_solve( CM, rhs )
        else:
            sol = np.linalg.solve( CM, rhs )
        #print sol[::(NMAX*(2*NMAX+1))]
        Qs[si,:] = sol[::(NMAX*(2*NMAX+1))]
    
    return Qs