บทนำ
ในการสร้างเมทริกซ์ Vandermonde แบบปลอมของพหุนาม Hermite 2 มิติ ด้วยพิกัดจุดเชิงซ้อน สามารถใช้ hermite.hermvander2d() จาก NumPy พารามิเตอร์ x, y เป็นอาเรย์พิกัดจุดรูปร่างเดียวกัน ชนิดข้อมูลจะแปลงเป็น float64 หรือ complex128
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import hermite as H
2. สร้างอาเรย์พิกัดจุดเชิงซ้อน
x = np.array([-2.+2.j, -1.+2.j]) y = np.array([1.+2.j, 2.+2.j])
3. แสดงอาเรย์และตรวจสอบคุณสมบัติ
print("Array1...\n", x)
print("\nArray2...\n", y)
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)
4. สร้างเมทริกซ์ Vandermonde 2 มิติ
x_deg, y_deg = 2, 3
print("\nResult...\n", H.hermvander2d(x, y, [x_deg, y_deg]))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import hermite as H
# สร้างอาเรย์พิกัดจุดเชิงซ้อน
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([1.+2.j, 2.+2.j])
# แสดงอาเรย์
print("Array1...\n", x)
print("\nArray2...\n", y)
# แสดงชนิดข้อมูล
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
# ตรวจสอบมิติ
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
# ตรวจสอบรูปร่าง
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)
# สร้างเมทริกซ์ Vandermonde 2 มิติ
x_deg, y_deg = 2, 3
print("\nResult...\n", H.hermvander2d(x, y, [x_deg, y_deg]))
ผลลัพธ์ที่คาดหวัง
Array1... [-2.+2.j -1.+2.j]
Array2... [1.+2.j 2.+2.j]
Array1 datatype... complex128
Array2 datatype... complex128
Dimensions of Array1... 1
Dimensions of Array2... 1
Shape of Array1... (2,)
Shape of Array2... (2,)
Result... [[ 1.000e+00 +0.j 2.000e+00 +4.j -1.400e+01 +16.j ... -1.080e+03 +3280.j]
[ 1.000e+00 +0.j 4.000e+00 +4.j -2.000e+00 +32.j ... 3.792e+03 +976.j]]