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
评论列表
文章目录