[英]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.