在 Python 中計算具有給定復根的切比雪夫級數的根


要計算多項式的根,請在 Python Numpy 中使用 chebyshev.chebroots() 方法。該方法返回級數根的陣列。如果所有根都是實數,則輸出也是實數,否則為複數。引數 c 是一個 1-D 係數陣列。

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

步驟

首先,匯入所需的庫 -

from numpy.polynomial import chebyshev as C

要計算多項式的根,請在 Python Numpy 中使用 chebyshev.chebroots() 方法 -

j = complex(0,1)
print("Result (roots)...\n",C.chebroots((-j, j)))

獲取資料型別 -

print("\nType...\n",C.chebroots((-j, j)).dtype)

獲取形狀 -

print("\nShape...\n",C.chebroots((-j, j)).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.
j = complex(0,1)
print("Result (roots)...\n",C.chebroots((-j, j)))

# Get the datatype
print("\nType...\n",C.chebroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",C.chebroots((-j, j)).shape)

輸出

Result (roots)...
   [1.+0.j]

Type...
complex128

Shape...
(1,)

更新於: 2022年3月2日

123 次瀏覽

啟動你的 職業生涯

透過完成課程獲得認證

開始學習
廣告

© . All rights reserved.