示例#1
0
def test_chebyshev_u():
    x, w = gauss_chebyshev_u(1, 17)
    assert [str(r) for r in x] == ["0"]
    assert [str(r) for r in w] == ["1.5707963267948966"]

    x, w = gauss_chebyshev_u(2, 17)
    assert [str(r)
            for r in x] == ["0.50000000000000000", "-0.50000000000000000"]
    assert [str(r)
            for r in w] == ["0.78539816339744831", "0.78539816339744831"]

    x, w = gauss_chebyshev_u(3, 17)
    assert [str(r) for r in x
            ] == ["0.70710678118654752", "0", "-0.70710678118654752"]
    assert [str(r) for r in w] == [
        "0.39269908169872415",
        "0.78539816339744831",
        "0.39269908169872415",
    ]

    x, w = gauss_chebyshev_u(4, 17)
    assert [str(r) for r in x] == [
        "0.80901699437494742",
        "0.30901699437494742",
        "-0.30901699437494742",
        "-0.80901699437494742",
    ]
    assert [str(r) for r in w] == [
        "0.21707871342270599",
        "0.56831944997474231",
        "0.56831944997474231",
        "0.21707871342270599",
    ]

    x, w = gauss_chebyshev_u(5, 17)
    assert [str(r) for r in x] == [
        "0.86602540378443865",
        "0.50000000000000000",
        "0",
        "-0.50000000000000000",
        "-0.86602540378443865",
    ]
    assert [str(r) for r in w] == [
        "0.13089969389957472",
        "0.39269908169872415",
        "0.52359877559829887",
        "0.39269908169872415",
        "0.13089969389957472",
    ]
示例#2
0
def test_chebyshev_u():
    x, w = gauss_chebyshev_u(1, 17)
    assert [str(r) for r in x] == ['0']
    assert [str(r) for r in w] == ['1.5707963267948966']

    x, w = gauss_chebyshev_u(2, 17)
    assert [str(r) for r in x] == [
            '0.50000000000000000',
            '-0.50000000000000000']
    assert [str(r) for r in w] == [
            '0.78539816339744831',
            '0.78539816339744831']

    x, w = gauss_chebyshev_u(3, 17)
    assert [str(r) for r in x] == [
            '0.70710678118654752',
            '0',
            '-0.70710678118654752']
    assert [str(r) for r in w] == [
            '0.39269908169872415',
            '0.78539816339744831',
            '0.39269908169872415']

    x, w = gauss_chebyshev_u(4, 17)
    assert [str(r) for r in x] == [
            '0.80901699437494742',
            '0.30901699437494742',
            '-0.30901699437494742',
            '-0.80901699437494742']
    assert [str(r) for r in w] == [
            '0.21707871342270599',
            '0.56831944997474231',
            '0.56831944997474231',
            '0.21707871342270599']

    x, w = gauss_chebyshev_u(5, 17)
    assert [str(r) for r in x] == [
            '0.86602540378443865',
            '0.50000000000000000',
            '0',
            '-0.50000000000000000',
            '-0.86602540378443865']
    assert [str(r) for r in w] == [
            '0.13089969389957472',
            '0.39269908169872415',
            '0.52359877559829887',
            '0.39269908169872415',
            '0.13089969389957472']
def test_chebyshev_u():
    x, w = gauss_chebyshev_u(1, 17)
    assert [str(r) for r in x] == ['0']
    assert [str(r) for r in w] == ['1.5707963267948966']

    x, w = gauss_chebyshev_u(2, 17)
    assert [str(r) for r in x] == [
            '0.50000000000000000',
            '-0.50000000000000000']
    assert [str(r) for r in w] == [
            '0.78539816339744831',
            '0.78539816339744831']

    x, w = gauss_chebyshev_u(3, 17)
    assert [str(r) for r in x] == [
            '0.70710678118654752',
            '0',
            '-0.70710678118654752']
    assert [str(r) for r in w] == [
            '0.39269908169872415',
            '0.78539816339744831',
            '0.39269908169872415']

    x, w = gauss_chebyshev_u(4, 17)
    assert [str(r) for r in x] == [
            '0.80901699437494742',
            '0.30901699437494742',
            '-0.30901699437494742',
            '-0.80901699437494742']
    assert [str(r) for r in w] == [
            '0.21707871342270599',
            '0.56831944997474231',
            '0.56831944997474231',
            '0.21707871342270599']

    x, w = gauss_chebyshev_u(5, 17)
    assert [str(r) for r in x] == [
            '0.86602540378443865',
            '0.50000000000000000',
            '0',
            '-0.50000000000000000',
            '-0.86602540378443865']
    assert [str(r) for r in w] == [
            '0.13089969389957472',
            '0.39269908169872415',
            '0.52359877559829887',
            '0.39269908169872415',
            '0.13089969389957472']
示例#4
0
def test_chebyshev_u_precise():
    x, w = gauss_chebyshev_u(3, 40)
    assert [str(r) for r in x] == [
        '0.7071067811865475244008443621048490392848',
        '0',
        '-0.7071067811865475244008443621048490392848']
    assert [str(r) for r in w] == [
        '0.3926990816987241548078304229099378605246',
        '0.7853981633974483096156608458198757210493',
        '0.3926990816987241548078304229099378605246']
def test_chebyshev_u_precise():
    x, w = gauss_chebyshev_u(3, 40)
    assert [str(r) for r in x] == [
            '0.7071067811865475244008443621048490392848',
            '0',
            '-0.7071067811865475244008443621048490392848']
    assert [str(r) for r in w] == [
            '0.3926990816987241548078304229099378605246',
            '0.7853981633974483096156608458198757210493',
            '0.3926990816987241548078304229099378605246']
示例#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