在 Python 中計算具有給定復根的 Hermite 級數的根
要計算 Hermite 級數的根,可以使用 Python Numpy 中的 hermite.hermroots() 方法。該方法返回級數根的陣列。如果所有根都是實數,則輸出也是實數,否則為複數。引數 c 是一個 1 維的係數陣列。
根的估計值是作為伴隨矩陣的特徵值獲得的,遠離複平面原點的根由於此類值的級數數值不穩定而可能存在較大的誤差。多重性大於 1 的根也會顯示更大的誤差,因為該點附近級數的值對根的誤差相對不敏感。可以透過牛頓法迭代幾次來改進靠近原點的孤立根。
步驟
首先,匯入所需的庫 -
from numpy.polynomial import hermite as H
要計算 Hermite 級數的根,可以使用 Python Numpy 中的 hermite.hermroots() 方法 -
j = complex(0,1)
print("Result...\n",H.hermroots((-j, j)))獲取資料型別 -
print("\nType...\n",H.hermroots((-j, j)).dtype)獲取形狀 -
print("\nShape...\n",H.hermroots((-j, j)).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.
j = complex(0,1)
print("Result...\n",H.hermroots((-j, j)))
# Get the datatype
print("\nType...\n",H.hermroots((-j, j)).dtype)
# Get the shape
print("\nShape...\n",H.hermroots((-j, j)).shape)輸出
Result... [0.5+0.j] Type... complex128 Shape... (1,)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP