เพื่อสร้างเมทริกซ์วนเดอร์มอนด์แบบปลอม (Pseudo-Vandermonde Matrix) ของพหุนามเฮอร์ไมต์_e (Hermite_e) และจุดตัวอย่าง x, y, z ให้ใช้ฟังก์ชัน hermite_e.hermevander3d() ในไลบรารี NumPy ของ Python ฟังก์ชันนี้จะคืนค่าเป็นเมทริกซ์วนเดอร์มอนด์แบบปลอม พารามิเตอร์ x, y, z คืออาร์เรย์ของพิกัดจุด ซึ่งต้องมีรูปร่าง (Shape) เท่ากัน ทุกชนิดข้อมูลจะถูกแปลงเป็น float64 หรือ complex128 ขึ้นอยู่กับว่ามีจำนวนเชิงซ้อนหรือไม่ สเกลาร์จะถูกแปลงเป็นอาร์เรย์ 1 มิติ พารามิเตอร์ deg คือรายการขององศาสูงสุดในรูปแบบ [x_deg, y_deg, z_deg]
ขั้นตอน
ขั้นแรก ให้นำเข้าไลบรารีที่จำเป็น:
import numpy as np from numpy.polynomial import hermite_e as H
สร้างอาร์เรย์ของพิกัดจุด ซึ่งมีรูปร่างเท่ากัน โดยใช้เมธอด numpy.array():
x = np.array([-2.+2.j, -1.+2.j]) y = np.array([0.+2.j, 1.+2.j]) z = np.array([2.+2.j, 3. + 3.j])
แสดงอาร์เรย์:
print("Array1...\n", x)
print("\nArray2...\n", y)
print("\nArray3...\n", z)แสดงชนิดข้อมูล:
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
print("\nArray3 datatype...\n", z.dtype)ตรวจสอบมิติของอาร์เรย์:
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
print("\nDimensions of Array3...\n", z.ndim)ตรวจสอบรูปร่างของอาร์เรย์:
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)
print("\nShape of Array3...\n", z.shape)เพื่อสร้างเมทริกซ์วนเดอร์มอนด์แบบปลอมของพหุนามเฮอร์ไมต์_e และจุดตัวอย่าง x, y, z ให้ใช้เมธอด hermite_e.hermevander3d():
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n", H.hermevander3d(x, y, z, [x_deg, y_deg, z_deg]))ตัวอย่างโค้ดเต็ม
import numpy as np
from numpy.polynomial import hermite_e as H
# Create arrays of point coordinates, all of the same shape
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3. + 3.j])
# Display the arrays
print("Array1...\n", x)
print("\nArray2...\n", y)
print("\nArray3...\n", z)
# Display the datatype
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
print("\nArray3 datatype...\n", z.dtype)
# Check the Dimensions
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
print("\nDimensions of Array3...\n", z.ndim)
# Check the Shape
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)
print("\nShape of Array3...\n", z.shape)
# Generate pseudo Vandermonde matrix
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n", H.hermevander3d(x, y, z, [x_deg, y_deg, z_deg]))ผลลัพธ์
Array1... [-2.+2.j -1.+2.j] Array2... [0.+2.j 1.+2.j] Array3... [2.+2.j 3.+3.j] Array1 datatype... complex128 Array2 datatype... complex128 Array3 datatype... complex128 Dimensions of Array1... 1 Dimensions of Array2... 1 Dimensions of Array3... 1 Shape of Array1... (2,) Shape of Array2... (2,) Shape of Array3... (2,) Result... [[ 1.0000e+00 +0.000e+00j 2.0000e+00 +2.000e+00j -1.0000e+00 +8.000e+00j ...]]