[英]Getting the derivatives of Legendre polynomials in Python
我知道这是一个老问题,但仍然没有关于如何使用 numpy/scipy 计算导数的答案。
这就是它仅适用于 numpy 和 scipy 的方式:
from scipy.special import legendre
import numpy as np
n = 2 # degree of Legendre polynomial
poly = legendre(n) # coefficients of n^th degree Legendre polynomial
polyd= poly.deriv() # coefficients of derivative of n^th degree Legendre Polynomial
x = np.linspace(0,1,10000) # arbitrary coordinates
evald = np.polyval(polyd,x) # evaluate derivative at desired coordinates(s)
上面接受的答案也包含一个小错误(我无法评论但也许有人可以编辑答案):导数应该读作P2' = 3*x
如果您只需要P2
、 P4
和P6
的导数,那很容易用手计算然后写下来作为代码......例如
P2 = .5 * (3 * x^2 - 1)
所以:
P2' = .75 * x
您可以在 python 中将其编写为:
def P2_deriv(x):
return .75 * x
事情并没有比这快很多;-)。 如果你需要任意勒让德多项式,那么......事情开始变得有点棘手......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.