使用 NumPy 在 Python 中將一個 Hermite 級數除以另一個
Hermite 級數是數學技術之一,用於表示 Hermite 多項式的無限級數。Hermite 多項式被稱為正交多項式序列,是 Hermite 微分方程的解。
將一個 Hermite 級數除以另一個
Hermite 級數由以下等式給出。
f(x) = Σn=0^∞ cn Hn(x)
其中
Hn(x) 是第 n 個 Hermite 多項式
cn 是展開式中的第 n 個係數。
係數 cn 可以使用以下公式確定
cn = (1/$\mathrm{\surd}$(2^n n!))$\mathrm{\lmoustache}$ f(x) Hn(x) e^(−x^2/2) dx
示例
首先,讓我們使用 numpy 庫中的函式(即 **polynomial.hermite.poly2herm()**)建立 Hermite 級數。
import numpy as np
from numpy.polynomial import hermite as H
c = np.array([1, 2, 3, 4, 5])
print("Our Array...\n",c)
print("\nDimensions of our Array...\n",c.ndim)
print("\nDatatype of our Array object...\n",c.dtype)
print("\nShape of our Array object...\n",c.shape)
print("\nResult (polynomial to hermite)...\n",H.poly2herm(c))
輸出
Our Array... [1 2 3 4 5] Dimensions of our Array... 1 Datatype of our Array object... int32 Shape of our Array object... (5,) Result (polynomial to hermite)... [6.25 4. 4.5 0.5 0.3125]
示例
我們在 Numpy 庫中有一個名為 divide() 的函式,用於將 Hermite 級數除以另一個 Hermite 級數。以下是一個示例。
import numpy as np
from numpy.polynomial import hermite as H
h = np.array([1, 2, 3, 4, 5])
print("Our Array...\n",h)
print("\nDimensions of our Array...\n",h.ndim)
print("\nDatatype of our Array object...\n",h.dtype)
print("\nShape of our Array object...\n",h.shape)
print("\nResult (polynomial to hermite)...\n",H.poly2herm(h))
divide_hermite = np.divide(h,h)
print("The output of dividing the hermite series by another:",divide_hermite)
輸出
Our Array... [1 2 3 4 5] Dimensions of our Array... 1 Datatype of our Array object... int32 Shape of our Array object... (5,) Result (polynomial to hermite)... [6.25 4. 4.5 0.5 0.3125] The output of dividing the hermite series by another: [1. 1. 1. 1. 1.]
示例
讓我們再看一個使用 numpy 庫的 divide() 函式將一個 Hermite 級數除以另一個 Hermite 級數的示例。
import numpy as np
from numpy.polynomial import hermite as H
h1 = np.array([1, 2, 3, 4, 5])
h2 = np.arange(2,12,2)
print("Array1...\n",h1)
print("Array2...\n",h2)
print("\nDimensions of Array1...\n",h1.ndim)
print("\nDimensions of Array2...\n",h2.ndim)
print("\nDatatype of Array1 object...\n",h1.dtype)
print("\nDatatype of Array2 object...\n",h2.dtype)
print("\nShape of Array1 object...\n",h1.shape)
print("\nShape of Array2 object...\n",h2.shape)
print("\nResult (polynomial to hermite)...\n",H.poly2herm(h1))
print("\nResult (polynomial to hermite)...\n",H.poly2herm(h2))
divide_hermite = np.divide(h1,h2)
print("The output of dividing the hermite series by another:",divide_hermite)
輸出
Array1... [1 2 3 4 5] Array2... [ 2 4 6 8 10] Dimensions of Array1... 1 Dimensions of Array2... 1 Datatype of Array1 object... int32 Datatype of Array2 object... int32 Shape of Array1 object... (5,) Shape of Array2 object... (5,) Result (polynomial to hermite)... [6.25 4. 4.5 0.5 0.3125] Result (polynomial to hermite)... [12.5 8. 9. 1. 0.625] The output of dividing the hermite series by another: [0.5 0.5 0.5 0.5 0.5]
示例
在以下示例中,我們使用 divide() 函式將一個一維陣列除以一個二維 Hermite 級數陣列,由於兩個級數之間的係數維度不匹配,因此會引發錯誤。
import numpy as np
from numpy.polynomial import hermite as H
h1 = np.array([1, 2, 3, 4, 5])
h2 = np.arange(2,12).reshape(5,2)
print("Array1...\n",h1)
print("Array2...\n",h2)
print("\nDimensions of Array1...\n",h1.ndim)
print("\nDimensions of Array2...\n",h2.ndim)
print("\nDatatype of Array1 object...\n",h1.dtype)
print("\nDatatype of Array2 object...\n",h2.dtype)
print("\nShape of Array1 object...\n",h1.shape)
print("\nShape of Array2 object...\n",h2.shape)
print("\nResult (polynomial to hermite)...\n",H.poly2herm(h1))
print("\nResult (polynomial to hermite)...\n",H.poly2herm(h2))
divide_hermite = np.divide(h1,h2)
print("The output of dividing the hermite series by another:",divide_hermite)
輸出
Array1...
[1 2 3 4 5]
Array2...
[[ 2 3]
[ 4 5]
[ 6 7]
[ 8 9]
[10 11]]
Dimensions of Array1...
1
Dimensions of Array2...
2
Datatype of Array1 object...
int32
Datatype of Array2 object...
int32
Shape of Array1 object...
(5,)
Shape of Array2 object...
(5, 2)
Result (polynomial to hermite)...
[6.25 4. 4.5 0.5 0.3125]
Traceback (most recent call last):
File "F:\test.py", line 14, in <module>
print("\nResult (polynomial to hermite)...\n",H.poly2herm(h2))
^^^^^^^^^^^^^^^
File "C:\Users\Krishna\AppData\Roaming\Python\Python311\site-packages\numpy\polynomial\hermite.py", line 134, in poly2herm
[pol] = pu.as_series([pol])
^^^^^^^^^^^^^^^^^^^
File "C:\Users\Krishna\AppData\Roaming\Python\Python311\site-packages\numpy\polynomial\polyutils.py", line 134, in as_series
raise ValueError("Coefficient array is not 1-d")
ValueError: Coefficient array is not 1-d
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP