main.py 文件源码

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

项目:orthopy 作者: nschloe 项目源码 文件源码
def compute_moments(w, a, b, n, polynomial_class=lambda k, x: x**k):
    '''Symbolically calculate the first n moments

      int_a^b w(x) P_k(x) dx

    where `P_k` is the `k`th polynomials of a specified class. The default
    settings are monomials, i.e., `P_k(x)=x^k`, but you can provide any
    function with the signature `p(k, x)`, e.g.,
    `sympy.polys.orthopolys.legendre_poly` scaled by the inverse of its leading
    coefficient `(2n)! / 2^n / (n!)^2`.
    '''
    x = sympy.Symbol('x')
    return numpy.array([
        sympy.integrate(w(x) * polynomial_class(k, x), (x, a, b))
        for k in range(n)
        ])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号