Пример #1
0
    def testJacobi(self):
        from scipy.special.orthogonal import jacobi

        N = 5
        x = numpy.linspace(0, 1, 6)
        for a in range(4):
            for b in range(4):
                j1 = numpy.vstack([jacobi(n, a, b)(2 * x - 1) for n in range(N + 1)])
                j3 = Jacobi(a, b)(N, x)
                numpy.testing.assert_array_almost_equal(j1, j3)
Пример #2
0
    def test_sh_jacobi(self):
        # G^(p,q)_n(x) = n! gamma(n+p)/gamma(2*n+p) * P^(p-q,q-1)_n(2*x-1)
        conv = lambda n, p: gamma(n + 1) * gamma(n + p) / gamma(2 * n + p)
        psub = np.poly1d([2, -1])
        q = 4 * np.random.random()
        p = q - 1 + 2 * np.random.random()
        #print "shifted jacobi p,q = ", p, q
        G0 = orth.sh_jacobi(0, p, q)
        G1 = orth.sh_jacobi(1, p, q)
        G2 = orth.sh_jacobi(2, p, q)
        G3 = orth.sh_jacobi(3, p, q)
        G4 = orth.sh_jacobi(4, p, q)
        G5 = orth.sh_jacobi(5, p, q)
        ge0 = orth.jacobi(0, p - q, q - 1)(psub) * conv(0, p)
        ge1 = orth.jacobi(1, p - q, q - 1)(psub) * conv(1, p)
        ge2 = orth.jacobi(2, p - q, q - 1)(psub) * conv(2, p)
        ge3 = orth.jacobi(3, p - q, q - 1)(psub) * conv(3, p)
        ge4 = orth.jacobi(4, p - q, q - 1)(psub) * conv(4, p)
        ge5 = orth.jacobi(5, p - q, q - 1)(psub) * conv(5, p)

        assert_array_almost_equal(G0.c, ge0.c, 13)
        assert_array_almost_equal(G1.c, ge1.c, 13)
        assert_array_almost_equal(G2.c, ge2.c, 13)
        assert_array_almost_equal(G3.c, ge3.c, 13)
        assert_array_almost_equal(G4.c, ge4.c, 13)
        assert_array_almost_equal(G5.c, ge5.c, 13)
Пример #3
0
    def test_sh_jacobi(self):
        # G^(p,q)_n(x) = n! gamma(n+p)/gamma(2*n+p) * P^(p-q,q-1)_n(2*x-1)
        conv = lambda n,p: gamma(n+1)*gamma(n+p)/gamma(2*n+p)
        psub = np.poly1d([2,-1])
        q = 4 * np.random.random()
        p = q-1 + 2*np.random.random()
        #print "shifted jacobi p,q = ", p, q
        G0 = orth.sh_jacobi(0,p,q)
        G1 = orth.sh_jacobi(1,p,q)
        G2 = orth.sh_jacobi(2,p,q)
        G3 = orth.sh_jacobi(3,p,q)
        G4 = orth.sh_jacobi(4,p,q)
        G5 = orth.sh_jacobi(5,p,q)
        ge0 = orth.jacobi(0,p-q,q-1)(psub) * conv(0,p)
        ge1 = orth.jacobi(1,p-q,q-1)(psub) * conv(1,p)
        ge2 = orth.jacobi(2,p-q,q-1)(psub) * conv(2,p)
        ge3 = orth.jacobi(3,p-q,q-1)(psub) * conv(3,p)
        ge4 = orth.jacobi(4,p-q,q-1)(psub) * conv(4,p)
        ge5 = orth.jacobi(5,p-q,q-1)(psub) * conv(5,p)

        assert_array_almost_equal(G0.c,ge0.c,13)
        assert_array_almost_equal(G1.c,ge1.c,13)
        assert_array_almost_equal(G2.c,ge2.c,13)
        assert_array_almost_equal(G3.c,ge3.c,13)
        assert_array_almost_equal(G4.c,ge4.c,13)
        assert_array_almost_equal(G5.c,ge5.c,13)
Пример #4
0
def jacobid(n, a, b, d):
    """ (Derivatives of) Jacobi polynomials shifted to [0,1]
    
    The scipy.special.orthogonal routines mean that this function is:
    a) slow
    b) incorrect (it fails at x=0, i.e. the sso routines fail at x=-1)
    
    Don't use it until they fix thins.
    """
    from scipy.special.orthogonal import jacobi
    from math import factorial
    if d > n: return lambda x: numpy.zeros(x.shape)
    fac = factorial(a + b + n + d) / factorial(a + b + n)
    j = jacobi(n-d, a+d, b+d)
    return lambda x: fac * j(2 * x - 1)