【问题标题】:Generating Legendre Polynomials in Sympy在 Sympy 中生成勒让德多项式
【发布时间】:2015-05-09 08:59:52
【问题描述】:

我有一个项目,我想使用一组相关的 Legendre 多项式。我的想法是使用 sympy 生成一组度数和阶数的代码。

我可以像文档中解释的那样计算特定值:http://docs.sympy.org/dev/modules/mpmath/functions/orthogonal.html#legenp

我无法获得多项式的系数。

>>> from sympy import Symbol
x
>>> x = Symbol('x')

>>> from sympy.mpmath import *

>>> legenp(1, 0, x)

TypeError: cannot create mpf from x

我对 sympy 或其他 CAS 都不是很有经验,所以我想肯定有一种我不知道的方法来做到这一点。

【问题讨论】:

    标签: python math sympy


    【解决方案1】:

    你走错了。来自the documentation

    勒让德多项式的系数可以使用 n 次泰勒展开恢复:

    >>> for n in range(5):
    ...     nprint(chop(taylor(lambda x: legendre(n, x), 0, n)))
    ...
    [1.0]
    [0.0, 1.0]
    [-0.5, 0.0, 1.5]
    [0.0, -1.5, 0.0, 2.5]
    [0.375, 0.0, -3.75, 0.0, 4.375]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多