对 Hermite_e 级数进行微分并在 Python 中设置导数
Hermite_e 级数也称为概率论者的 Hermite 多项式或物理学家的 Hermite 多项式,它存在于数学中,用于对加权 Hermite 多项式求和。在量子力学的某些特定情况下,Hermite_e 级数的权重函数给定为 e^(−x^2)。以下是 Hermite_e 级数的公式。
H_n(x) = (-1)^n e^(x^2/2) d^n/dx^n(e^(-x^2/2))
其中,
H_n(x) 是 n 次 Hermite 多项式
x 是自变量
d^n/dx^n 表示关于 x 的 n 阶导数。
定义系数
要执行 Hermite_e 级数的微分,首先我们必须定义该级数的系数。在 Numpy 库中,我们在多项式包中有一个名为 hermite_e 的模块,用于生成指定次数的 Hermite 多项式,然后我们可以将每个多项式乘以相应的系数并将它们加起来以得到级数。
语法
以下是语法。
np.polynomial.hermite_e.hermval(series, coefficients) np.polynomial.hermite_e.hermdifn(series, coefficients, derivate_degree)
示例
在这个例子中,我们将使用 **polynomial.hermite_e.hermval()** 函数生成 Hermite_e 级数的微分,方法是传递元素和系数的序列,并且为了计算级数的导数,我们有函数 **polynomial.hermite_e.hermdifn()**。
import numpy as np from numpy.polynomial import hermite coefficients = [-2,-4,7,-1,5] x = np.linspace(-5, 5, 20) series = hermite.hermval(x, coefficients) print("The Hermite_e series of the given cofficients and series of elements:",series) derivatives = hermite.hermder(series, m=2,axis = 0) print("The derivatives of the generated hermite_e series:",derivatives)
输出
The Hermite_e series of the given cofficients and series of elements: [ 4.57240000e+04 2.85437908e+04 1.66401342e+04 8.82740375e+03 4.06730185e+03 1.46885923e+03 2.88435202e+02 -7.02824257e+01 -5.62773152e+01 2.87953898e+01 3.06090653e+01 -5.78343935e+01 -9.62045718e+01 2.03157465e+02 1.27523917e+03 3.70235652e+03 8.21415400e+03 1.56876046e+04 2.71470100e+04 4.37640000e+04] The derivatives of the generated hermite_e series: [ 1.33121073e+05 2.11857690e+05 1.95230489e+05 1.17508739e+05 3.46122243e+04 -1.18074475e+04 -1.26061186e+04 8.29307228e+03 1.10192635e+04 -2.54471332e+04 -5.07960139e+04 1.26770258e+05 9.28374116e+05 3.10997948e+06 7.88558784e+06 1.70681138e+07 3.32279402e+07 5.98691520e+07]
示例
在上面的示例中,我们将 hermder() 函数中的轴作为 0 传递,因为元素序列是一维数组,但这里我们使用的是二维数组,因此轴可以指定为 axis = 1 或 axis = 0。
import numpy as np from numpy.polynomial import hermite coefficients = [-2,-4,7,-1,5] x = np.linspace(-5, 5, 20).reshape(5,4) series = hermite.hermval(x, coefficients) print("The Hermite_e series of the given cofficients and series of elements:",series) derivatives = hermite.hermder(series, m=2,axis = 1) print("The derivatives of the generated hermite_e series:",derivatives)
输出
The Hermite_e series of the given cofficients and series of elements: [[ 4.57240000e+04 2.85437908e+04 1.66401342e+04 8.82740375e+03] [ 4.06730185e+03 1.46885923e+03 2.88435202e+02 -7.02824257e+01] [-5.62773152e+01 2.87953898e+01 3.06090653e+01 -5.78343935e+01] [-9.62045718e+01 2.03157465e+02 1.27523917e+03 3.70235652e+03] [ 8.21415400e+03 1.56876046e+04 2.71470100e+04 4.37640000e+04]] The derivatives of the generated hermite_e series: [[ 1.33121073e+05 2.11857690e+05] [ 2.30748162e+03 -1.68677822e+03] [ 2.44872522e+02 -1.38802544e+03] [ 1.02019134e+04 8.88565565e+04] [ 2.17176080e+05 1.05033600e+06]]
示例
在下面的示例中,当我们将参数 axis = 2 传递给二维数组的元素序列的 hermder() 函数时,它将引发轴错误,因为轴应该为 0 或 1。
import numpy as np from numpy.polynomial import hermite coefficients = [-2,-4,7,-1,5] x = np.linspace(-5, 5, 20).reshape(5,4) series = hermite.hermval(x, coefficients) print("The Hermite_e series of the given cofficients and series of elements:",series) derivatives = hermite.hermder(series, m=2,axis = 2) print("The derivatives of the generated hermite_e series:",derivatives)
输出
The Hermite_e series of the given cofficients and series of elements: [[ 4.57240000e+04 2.85437908e+04 1.66401342e+04 8.82740375e+03] [ 4.06730185e+03 1.46885923e+03 2.88435202e+02 -7.02824257e+01] [-5.62773152e+01 2.87953898e+01 3.06090653e+01 -5.78343935e+01] [-9.62045718e+01 2.03157465e+02 1.27523917e+03 3.70235652e+03] [ 8.21415400e+03 1.56876046e+04 2.71470100e+04 4.37640000e+04]] --------------------------------------------------------------------------- AxisError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_3956\2241814449.py in <module> 5 series = hermite.hermval(x, coefficients) 6 print("The Hermite_e series of the given cofficients and series of elements:",series) ----> 7 derivatives = hermite.hermder(series, m=2,axis = 2) 8 print("The derivatives of the generated hermite_e series:",derivatives) ~\anaconda3\lib\site-packages\numpy\polynomial\hermite.py in hermder(c, m, scl, axis) 657 if cnt < 0: 658 raise ValueError("The order of derivation must be non-negative") --> 659 iaxis = normalize_axis_index(iaxis, c.ndim) 660 661 if cnt == 0: AxisError: axis 2 is out of bounds for array of dimension 2
示例
以下是另一个示例 -
import numpy as np from numpy.polynomial import hermite_e as H # Create an array of coefficients c = np.array([1,2,3,4]) # Display the array print("Our Array...\n",c) # Check the Dimensions print("\nDimensions of our Array...\n",c.ndim) # Get the Datatype print("\nDatatype of our Array object...\n",c.dtype) # Get the Shape print("\nShape of our Array object...\n",c.shape) # To differentiate a Hermite_e series, use the hermite_e.hermeder() method in Python print("\nResult...\n",H.hermeder(c, 3))
输出
Our Array... [1 2 3 4] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (4,) Result... [24.]
广告