Example #1
0
def test_h_roots():
    rootf = orth.h_roots
    evalf = orth.eval_hermite
    weightf = orth.hermite(5).weight_func

    verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 5)
    verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 25, atol=1e-13)
    verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 100, atol=1e-12)

    # Golub-Welsch branch
    x, w = orth.h_roots(5, False)
    y, v, m = orth.h_roots(5, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

    muI, muI_err = integrate.quad(weightf, -np.inf, np.inf)
    assert_allclose(m, muI, rtol=muI_err)

    # Asymptotic branch (switch over at n >= 150)
    x, w = orth.h_roots(200, False)
    y, v, m = orth.h_roots(200, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)
    assert_allclose(sum(v), m, 1e-14, 1e-14)

    assert_raises(ValueError, orth.h_roots, 0)
    assert_raises(ValueError, orth.h_roots, 3.3)
Example #2
0
def test_roots_hermite():
    rootf = sc.roots_hermite
    evalf = orth.eval_hermite
    weightf = orth.hermite(5).weight_func

    verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 5)
    verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 25, atol=1e-13)
    verify_gauss_quad(rootf, evalf, weightf, -np.inf, np.inf, 100, atol=1e-12)

    # Golub-Welsch branch
    x, w = sc.roots_hermite(5, False)
    y, v, m = sc.roots_hermite(5, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

    muI, muI_err = integrate.quad(weightf, -np.inf, np.inf)
    assert_allclose(m, muI, rtol=muI_err)

    # Asymptotic branch (switch over at n >= 150)
    x, w = sc.roots_hermite(200, False)
    y, v, m = sc.roots_hermite(200, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)
    assert_allclose(sum(v), m, 1e-14, 1e-14)

    assert_raises(ValueError, sc.roots_hermite, 0)
    assert_raises(ValueError, sc.roots_hermite, 3.3)
Example #3
0
 def test_hermite(self):
     H0 = orth.hermite(0)
     H1 = orth.hermite(1)
     H2 = orth.hermite(2)
     H3 = orth.hermite(3)
     H4 = orth.hermite(4)
     H5 = orth.hermite(5)
     assert_array_almost_equal(H0.c, [1], 13)
     assert_array_almost_equal(H1.c, [2, 0], 13)
     assert_array_almost_equal(H2.c, [4, 0, -2], 13)
     assert_array_almost_equal(H3.c, [8, 0, -12, 0], 13)
     assert_array_almost_equal(H4.c, [16, 0, -48, 0, 12], 12)
     assert_array_almost_equal(H5.c, [32, 0, -160, 0, 120, 0], 12)
Example #4
0
 def test_hermite(self):
     H0 = orth.hermite(0)
     H1 = orth.hermite(1)
     H2 = orth.hermite(2)
     H3 = orth.hermite(3)
     H4 = orth.hermite(4)
     H5 = orth.hermite(5)
     assert_array_almost_equal(H0.c,[1],13)
     assert_array_almost_equal(H1.c,[2,0],13)
     assert_array_almost_equal(H2.c,[4,0,-2],13)
     assert_array_almost_equal(H3.c,[8,0,-12,0],13)
     assert_array_almost_equal(H4.c,[16,0,-48,0,12],12)
     assert_array_almost_equal(H5.c,[32,0,-160,0,120,0],12)
Example #5
0
    def test_hermitenorm(self):
        # He_n(x) = 2**(-n/2) H_n(x/sqrt(2))
        psub = np.poly1d([1.0 / sqrt(2), 0])
        H0 = orth.hermitenorm(0)
        H1 = orth.hermitenorm(1)
        H2 = orth.hermitenorm(2)
        H3 = orth.hermitenorm(3)
        H4 = orth.hermitenorm(4)
        H5 = orth.hermitenorm(5)
        he0 = orth.hermite(0)(psub)
        he1 = orth.hermite(1)(psub) / sqrt(2)
        he2 = orth.hermite(2)(psub) / 2.0
        he3 = orth.hermite(3)(psub) / (2 * sqrt(2))
        he4 = orth.hermite(4)(psub) / 4.0
        he5 = orth.hermite(5)(psub) / (4.0 * sqrt(2))

        assert_array_almost_equal(H0.c, he0.c, 13)
        assert_array_almost_equal(H1.c, he1.c, 13)
        assert_array_almost_equal(H2.c, he2.c, 13)
        assert_array_almost_equal(H3.c, he3.c, 13)
        assert_array_almost_equal(H4.c, he4.c, 13)
        assert_array_almost_equal(H5.c, he5.c, 13)
Example #6
0
    def test_hermitenorm(self):
        # He_n(x) = 2**(-n/2) H_n(x/sqrt(2))
        psub = np.poly1d([1.0/sqrt(2),0])
        H0 = orth.hermitenorm(0)
        H1 = orth.hermitenorm(1)
        H2 = orth.hermitenorm(2)
        H3 = orth.hermitenorm(3)
        H4 = orth.hermitenorm(4)
        H5 = orth.hermitenorm(5)
        he0 = orth.hermite(0)(psub)
        he1 = orth.hermite(1)(psub) / sqrt(2)
        he2 = orth.hermite(2)(psub) / 2.0
        he3 = orth.hermite(3)(psub) / (2*sqrt(2))
        he4 = orth.hermite(4)(psub) / 4.0
        he5 = orth.hermite(5)(psub) / (4.0*sqrt(2))

        assert_array_almost_equal(H0.c,he0.c,13)
        assert_array_almost_equal(H1.c,he1.c,13)
        assert_array_almost_equal(H2.c,he2.c,13)
        assert_array_almost_equal(H3.c,he3.c,13)
        assert_array_almost_equal(H4.c,he4.c,13)
        assert_array_almost_equal(H5.c,he5.c,13)