在Python中计算Hermite级数的根
要计算Hermite级数的根,在Python的Numpy中使用hermite.hermroots()方法。该方法返回一个包含级数根的数组。如果所有的根都是实根,则输出也是实数,否则是复数。参数c是一维数组,包含系数。
根的估计值是通过伴随矩阵的特征值获得的。离复平面原点较远的根可能由于级数在这些值上的数值不稳定性而产生较大的误差。具有大于1重根的根也会显示出较大的误差,因为级数在这些点附近的值对于根的误差相对不敏感。靠近原点的孤立根可以通过几次牛顿迭代法进行改进。
步骤
首先,导入所需的库-
from numpy.polynomial import hermite as H
计算 Hermite 级数的根,请使用 Python Numpy 中的 hermite.hermroots() 方法。
print("Result...\n",H.hermroots((-1, 0, 1)))
获取数据类型
print("\nType...\n",H.hermroots((-1, 0, 1)).dtype)
获取形状 –
print("\nShape...\n",H.hermroots((-1, 0, 1)).shape)
示例
from numpy.polynomial import hermite as H
# To compute the roots of a Hermite series., use the hermite.hermroots() 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...\n",H.hermroots((-1, 0, 1)))
# Get the datatype
print("\nType...\n",H.hermroots((-1, 0, 1)).dtype)
# Get the shape
print("\nShape...\n",H.hermroots((-1, 0, 1)).shape)
输出
Result...
[-0.8660254 0.8660254]
Type...
float64
Shape...
(2,)