Пример #1
0
def test_la_roots():
    root_func = lambda a: lambda n, mu: orth.la_roots(n, a, mu)
    eval_func = lambda a: lambda n, x: orth.eval_genlaguerre(n, a, x)

    verify_gauss_quad(root_func(-0.5), eval_func(-0.5), 5)
    verify_gauss_quad(root_func(-0.5), eval_func(-0.5), 25, atol=1e-13)
    verify_gauss_quad(root_func(-0.5), eval_func(-0.5), 100, atol=1e-12)

    verify_gauss_quad(root_func(0.1), eval_func(0.1), 5)
    verify_gauss_quad(root_func(0.1), eval_func(0.1), 25, atol=1e-13)
    verify_gauss_quad(root_func(0.1), eval_func(0.1), 100, atol=1e-13)

    verify_gauss_quad(root_func(1), eval_func(1), 5)
    verify_gauss_quad(root_func(1), eval_func(1), 25, atol=1e-13)
    verify_gauss_quad(root_func(1), eval_func(1), 100, atol=1e-13)

    verify_gauss_quad(root_func(10), eval_func(10), 5)
    verify_gauss_quad(root_func(10), eval_func(10), 25, atol=1e-13)
    verify_gauss_quad(root_func(10), eval_func(10), 100, atol=1e-12)

    verify_gauss_quad(root_func(50), eval_func(50), 5)
    verify_gauss_quad(root_func(50), eval_func(50), 25, atol=1e-13)
    verify_gauss_quad(root_func(50), eval_func(50), 100, atol=1e-13)

    x, w = orth.la_roots(5, 2, False)
    y, v, m = orth.la_roots(5, 2, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

    assert_raises(ValueError, orth.la_roots, 0, 2)
    assert_raises(ValueError, orth.la_roots, 3.3, 2)
    assert_raises(ValueError, orth.la_roots, 3, -1.1)
Пример #2
0
def test_la_roots():
    root_func = lambda a: lambda n, mu: orth.la_roots(n, a, mu)
    eval_func = lambda a: lambda n, x: orth.eval_genlaguerre(n, a, x)

    verify_gauss_quad(root_func(-0.5), eval_func(-0.5), 5)
    verify_gauss_quad(root_func(-0.5), eval_func(-0.5), 25, atol=1e-13)
    verify_gauss_quad(root_func(-0.5), eval_func(-0.5), 100, atol=1e-12)

    verify_gauss_quad(root_func(0.1), eval_func(0.1), 5)
    verify_gauss_quad(root_func(0.1), eval_func(0.1), 25, atol=1e-13)
    verify_gauss_quad(root_func(0.1), eval_func(0.1), 100, atol=1e-13)

    verify_gauss_quad(root_func(1), eval_func(1), 5)
    verify_gauss_quad(root_func(1), eval_func(1), 25, atol=1e-13)
    verify_gauss_quad(root_func(1), eval_func(1), 100, atol=1e-13)

    verify_gauss_quad(root_func(10), eval_func(10), 5)
    verify_gauss_quad(root_func(10), eval_func(10), 25, atol=1e-13)
    verify_gauss_quad(root_func(10), eval_func(10), 100, atol=1e-12)

    verify_gauss_quad(root_func(50), eval_func(50), 5)
    verify_gauss_quad(root_func(50), eval_func(50), 25, atol=1e-13)
    verify_gauss_quad(root_func(50), eval_func(50), 100, atol=1e-13)

    x, w = orth.la_roots(5, 2, False)
    y, v, m = orth.la_roots(5, 2, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

    assert_raises(ValueError, orth.la_roots, 0, 2)
    assert_raises(ValueError, orth.la_roots, 3.3, 2)
    assert_raises(ValueError, orth.la_roots, 3, -1.1)
Пример #3
0
def eval_harmonicBasis(n, l, r, r0=1.):
    """ 
    For testing purposes 
    
    Evaluates the harmonic basis function at positions r
    """
    N = norm_harmonicBasis(n, l, r0)
    return (N * r**l * exp(-0.5 * r**2 / r0**2) *
            eval_genlaguerre(n, l + 0.5, r**2 / r0**2))
Пример #4
0
def test_roots_genlaguerre():
    rootf = lambda a: lambda n, mu: sc.roots_genlaguerre(n, a, mu)
    evalf = lambda a: lambda n, x: orth.eval_genlaguerre(n, a, x)
    weightf = lambda a: lambda x: x**a * np.exp(-x)

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

    vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 5)
    vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 25, atol=1e-13)
    vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 100, atol=1.6e-13)

    vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 5)
    vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 25, atol=1e-13)
    vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 100, atol=1.03e-13)

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

    vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 5)
    vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 25, atol=1e-13)
    vgq(rootf(50),
        evalf(50),
        weightf(50),
        0.,
        np.inf,
        100,
        rtol=1e-14,
        atol=2e-13)

    x, w = sc.roots_genlaguerre(5, 2, False)
    y, v, m = sc.roots_genlaguerre(5, 2, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

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

    assert_raises(ValueError, sc.roots_genlaguerre, 0, 2)
    assert_raises(ValueError, sc.roots_genlaguerre, 3.3, 2)
    assert_raises(ValueError, sc.roots_genlaguerre, 3, -1.1)
Пример #5
0
def test_roots_genlaguerre():
    rootf = lambda a: lambda n, mu: sc.roots_genlaguerre(n, a, mu)
    evalf = lambda a: lambda n, x: orth.eval_genlaguerre(n, a, x)
    weightf = lambda a: lambda x: x**a * np.exp(-x)

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

    vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 5)
    vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 25, atol=1e-13)
    vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 100, atol=1e-13)

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

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

    vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 5)
    vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 25, atol=1e-13)
    vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 100, rtol=1e-14, atol=2e-13)

    x, w = sc.roots_genlaguerre(5, 2, False)
    y, v, m = sc.roots_genlaguerre(5, 2, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

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

    assert_raises(ValueError, sc.roots_genlaguerre, 0, 2)
    assert_raises(ValueError, sc.roots_genlaguerre, 3.3, 2)
    assert_raises(ValueError, sc.roots_genlaguerre, 3, -1.1)
Пример #6
0
def test_eval_genlaguerre_restriction():
    # check it returns nan for alpha <= -1
    assert_(np.isnan(orth.eval_genlaguerre(0, -1, 0)))
    assert_(np.isnan(orth.eval_genlaguerre(0.1, -1, 0)))
Пример #7
0
def test_genlaguerre_nan(n, alpha, x):
    # Regression test for gh-11361.
    nan_laguerre = np.isnan(orth.eval_genlaguerre(n, alpha, x))
    nan_arg = np.any(np.isnan([n, alpha, x]))
    assert nan_laguerre == nan_arg