使用 Python 中的 NumPy 对 Hermite 级数进行微分,并使用标量乘以每个微分


Hermite_e 级数也称为概率论中的 Hermite 多项式或物理学中的 Hermite 多项式。它在数学中可用,用于计算加权 Hermite 多项式的和。在量子力学的一些特定情况下,Hermite_e 级数的权重函数为 e^(−x^2)。

计算 Hermite_e 级数

以下是 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 阶导数。

在 NumPy 库中,我们有一个名为 polynomial.hermite.hermder() 的函数,用于对 Hermite 级数进行微分,并使用标量乘以每个微分。

语法

以下是 polynomial.hermite.hermder() 的语法 -

np.polynomial.hermite.hermder(coefficients,derivate_range,scalar)

示例

在以下示例中,我们将通过在 hermite.hermder() 函数中定义为“scl”的标量值乘以微分后的 Hermite 级数来乘以它。

import numpy as np
from numpy.polynomial import hermite
coefficients = np.arange(-10,14,2).reshape(2,3,2)
print("The coefficient values:",coefficients)
diff_coefficicents = hermite.hermder(coefficients,m = 1,scl = 3)
print("The derivative of the coefficient values:",diff_coefficicents)

输出

The coefficient values: [[[-10  -8]
  [ -6  -4]
  [ -2   0]]

 [[  2   4]
  [  6   8]
  [ 10  12]]]
The derivative of the coefficient values: [[[12. 24.]
  [36. 48.]
  [60. 72.]]]

示例

在以下示例中,我们将为系数创建 Hermite 级数的微分,这些系数采用 2 维数组格式。

import numpy as np
from numpy.polynomial import hermite
coefficients = np.arange(-40,14,4).reshape(7,2)
print("The coefficient values:",coefficients)
diff_coefficicents = hermite.hermder(coefficients,m = 2,scl = 1)
print("The 2nd order derivative of the coefficient values:",diff_coefficicents) 

输出

The coefficient values: [[-40 -36]
 [-32 -28]
 [-24 -20]
 [-16 -12]
 [ -8  -4]
 [  0   4]
 [  8  12]]
The The 2nd order derivative of the coefficient values: [[-192. -160.]
 [-384. -288.]
 [-384. -192.]
 [   0.  320.]
 [ 960. 1440.]]

示例

在以下示例中,我们使用 NumPy 库中的 hermite.hermder() 函数计算 Hermite 级数的微分。

import numpy as np
def diff_hermite(coefficients,m,scl):
   from numpy.polynomial import hermite
   print("The coefficient values:",coefficients)
   diff_coefficicents = hermite.hermder(coefficients,m,scl)
   print("The 2nd order derivative of the coefficient values:",diff_coefficicents)
diff_hermite(np.linspace(-10,20,20),3,-3)

输出

The coefficient values: [-10. -8.42105263  -6.84210526  -5.26315789  -3.68421053
  -2.10526316  -0.52631579   1.05263158   2.63157895   4.21052632
   5.78947368   7.36842105   8.94736842  10.52631579  12.10526316
  13.68421053  15.26315789  16.84210526  18.42105263  20.        ]
The 2nd order derivative of the coefficient values: [ 6.82105263e+03  1.90989474e+04  2.72842105e+04  1.36421053e+04
 -4.77473684e+04 -1.90989474e+05 -4.58374737e+05 -9.00378947e+05
 -1.57566316e+06 -2.55107368e+06 -3.90164211e+06 -5.71058526e+06
 -8.06930526e+06 -1.10773895e+07 -1.48426105e+07 -1.94809263e+07
 -2.51164800e+07]

示例

在以下示例中,我们通过传递默认标量值和导数阶数来计算 Hermite 级数的微分。

import numpy as np
def diff_hermite(coefficients):
   from numpy.polynomial import hermite
   print("The coefficient values:",coefficients)
   diff_coefficicents = hermite.hermder(coefficients)
   print("The default order of derivative of the coefficient values:",diff_coefficicents)
diff_hermite(np.linspace(-10,20,20))

输出

The coefficient values: [-10.          -8.42105263  -6.84210526  -5.26315789  -3.68421053
  -2.10526316  -0.52631579   1.05263158   2.63157895   4.21052632
   5.78947368   7.36842105   8.94736842  10.52631579  12.10526316
  13.68421053  15.26315789  16.84210526  18.42105263  20.        ]
The default order of derivative of the coefficient values: [-16.84210526 -27.36842105 -31.57894737 -29.47368421 -21.05263158
  -6.31578947  14.73684211  42.10526316  75.78947368 115.78947368
 162.10526316 214.73684211 273.68421053 338.94736842 410.52631579
 488.42105263 572.63157895 663.15789474 760.        ]

更新于: 2023-10-31

57 次查看

开启您的 职业生涯

通过完成课程获得认证

开始学习
广告