บทนำ
ในการสร้างเมทริกซ์ Vandermonde แบบปลอม (pseudo-Vandermonde matrix) ของพหุนาม Hermite สามารถใช้ฟังก์ชัน hermite.hermvander() จากไลบรารี NumPy ใน Python ฟังก์ชันนี้จะคืนค่าเป็นเมทริกซ์ที่มีรูปร่าง (shape) เท่ากับ x.shape + (deg + 1,) โดยดัชนีสุดท้ายจะแสดงถึงองศาของพหุนาม Hermite ที่สอดคล้องกัน ชนิดข้อมูล (dtype) จะเหมือนกับข้อมูล x ที่ถูกแปลงแล้ว
พารามิเตอร์สำคัญ
- x: อาเรย์ของจุดข้อมูล จะถูกแปลงเป็น
float64หรือcomplex128ขึ้นอยู่กับว่ามีจำนวนเชิงซ้อนหรือไม่ หากเป็นสเกลาร์ จะถูกแปลงเป็นอาเรย์ 1 มิติ - deg: องศาของเมทริกซ์ที่ต้องการสร้าง
ขั้นตอนการทำงาน
1. นำเข้าไลบรารีที่จำเป็น
import numpy as np from numpy.polynomial import hermite as H
2. สร้างอาเรย์ข้อมูล
x = np.array([0, 1, -1, 2])
3. แสดงอาเรย์
print("Our Array...\n", x)
4. สร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite
print("\nResult...\n", H.hermvander(x, 2))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import hermite as H
# สร้างอาเรย์
x = np.array([0, 1, -1, 2])
# แสดงอาเรย์
print("Our Array...\n", x)
# ตรวจสอบมิติ
print("\nDimensions of our Array...\n", x.ndim)
# ตรวจสอบชนิดข้อมูล
print("\nDatatype of our Array object...\n", x.dtype)
# ตรวจสอบรูปร่าง
print("\nShape of our Array object...\n", x.shape)
# สร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite
print("\nResult...\n", H.hermvander(x, 2))
ผลลัพธ์ที่คาดหวัง
Our Array... [ 0 1 -1 2]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (4,)
Result... [[ 1. 0. -2.]
[ 1. 2. 2.]
[ 1. -2. 2.]
[ 1. 4. 14.]]