บทนำ
การสร้างเมทริกซ์ Vandermonde แบบปลอมของพหุนามเลจันเดอร์ ใช้เมธอด legendre.legvander2d() ใน NumPy คืนค่าเมทริกซ์ Vandermonde แบบปลอม รูปร่าง: x.shape + (deg + 1,) ดัชนีสุดท้ายคือดีกรีของพหุนามเลจันเดอร์ dtype เหมือน x ที่แปลงแล้ว
พารามิเตอร์
- x, y: อาร์เรย์พิกัดจุด รูปร่างเท่ากัน dtype แปลงเป็น float64 หรือ complex128 สเกลาร์แปลงเป็น 1-D array
- deg: รายการดีกรีสูงสุด [x_deg, y_deg]
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import legendre as L
2. สร้างอาร์เรย์พิกัดจุด
x = np.array([0.1, 1.4]) y = np.array([1.7, 2.8])
3. แสดงอาร์เรย์
print("Array1...\n", x)
print("\nArray2...\n", y)
4. ตรวจสอบชนิดข้อมูล
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
5. ตรวจสอบมิติ
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
6. ตรวจสอบรูปร่าง
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)
7. สร้างเมทริกซ์ Vandermonde แบบปลอม
x_deg, y_deg = 2, 3
print("\nResult...\n", L.legvander2d(x, y, [x_deg, y_deg]))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import legendre as L
x = np.array([0.1, 1.4])
y = np.array([1.7, 2.8])
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)
x_deg, y_deg = 2, 3
print("\nResult...\n", L.legvander2d(x, y, [x_deg, y_deg]))
ผลลัพธ์ที่คาดหวัง
Array1... [0.1 1.4] Array2... [1.7 2.8] Array1 datatype... float64 Array2 datatype... float64 Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (2,) Shape of Array2... (2,) Result... [[ 1.0000000e+00 1.7000000e+00 3.8350000e+00 9.7325000e+00 ...]]