Esempio n. 1
0
def test_QuadOneOverR_1():
    f = lambda x: 1 / (x - 0.4)
    exact = np.log(3.0 / 2.0)
    mapped_x0 = map_singular_pt(0.4, 0.0, 1.0)
    x, w = piessens(2, mapped_x0, nonsingular_N = 10)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)
    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 2
0
def test_quadlogr3():
    f = lambda x: x ** 2 * np.log(np.abs(x - 3.9))
    exact = -18.459
    mapped_x0 = map_singular_pt(3.9, 3, 4)
    tx, tw = telles_singular(50, mapped_x0)
    tx, tw = map_pts_wts(tx, tw, 3, 4)
    est = np.sum(f(tx) * tw)
    np.testing.assert_almost_equal(exact, est, 4)
Esempio n. 3
0
def test_QuadOneOverR_1():
    f = lambda x: 1 / (x - 0.4)
    exact = np.log(3.0 / 2.0)
    mapped_x0 = map_singular_pt(0.4, 0.0, 1.0)
    x, w = piessens(2, mapped_x0, nonsingular_N=10)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)
    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 4
0
def test_QuadOneOverR_4():
    f = lambda x: np.exp(x) / (x - 0.8)
    exact = -1.13761642399

    mapped_x0 = map_singular_pt(0.8, 0.0, 1.0)
    x, w = piessens(2, mapped_x0, nonsingular_N = 20)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)
    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 5
0
def test_QuadOneOverR_4():
    f = lambda x: np.exp(x) / (x - 0.8)
    exact = -1.13761642399

    mapped_x0 = map_singular_pt(0.8, 0.0, 1.0)
    x, w = piessens(2, mapped_x0, nonsingular_N=20)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)
    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 6
0
def test_QuadOneOverR_5():
    f = lambda x: np.exp(x) / (x - 0.2)
    exact = 3.139062607254266

    mapped_x0 = map_singular_pt(0.2, 0.0, 1.0)
    x, w = piessens(2, mapped_x0, nonsingular_N=50)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 7
