Пример #1
0
def test_hermite():
    x, w = gauss_hermite(1, 17)
    assert [str(r) for r in x] == ['0']
    assert [str(r) for r in w] == ['1.7724538509055160']

    x, w = gauss_hermite(2, 17)
    assert [str(r) for r in x] == ['-0.70710678118654752',
                                    '0.70710678118654752']

    assert [str(r) for r in w] == ['0.88622692545275801',
                                   '0.88622692545275801']

    x, w = gauss_hermite(3, 17)
    assert [str(r) for r in x] == [
        '-1.2247448713915890',
        '0',
        '1.2247448713915890']
    assert [str(r) for r in w] == [
        '0.29540897515091934',
        '1.1816359006036774',
        '0.29540897515091934']

    x, w = gauss_hermite(4, 17)
    assert [str(r) for r in x] == [
        '-1.6506801238857846',
        '-0.52464762327529032',
        '0.52464762327529032',
        '1.6506801238857846'
        ]
    assert [str(r) for r in w] == [
        '0.081312835447245177',
        '0.80491409000551284',
        '0.80491409000551284',
        '0.081312835447245177'
        ]

    x, w = gauss_hermite(5, 17)
    assert [str(r) for r in x] == [
        '-2.0201828704560856',
        '-0.95857246461381851',
        '0',
        '0.95857246461381851',
        '2.0201828704560856'
        ]
    assert [str(r) for r in w] == [
        '0.019953242059045913',
        '0.39361932315224116',
        '0.94530872048294188',
        '0.39361932315224116',
        '0.019953242059045913'
        ]
Пример #2
0
def test_hermite():
    x, w = gauss_hermite(1, 17)
    assert [str(r) for r in x] == ["0"]
    assert [str(r) for r in w] == ["1.7724538509055160"]

    x, w = gauss_hermite(2, 17)
    assert [str(r)
            for r in x] == ["-0.70710678118654752", "0.70710678118654752"]
    assert [str(r)
            for r in w] == ["0.88622692545275801", "0.88622692545275801"]

    x, w = gauss_hermite(3, 17)
    assert [str(r)
            for r in x] == ["-1.2247448713915890", "0", "1.2247448713915890"]
    assert [str(r) for r in w] == [
        "0.29540897515091934",
        "1.1816359006036774",
        "0.29540897515091934",
    ]

    x, w = gauss_hermite(4, 17)
    assert [str(r) for r in x] == [
        "-1.6506801238857846",
        "-0.52464762327529032",
        "0.52464762327529032",
        "1.6506801238857846",
    ]
    assert [str(r) for r in w] == [
        "0.081312835447245177",
        "0.80491409000551284",
        "0.80491409000551284",
        "0.081312835447245177",
    ]

    x, w = gauss_hermite(5, 17)
    assert [str(r) for r in x] == [
        "-2.0201828704560856",
        "-0.95857246461381851",
        "0",
        "0.95857246461381851",
        "2.0201828704560856",
    ]
    assert [str(r) for r in w] == [
        "0.019953242059045913",
        "0.39361932315224116",
        "0.94530872048294188",
        "0.39361932315224116",
        "0.019953242059045913",
    ]
def test_hermite():
    x, w = gauss_hermite(1, 17)
    assert [str(r) for r in x] == ['0']
    assert [str(r) for r in w] == ['1.7724538509055160']

    x, w = gauss_hermite(2, 17)
    assert [str(r) for r in x] == [
            '-0.70710678118654752',
            '0.70710678118654752']
    assert [str(r) for r in w] == [
            '0.88622692545275801',
            '0.88622692545275801']

    x, w = gauss_hermite(3, 17)
    assert [str(r) for r in x] == [
            '-1.2247448713915890',
            '0',
            '1.2247448713915890']
    assert [str(r) for r in w] == [
            '0.29540897515091934',
            '1.1816359006036774',
            '0.29540897515091934']

    x, w = gauss_hermite(4, 17)
    assert [str(r) for r in x] == [
            '-1.6506801238857846',
            '-0.52464762327529032',
            '0.52464762327529032',
            '1.6506801238857846']
    assert [str(r) for r in w] == [
            '0.081312835447245177',
            '0.80491409000551284',
            '0.80491409000551284',
            '0.081312835447245177']

    x, w = gauss_hermite(5, 17)
    assert [str(r) for r in x] == [
            '-2.0201828704560856',
            '-0.95857246461381851',
            '0',
            '0.95857246461381851',
            '2.0201828704560856']
    assert [str(r) for r in w] == [
            '0.019953242059045913',
            '0.39361932315224116',
            '0.94530872048294188',
            '0.39361932315224116',
            '0.019953242059045913']
Пример #4
0
def test_hermite_precise():
    x, w = gauss_hermite(3, 40)
    assert [str(r) for r in x] == [
        '-1.224744871391589049098642037352945695983',
        '0',
        '1.224744871391589049098642037352945695983']
    assert [str(r) for r in w] == [
        '0.2954089751509193378830279138901908637996',
        '1.181635900603677351532111655560763455198',
        '0.2954089751509193378830279138901908637996']
def test_hermite_precise():
    x, w = gauss_hermite(3, 40)
    assert [str(r) for r in x] == [
        '-1.224744871391589049098642037352945695983',
        '0',
        '1.224744871391589049098642037352945695983']
    assert [str(r) for r in w] == [
        '0.2954089751509193378830279138901908637996',
        '1.181635900603677351532111655560763455198',
        '0.2954089751509193378830279138901908637996']
Пример #6
0
def _quad_coeffs_hq(M, collocation_type, digits=20):
    if M == 1:
        x = np.array([0.0])
        w = np.array([2.0])

    elif collocation_type == "gauss_legendre":
        from sympy.integrals.quadrature import gauss_legendre
        x, w = gauss_legendre(M, digits)

    elif collocation_type == "gauss_lobatto":
        from sympy.integrals.quadrature import gauss_lobatto
        x, w = gauss_lobatto(M, digits)

    elif collocation_type == "gauss_hermite":
        from sympy.integrals.quadrature import gauss_hermite
        x, w = gauss_hermite(M, 30)
        x = np.array(x, dtype=float)
        w = np.array(w, dtype=float)

    elif collocation_type == "gauss_jacobi":
        from sympy.integrals.quadrature import gauss_jacobi
        x, w = gauss_jacobi(M, 0, 0, 30)
        x = np.array(x, dtype=float)
        w = np.array(w, dtype=float)

    elif collocation_type == "gauss_chebyshev_u":
        from sympy.integrals.quadrature import gauss_chebyshev_u
        x, w = gauss_chebyshev_u(M, 30)
        x = np.array(x, dtype=float)
        w = np.array(w, dtype=float)

    elif collocation_type == "gauss_chebyshev_t":
        from sympy.integrals.quadrature import gauss_chebyshev_t
        x, w = gauss_chebyshev_t(M, 30)
        x = np.array(x, dtype=float)
        w = np.array(w, dtype=float)

    else:
        raise Exception("Unknown collocation method '" +
                        str(collocation_type) + "'")

    assert len(x) == M

    return x, w