Ejemplo n.º 1
0
def test_laguerre_scheme(scheme):
    def integrate_exact(k):
        # \int_0^\infty x^k * exp(-x)
        return math.gamma(k + 1)

    degree = check_degree_1d(
        lambda poly: quadpy.line_segment.integrate(
            poly, numpy.array([[-1.0], [1.0]]), scheme), integrate_exact,
        scheme.degree + 1)
    assert degree == scheme.degree
    return
Ejemplo n.º 2
0
def test_hermite_scheme(scheme):
    def integrate_exact(k):
        # \int_-\infty^\infty x^k * exp(-x^2)
        return 0.5 * ((-1)**k + 1) * math.gamma(0.5 * (k + 1))

    degree = check_degree_1d(
        lambda poly: quadpy.line_segment.integrate(
            poly, numpy.array([[-1.0], [1.0]]), scheme), integrate_exact,
        scheme.degree + 1)
    assert degree == scheme.degree
    return
Ejemplo n.º 3
0
def test_cheb1_scheme(scheme):
    # \int_-1^1 x^k / sqrt(1 - x^2)
    # <https://github.com/nschloe/note-no-gamma>
    def integrate_exact(k):
        if k == 0:
            return numpy.pi
        elif k == 1:
            return 0
        return integrate_exact(k - 2) * (k - 1) / k

    degree = check_degree_1d(
        lambda poly: scheme.integrate(poly, numpy.array([[-1.0], [1.0]])),
        integrate_exact,
        scheme.degree + 1,
    )
    assert degree >= scheme.degree
Ejemplo n.º 4
0
def test_cheb2_scheme(scheme):
    def integrate_exact(k):
        # \int_-1^1 x^k * sqrt(1 - x^2)
        if k == 0:
            return 0.5 * numpy.pi
        if k % 2 == 1:
            return 0.0
        return (numpy.sqrt(numpy.pi) * ((-1)**k + 1) *
                math.gamma(0.5 * (k + 1)) / math.gamma(0.5 * k + 2) / 4)

    degree = check_degree_1d(
        lambda poly: scheme.integrate(poly, numpy.array([[-1.0], [1.0]])),
        integrate_exact,
        scheme.degree + 1,
    )
    assert degree >= scheme.degree
Ejemplo n.º 5
0
def test_cheb1_scheme(scheme):
    def integrate_exact(k):
        # \int_-1^1 x^k / sqrt(1 - x^2)
        if k == 0:
            return numpy.pi
        if k % 2 == 1:
            return 0.0
        return numpy.sqrt(numpy.pi) * ((-1)**k + 1) \
            * math.gamma(0.5*(k+1)) / math.gamma(0.5*k) \
            / k

    degree = check_degree_1d(
        lambda poly: quadpy.line_segment.integrate(
            poly, numpy.array([[-1.0], [1.0]]), scheme), integrate_exact,
        scheme.degree + 1)
    assert degree >= scheme.degree
    return