使用 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 次檢視

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告