在 Python 中計算厄米特級數的根


要計算厄米特級數的根,請在 Python Numpy 中使用 hermite.hermroots() 方法。該方法返回級數根的陣列。如果所有根都是實數,則輸出也是實數,否則為複數。引數 c 是一個 1 維繫數陣列。

根的估計值是作為伴隨矩陣的特徵值獲得的,遠離複平面原點的根由於此類值的級數數值不穩定而可能存在較大誤差。具有大於 1 的重數的根也會顯示更大的誤差,因為該級數在這些點附近的數值對根的誤差相對不敏感。可以透過牛頓法進行幾次迭代來改進靠近原點的孤立根。

步驟

首先,匯入所需的庫 -

from numpy.polynomial import hermite as H

要計算厄米特級數的根,請在 Python Numpy 中使用 hermite.hermroots() 方法 -

print("Result...\n",H.hermroots((-1, 0, 1)))

獲取資料型別 -

print("\nType...\n",H.hermroots((-1, 0, 1)).dtype)

獲取形狀 -

print("\nShape...\n",H.hermroots((-1, 0, 1)).shape)

示例

from numpy.polynomial import hermite as H

# To compute the roots of a Hermite series., use the hermite.hermroots() method in Python Numpy.
# The method returns an Array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex..

# The parameter, c is a 1-D array of coefficients.
print("Result...\n",H.hermroots((-1, 0, 1)))

# Get the datatype
print("\nType...\n",H.hermroots((-1, 0, 1)).dtype)

# Get the shape
print("\nShape...\n",H.hermroots((-1, 0, 1)).shape)

輸出

Result...
   [-0.8660254 0.8660254]

Type...
float64

Shape...
(2,)

更新於: 2022-03-04

122 次檢視

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.