หากต้องการประเมินค่า (evaluate) อนุกรมเฮอร์ไมท์ (Hermite series) ที่จุด x ให้ใช้เมธอด hermite.hermval() ใน Python NumPy
พารามิเตอร์สำคัญ
- x: จุดที่ต้องการประเมิน หากเป็น list หรือ tuple จะแปลงเป็น ndarray มิฉะนั้นถือเป็นสเกลาร์
- c: อาร์เรย์สัมประสิทธิ์ เรียงลำดับว่าสัมประสิทธิ์ของพจน์อันดับ n อยู่ใน c[n]
- tensor: หาก True (default) รูปร่างสัมประสิทธิ์จะขยายสำหรับแต่ละมิติของ x
ขั้นตอนการใช้งาน
1. นำเข้าไลบรารีที่จำเป็น
import numpy as np
from numpy.polynomial import hermite as H
2. สร้างอาร์เรย์สัมประสิทธิ์
c = np.array([1, 2, 3])
3. แสดงอาร์เรย์
print("Our Array...\n", c)
4. ตรวจสอบมิติ
print("\nDimensions of our Array...\n", c.ndim)
5. ตรวจสอบชนิดข้อมูล
print("\nDatatype of our Array object...\n", c.dtype)
6. ตรวจสอบรูปร่าง
print("\nShape of our Array object...\n", c.shape)
7. ประเมินอนุกรมเฮอร์ไมท์ที่จุด x=1
print("\nResult...\n", H.hermval(1, c))
ตัวอย่างโค้ดเต็ม
import numpy as np
from numpy.polynomial import hermite as H
# สร้างอาร์เรย์สัมประสิทธิ์: 1·H₀ + 2·H₁ + 3·H₂
c = np.array([1, 2, 3])
# แสดงอาร์เรย์
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)
# ประเมินอนุกรมเฮอร์ไมท์ที่จุด x=1
print("\nResult...\n", H.hermval(1, c))
ผลลัพธ์ที่ได้
Our Array...
[1 2 3]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(3,)
Result...
11.0
คำอธิบายเพิ่มเติม
อนุกรมเฮอร์ไมท์: H(x) = 1·H₀(x) + 2·H₁(x) + 3·H₂(x)
พหุนามเฮอร์ไมท์ (physicist's):
- H₀(x) = 1
- H₁(x) = 2x
- H₂(x) = 4x² - 2
ที่ x = 1:
H(1) = 1·1 + 2·(2·1) + 3·(4·1² - 2) = 1 + 4 + 3·2 = 1 + 4 + 6 = 11
ตรงกับผลลัพธ์ 11.0
การใช้งานทั่วไป:
- ฟิสิกส์ควอนตัม (quantum harmonic oscillator)
- การประมาณค่าฟังก์ชัน (function approximation)
- การแก้สมการ微分方程 (differential equations)
- การประมวลผลสัญญาณและความน่าจะเป็น
ใช้ hermite.hermval() ประเมินอนุกรมเฮอร์ไมท์ 1·H₀+2·H₁+3·H₂ ที่ x=1 ได้ผลลัพธ์ 11.0