[英]Generating Legendre Polynomials in Sympy
我有一个项目,我想使用一组关联的Legendre多项式。 我的想法是通过使用sympy为一组学位和命令生成代码。
我可以得到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都不是很有经验,所以我想一定有一种我不知道的方法。
您正在错误地处理它。 从文档中
勒让德多项式的系数可以使用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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.