在Python中計算拉蓋爾級數的根
要計算拉蓋爾級數的根,可以使用Python Numpy中的`laguerre.lagroots()`方法。該方法返回一個包含級數根的陣列。如果所有根都是實數,則輸出也是實數,否則是複數。
根的估計值是作為伴隨矩陣的特徵值獲得的。遠離複平面原點的根由於級數在這些值的數值不穩定性而可能存在較大的誤差。具有大於1的重數的根也將顯示較大的誤差,因為在這些點附近級數的值對根的誤差相對不敏感。可以通過幾次牛頓法迭代來改進靠近原點的孤立根。
步驟
首先,匯入所需的庫:
from numpy.polynomial import laguerre as L
要計算拉蓋爾級數的根,可以使用Python Numpy中的`laguerre.lagroots()`方法:
print("Result...\n",L.lagroots([0, 1, 2]))獲取資料型別:
print("\nType...\n",L.lagroots([0, 1, 2]).dtype)獲取形狀:
print("\nShape...\n",L.lagroots([0, 1, 2]).shape)
示例
from numpy.polynomial import laguerre as L
# To Compute the roots of a Laguerre series, use the laguerre.lagroots() 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..
print("Result...\n",L.lagroots([0, 1, 2]))
# Get the datatype
print("\nType...\n",L.lagroots([0, 1, 2]).dtype)
# Get the shape
print("\nShape...\n",L.lagroots([0, 1, 2]).shape)輸出
Result... [0.69722436 4.30277564] Type... float64 Shape... (2,)
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP