在Python中计算具有给定复根的切比雪夫级数的根

在Python中计算具有给定复根的切比雪夫级数的根

要计算多项式的根,可以使用Python的NumPy库中的chebyshev.chebroots()方法。该方法返回级数的根的数组。如果所有的根都是实数,则输出也是实数,否则是复数。参数c是一个一维数组,包含系数。

根的估计值是通过伴随矩阵的特征值获得的,在复平面上远离原点的根可能有较大的误差,这是由于对于这些值级数的数值不稳定性所致。具有多重性大于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,)

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程