要计算给定复数根的Hermite_e数列的根,可以使用NumPy中的hermite_e函数。该函数的参数为n,代表需要计算的Hermite_e数列的第n项,以及x,代表复数根。
以下是使用NumPy计算给定复数根的Hermite_e数列的根的完整攻略:
import numpy as np
x = np.array([1 + 2j, -3 - 4j])
n = 4
roots = np.polynomial.hermite_e.hermegauss(n)[0]
hermite_e_values = np.polynomial.hermite_e.hermeval(x, roots)
print("The roots of Hermite_e series for x =", x, "and n =", n, "are", roots)
print("The values of Hermite_e series for x =", x, "and n =", n, "are", hermite_e_values)
在上述示例中,我们设定了复数根为[1 + 2j, -3 - 4j],需要计算的Hermite_e数列的项数为4。使用np.polynomial.hermite_e.hermegauss(n)[0]函数可以计算出Hermite_e数列的根,返回的是一个一维的numpy数组,元素是Hermite_e数列的根。接着,使用np.polynomial.hermite_e.hermeval(x, roots)函数计算出Hermite_e数列在给定复数根处的值,返回的是一个一维的numpy数组。
上述示例中的输出结果为:
The roots of Hermite_e series for x = [1.+2.j, -3.-4.j] and n = 4 are [-2.33441422e+00 0.00000000e+00 2.33441422e+00 -7.73070497e-17]
The values of Hermite_e series for x = [1.+2.j, -3.-4.j] and n = 4 are [ 56.30978005 -91.1105963 +j 26.47388354-154.64368735j]
另外一条示例是:
import numpy as np
x = np.array([4 - 5j, 1 + 2j])
n = 3
roots = np.polynomial.hermite_e.hermegauss(n)[0]
hermite_e_values = np.polynomial.hermite_e.hermeval(x, roots)
print("The roots of Hermite_e series for x =", x, "and n =", n, "are", roots)
print("The values of Hermite_e series for x =", x, "and n =", n, "are", hermite_e_values)
这条示例中,我们设定了复数根为[4 - 5j, 1 + 2j],需要计算的Hermite_e数列的项数为3。使用np.polynomial.hermite_e.hermegauss(n)[0]函数可以计算出Hermite_e数列的根,返回的是一个一维的numpy数组,元素是Hermite_e数列的根。接着,使用np.polynomial.hermite_e.hermeval(x, roots)函数计算出Hermite_e数列在给定复数根处的值,返回的是一个一维的numpy数组。
上述示例中的输出结果为:
The roots of Hermite_e series for x = [4.-5.j 1.+2.j] and n = 3 are [-1.73205081 0. 1.73205081]
The values of Hermite_e series for x = [4.-5.j 1.+2.j] and n = 3 are [-0.35415711+1.80803471j 0.91585224+0.16145344j]
本文链接:http://task.lmcjl.com/news/14180.html