test_line_orthopy.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:orthopy 作者: nschloe 项目源码 文件源码
def test_compute_moments():
    moments = orthopy.line.compute_moments(lambda x: 1, -1, +1, 5)
    assert (
        moments == [2, 0, sympy.Rational(2, 3), 0, sympy.Rational(2, 5)]
        ).all()

    moments = orthopy.line.compute_moments(
            lambda x: 1, -1, +1, 5,
            polynomial_class=orthopy.line.legendre
            )
    assert (moments == [2, 0, 0, 0, 0]).all()

    # Example from Gautschi's "How to and how not to" article
    moments = orthopy.line.compute_moments(
            lambda x: sympy.exp(-x**3/3),
            0, sympy.oo,
            5
            )

    reference = [
        3**sympy.Rational(n-2, 3) * sympy.gamma(sympy.Rational(n+1, 3))
        for n in range(5)
        ]

    assert numpy.all([
        sympy.simplify(m - r) == 0
        for m, r in zip(moments, reference)
        ])
    return
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号