def lpmn(m, n, z): """Associated Legendre functions of the first kind, Pmn(z) and its derivative, Pmn'(z) of order m and degree n. Returns two arrays of size (m+1,n+1) containing Pmn(z) and Pmn'(z) for all orders from 0..m and degrees from 0..n. z can be complex. Parameters ---------- m : int |m| <= n; the order of the Legendre function n : int where `n` >= 0; the degree of the Legendre function. Often called ``l`` (lower case L) in descriptions of the associated Legendre function z : float or complex input value Returns ------- Pmn_z : (m+1, n+1) array Values for all orders 0..m and degrees 0..n Pmn_d_z : (m+1, n+1) array Derivatives for all orders 0..m and degrees 0..n """ if not isscalar(m) or (abs(m) > n): raise ValueError("m must be <= n.") if not isscalar(n) or (n < 0): raise ValueError("n must be a non-negative integer.") if not isscalar(z): raise ValueError("z must be scalar.") if (m < 0): mp = -m mf, nf = mgrid[0:mp + 1, 0:n + 1] sv = errprint(0) fixarr = where(mf > nf, 0.0, (-1)**mf * gamma(nf - mf + 1) / gamma(nf + mf + 1)) sv = errprint(sv) else: mp = m if iscomplex(z): p, pd = specfun.clpmn(mp, n, real(z), imag(z)) else: p, pd = specfun.lpmn(mp, n, z) if (m < 0): p = p * fixarr pd = pd * fixarr return p, pd
def lpmn(m,n,z): """Associated Legendre functions of the first kind, Pmn(z) and its derivative, Pmn'(z) of order m and degree n. Returns two arrays of size (m+1,n+1) containing Pmn(z) and Pmn'(z) for all orders from 0..m and degrees from 0..n. z can be complex. Parameters ---------- m : int |m| <= n; the order of the Legendre function n : int where `n` >= 0; the degree of the Legendre function. Often called ``l`` (lower case L) in descriptions of the associated Legendre function z : float or complex input value Returns ------- Pmn_z : (m+1, n+1) array Values for all orders 0..m and degrees 0..n Pmn_d_z : (m+1, n+1) array Derivatives for all orders 0..m and degrees 0..n """ if not isscalar(m) or (abs(m)>n): raise ValueError("m must be <= n.") if not isscalar(n) or (n<0): raise ValueError("n must be a non-negative integer.") if not isscalar(z): raise ValueError("z must be scalar.") if (m < 0): mp = -m mf,nf = mgrid[0:mp+1,0:n+1] sv = errprint(0) fixarr = where(mf>nf,0.0,(-1)**mf * gamma(nf-mf+1) / gamma(nf+mf+1)) sv = errprint(sv) else: mp = m if iscomplex(z): p,pd = specfun.clpmn(mp,n,real(z),imag(z)) else: p,pd = specfun.lpmn(mp,n,z) if (m < 0): p = p * fixarr pd = pd * fixarr return p,pd
def polygamma(n, x): """Polygamma function which is the nth derivative of the digamma (psi) function.""" n, x = asarray(n), asarray(x) cond = (n==0) fac2 = (-1.0)**(n+1) * gamma(n+1.0) * zeta(n+1,x) if sometrue(cond,axis=0): return where(cond, psi(x), fac2) return fac2
def hyp0f1(v,z): """Confluent hypergeometric limit function 0F1. Limit as q->infinity of 1F1(q;a;z/q) """ z = asarray(z) if issubdtype(z.dtype, complexfloating): arg = 2*sqrt(abs(z)) num = where(z>=0, iv(v-1,arg), jv(v-1,arg)) den = abs(z)**((v-1.0)/2) else: num = iv(v-1,2*sqrt(z)) den = z**((v-1.0)/2.0) num *= gamma(v) return where(z==0,1.0,num/ asarray(den))
def la_roots(n, alpha, mu=0): """[x,w] = la_roots(n,alpha) Returns the roots (x) of the nth order generalized (associated) Laguerre polynomial, L^(alpha)_n(x), and weights (w) to use in Gaussian quadrature over [0,inf] with weighting function exp(-x) x**alpha with alpha > -1. """ if not all(alpha > -1): raise ValueError("alpha > -1") assert n > 0, "n must be positive." (p, q) = (alpha, 0.0) sbn_La = lambda k: -sqrt(k * (k + p)) # from recurrence relation an_La = lambda k: 2 * k + p + 1 mu0 = cephes.gamma(alpha + 1) # integral of weight over interval val = gen_roots_and_weights(n, an_La, sbn_La, mu0) if mu: return val + [mu0] else: return val
def la_roots(n, alpha, mu=0): """[x,w] = la_roots(n,alpha) Returns the roots (x) of the nth order generalized (associated) Laguerre polynomial, L^(alpha)_n(x), and weights (w) to use in Gaussian quadrature over [0,inf] with weighting function exp(-x) x**alpha with alpha > -1. """ if not all(alpha > -1): raise ValueError("alpha > -1") assert (n > 0), "n must be positive." (p, q) = (alpha, 0.0) sbn_La = lambda k: -sqrt(k * (k + p)) # from recurrence relation an_La = lambda k: 2 * k + p + 1 mu0 = cephes.gamma(alpha + 1) # integral of weight over interval val = gen_roots_and_weights(n, an_La, sbn_La, mu0) if mu: return val + [mu0] else: return val