在Python中计算拉盖尔级数的根

在Python中计算拉盖尔级数的根

要计算拉盖尔级数的根,在Python的Numpy中使用laguerre.lagroots()方法。该方法返回一个根的数组。如果所有的根都是实数,则结果也是实数,否则是复数。

根的估计值是通过伴随矩阵的特征值得到的,远离复平面原点的根可能会由于该值的数值不稳定性而产生较大误差。多重度大于1的根也会显示较大误差,因为该值附近的级数相对于根的误差不敏感。靠近原点的孤立根可以通过对牛顿法进行几次迭代来改进。

步骤

首先,导入所需的库 –

from numpy.polynomial import laguerre as L

要计算Laguerre级数的根,可以使用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,)

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程