用 Python 計算勒讓德級數的根


要計算勒讓德級數的根,請在 Python 中使用 polynomial.legendre.legroots() 方法。該方法返回級數根的陣列。如果所有根均為實數,則輸出也將為實數,否則為複數。引數 c 是一個 1-D 係數陣列。

步驟

首先,匯入所需的庫 −

from numpy.polynomial import legendre as L

要計算勒讓德級數的根,請在 Python 中使用 polynomial.legendre.legroots() 方法 −

print("Result...\n",L.legroots((0, 1, 2)))

獲取資料型別 −

print("\nType...\n",L.legroots((0, 1, 2)).dtype)

獲取形狀 −

print("\nShape...\n",L.legroots((0, 1, 2)).shape)

示例

from numpy.polynomial import legendre as L

# To compute the roots of a Legendre series, use the polynomial.legendre.legroots() method in Python
print("Result...\n",L.legroots((0, 1, 2)))

# Get the datatype
print("\nType...\n",L.legroots((0, 1, 2)).dtype)

# Get the shape
print("\nShape...\n",L.legroots((0, 1, 2)).shape)

輸出

Result...
   [-0.76759188 0.43425855]

Type...
float64

Shape...
(2,)

更新於: 09-Mar-2022

291 人次瀏覽

啟動您的 職業生涯

透過完成課程來獲得認證

開始
廣告
© . All rights reserved.