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