當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python SciPy special.eval_legendre用法及代碼示例


本文簡要介紹 python 語言中 scipy.special.eval_legendre 的用法。

用法:

scipy.special.eval_legendre(n, x, out=None) = <ufunc 'eval_legendre'>#

在某一點計算勒讓德多項式。

Legendre多項式可以通過高斯超幾何函數 定義為

是整數時,結果是度數的多項式 。有關詳細信息,請參閱 [AS] 中的 22.5.49。

參數

n array_like

多項式的次數。如果不是整數,則通過與高斯超幾何函數的關係確定結果。

x array_like

計算勒讓德多項式的點

out ndarray,可選

函數值的可選輸出數組

返回

P 標量或 ndarray

勒讓德多項式的值

參考

[AS]

Milton Abramowitz 和 Irene A. Stegun 合編。帶有公式、圖表和數學表格的數學函數手冊。紐約:多佛,1972 年。

例子

>>> import numpy as np
>>> from scipy.special import eval_legendre

在 x = 0 處計算 zero-order Legendre 多項式

>>> eval_legendre(0, 0)
1.0

計算 -1 和 1 之間的 first-order Legendre 多項式

>>> X = np.linspace(-1, 1, 5)  # Domain of Legendre polynomials
>>> eval_legendre(1, X)
array([-1. , -0.5,  0. ,  0.5,  1. ])

在 x = 0 處計算 0 到 4 階的勒讓德多項式

>>> N = range(0, 5)
>>> eval_legendre(N, 0)
array([ 1.   ,  0.   , -0.5  ,  0.   ,  0.375])

繪製 0 到 4 階的勒讓德多項式

>>> X = np.linspace(-1, 1)
>>> import matplotlib.pyplot as plt
>>> for n in range(0, 5):
...     y = eval_legendre(n, X)
...     plt.plot(X, y, label=r'$P_{}(x)$'.format(n))
>>> plt.title("Legendre Polynomials")
>>> plt.xlabel("x")
>>> plt.ylabel(r'$P_n(x)$')
>>> plt.legend(loc='lower right')
>>> plt.show()
scipy-special-eval_legendre-1.png

相關用法


注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.special.eval_legendre。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。