0
def test_piessens_4_5():
    f = lambda x: np.exp(x - 4) / (x - 4.2)
    exact = 3.139062607254266

    mapped_x0 = map_singular_pt(4.2, 4.0, 5.0)
    x, w = piessens(20, mapped_x0, nonsingular_N=50)
    qx, qw = map_pts_wts(x, w, 4.0, 5.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 8
0
def test_QuadOneOverR_5():
    f = lambda x: np.exp(x) / (x - 0.2)
    exact = 3.139062607254266

    mapped_x0 = map_singular_pt(0.2, 0.0, 1.0)
    x, w = piessens(2, mapped_x0, nonsingular_N = 50)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 9
0
def test_quadlogr2():
    f = lambda x: x ** 2 * np.log(np.abs(x - 0.9))
    exact = -0.764714

    mapped_x0 = map_singular_pt(0.9, 0, 1)
    tx, tw = telles_singular(40, mapped_x0)
    tx, tw = map_pts_wts(tx, tw, 0, 1)

    est = np.sum(f(tx) * tw)
    np.testing.assert_almost_equal(exact, est, 4)
Esempio n. 10
0
def test_QuadLogR():
    f = lambda x: np.log(np.abs(x - 0.5))
    exact = -1.0 - np.log(2.0)

    mapped_x0 = map_singular_pt(0.5, 0, 1)
    tx, tw = telles_singular(50, mapped_x0)
    tx, tw = map_pts_wts(tx, tw, 0, 1)

    est = np.sum(f(tx) * tw)
    np.testing.assert_almost_equal(exact, est, 4)
Esempio n. 11
0
def test_piessens_4_5():
    f = lambda x: np.exp(x - 4) / (x - 4.2)
    exact = 3.139062607254266

    mapped_x0 = map_singular_pt(4.2, 4.0, 5.0)
    x, w = piessens(20, mapped_x0, nonsingular_N = 50)
    qx, qw = map_pts_wts(x, w, 4.0, 5.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 12
0
def test_QuadOneOverR_2():
    # Example 1 from Piessens
    g = lambda x: np.exp(x) / x
    f = lambda x: 2 * g((2 * x) - 1)
    exact = 2.11450175
    mapped_x0 = map_singular_pt(0.5, 0.0, 1.0)
    x, w = piessens(8, mapped_x0, nonsingular_N=10)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 13
0
def test_QuadOneOverR_2():
    # Example 1 from Piessens
    g = lambda x: np.exp(x) / x
    f = lambda x: 2 * g((2 * x) - 1)
    exact = 2.11450175
    mapped_x0 = map_singular_pt(0.5, 0.0, 1.0)
    x, w = piessens(8, mapped_x0, nonsingular_N = 10)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(exact, est)
Esempio n. 14
0
def test_QuadOneOverR_3():
    # Example 2 from Piessens
    g = lambda x: np.exp(x) / (np.sin(x) - np.cos(x))
    f = lambda x: np.pi / 2.0 * g(np.pi / 2.0 * x)
    exact = 2.61398312
    # Piessens estimate derived with a two pt rule.
    piessens_est = 2.61398135

    mapped_x0 = map_singular_pt(0.5, 0.0, 1.0)
    x, w = piessens(2, mapped_x0)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(piessens_est, est)
Esempio n. 15
0
def test_QuadOneOverR_3():
    # Example 2 from Piessens
    g = lambda x: np.exp(x) / (np.sin(x) - np.cos(x))
    f = lambda x: np.pi / 2.0 * g(np.pi / 2.0 * x)
    exact = 2.61398312
    # Piessens estimate derived with a two pt rule.
    piessens_est = 2.61398135

    mapped_x0 = map_singular_pt(0.5, 0.0, 1.0)
    x, w = piessens(2, mapped_x0)
    qx, qw = map_pts_wts(x, w, 0.0, 1.0)

    est = np.sum(f(qx) * qw)
    np.testing.assert_almost_equal(piessens_est, est)
Esempio n. 16
0
def test_mapped_recursive_quad2():
    mapped_ay = map_singular_pt(0.2, 0.0, 1.0)
    mapped_by = map_distance_to_interval(0.3, 0.0, 1.0)
    moments = modified_moments(rl1, 10, mapped_ay, mapped_by)
    x, w = recursive_quad(moments)
    x, w = map_pts_wts(x, w, 0.0, 1.0)
    w = map_weights_by_inv_power(w, 1.0, 0.0, 1.0)

    exact = [2.332556553293539,
             0.9603565576440610,
             0.5636909785950152, \
             0.3894662160471265,
             0.2949533988361775,
             0.2365588120191993, \
             0.1971850086215070,
             0.1689379319389373,
             0.1477219765628722, \
             0.1312177383160300]
    for i in range(len(exact)):
        est = np.sum(w * x**i)
        np.testing.assert_almost_equal(exact[i], est, 9)
Esempio n. 17
0
def test_mapped_recursive_quad2():
    mapped_ay = map_singular_pt(0.2, 0.0, 1.0)
    mapped_by = map_distance_to_interval(0.3, 0.0, 1.0)
    moments = modified_moments(rl1, 10, mapped_ay, mapped_by)
    x, w = recursive_quad(moments)
    x, w = map_pts_wts(x, w, 0.0, 1.0)
    w = map_weights_by_inv_power(w, 1.0, 0.0, 1.0)

    exact = [2.332556553293539,
             0.9603565576440610,
             0.5636909785950152, \
             0.3894662160471265,
             0.2949533988361775,
             0.2365588120191993, \
             0.1971850086215070,
             0.1689379319389373,
             0.1477219765628722, \
             0.1312177383160300]
    for i in range(len(exact)):
        est = np.sum(w * x ** i)
        np.testing.assert_almost_equal(exact[i], est, 9)
Esempio n. 18
0
def test_mapped_recursive_quad():

    mapped_ay = map_singular_pt(0.5, 1.0, 2.0)
    mapped_by = map_distance_to_interval(0.5, 1.0, 2.0)
    moments = modified_moments(rl1, 10, mapped_ay, mapped_by)
    x, w = recursive_quad(moments)
    x, w = map_pts_wts(x, w, 1.0, 2.0)
    w = map_weights_by_inv_power(w, 1.0, 1.0, 2.0)

    exact = [0.9370728722124352,
             1.342568485003826,
             2.000243585190683, \
             3.091829672374373,
             4.940760583752816,
             8.128175556459884, \
             13.70706664710914,
             23.59959784014733,
             41.33761425072659, \
             73.44841816566141]
    for i in range(10):
        est = np.sum(w * x ** i)
        np.testing.assert_almost_equal(exact[i], est, 10)
Esempio n. 19
0
def test_mapped_recursive_quad():

    mapped_ay = map_singular_pt(0.5, 1.0, 2.0)
    mapped_by = map_distance_to_interval(0.5, 1.0, 2.0)
    moments = modified_moments(rl1, 10, mapped_ay, mapped_by)
    x, w = recursive_quad(moments)
    x, w = map_pts_wts(x, w, 1.0, 2.0)
    w = map_weights_by_inv_power(w, 1.0, 1.0, 2.0)

    exact = [0.9370728722124352,
             1.342568485003826,
             2.000243585190683, \
             3.091829672374373,
             4.940760583752816,
             8.128175556459884, \
             13.70706664710914,
             23.59959784014733,
             41.33761425072659, \
             73.44841816566141]
    for i in range(10):
        est = np.sum(w * x**i)
        np.testing.assert_almost_equal(exact[i], est, 10)