หากต้องการสร้างเมทริกซ์วนเดอร์มอนด์แบบปลอม (pseudo-Vandermonde matrix) ของพหุนามเชบิเชฟและจุดตัวอย่าง x, y, z ให้ใช้ chebyshev.chebvander3d() ใน Python NumPy
เมธอดคืนค่าเมทริกซ์วนเดอร์มอนด์แบบปลอมของอันดับ deg และจุดตัวอย่าง (x, y, z)
พารามิเตอร์
- x, y, z: อาร์เรย์พิกัดจุด ทุกตัวต้องมีรูปร่างเหมือนกัน dtypes จะแปลงเป็น float64 หรือ complex128 ขึ้นอยู่กับว่ามีค่าเชิงซ้อนหรือไม่
- deg: รายการอันดับสูงสุด รูปแบบ
[x_deg, y_deg, z_deg]
ขั้นตอนการใช้งาน
1. นำเข้าไลบรารีที่จำเป็น
import numpy as np
from numpy.polynomial import chebyshev as C
2. สร้างอาร์เรย์พิกัดจุด รูปร่างเหมือนกัน
x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 6])
3. แสดงอาร์เรย์
print("Array1...\n", x)
print("\nArray2...\n", y)
print("\nArray3...\n", z)
4. ตรวจสอบชนิดข้อมูล
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
print("\nArray3 datatype...\n", z.dtype)
5. ตรวจสอบมิติ
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
print("\nDimensions of Array3...\n", z.ndim)
6. ตรวจสอบรูปร่าง
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)
print("\nShape of Array3...\n", z.shape)
7. สร้างเมทริกซ์วนเดอร์มอนด์แบบปลอม 3 มิติ ด้วย chebyshev.chebvander3d()
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n", C.chebvander3d(x, y, z, [x_deg, y_deg, z_deg]))
ตัวอย่างโค้ดเต็ม
import numpy as np
from numpy.polynomial import chebyshev as C
# สร้างอาร์เรย์พิกัดจุด
x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 6])
# แสดงอาร์เรย์
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)
# สร้างเมทริกซ์วนเดอร์มอนด์แบบปลอม 3 มิติ
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n", C.chebvander3d(x, y, z, [x_deg, y_deg, z_deg]))
ผลลัพธ์ที่ได้
Array1...
[1 2]
Array2...
[3 4]
Array3...
[5 6]
Array1 datatype...
int64
Array2 datatype...
int64
Array3 datatype...
int64
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.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03
3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04
1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04
9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05
1.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03
3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04
1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04
9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05
1.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03
3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04
1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04
9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05]
[1.0000000e+00 6.0000000e+00 7.1000000e+01 8.4600000e+02 1.0081000e+04
4.0000000e+00 2.4000000e+01 2.8400000e+02 3.3840000e+03 4.0324000e+04
3.1000000e+01 1.8600000e+02 2.2010000e+03 2.6226000e+04 3.1251100e+05
2.4400000e+02 1.4640000e+03 1.7324000e+04 2.0642400e+05 2.4597640e+06
2.0000000e+00 1.2000000e+01 1.4200000e+02 1.6920000e+03 2.0162000e+04
8.0000000e+00 4.8000000e+01 5.6800000e+02 6.7680000e+03 8.0648000e+04
6.2000000e+01 3.7200000e+02 4.4020000e+03 5.2452000e+04 6.2502200e+05
4.8800000e+02 2.9280000e+03 3.4648000e+04 4.1284800e+05 4.9195280e+06
7.0000000e+00 4.2000000e+01 4.9700000e+02 5.9220000e+03 7.0567000e+04
2.8000000e+01 1.6800000e+02 1.9880000e+03 2.3688000e+04 2.8226800e+05
2.1700000e+02 1.3020000e+03 1.5407000e+04 1.8358200e+05 2.1875770e+06
1.7080000e+03 1.0248000e+04 1.2126800e+05 1.4449680e+06 1.7218348e+07]]
คำอธิบายเพิ่มเติม
เมทริกซ์วนเดอร์มอนด์แบบปลอม (pseudo-Vandermonde matrix) สำหรับเชบิเชฟ 3 มิติ มีโครงสร้าง:
คอลัมน์แทนพจน์ Tᵢ(x) · Tⱼ(y) · Tₖ(z) สำหรับ i=0..x_deg, j=0..y_deg, k=0..z_deg
จำนวนคอลัมน์ = (x_deg+1) × (y_deg+1) × (z_deg+1) = 3 × 4 × 5 = 60 คอลัมน์
จำนวนแถว = จำนวนจุดตัวอย่าง = 2
เมทริกซ์นี้ใช้ใน:
- การ fit พหุนามเชบิเชฟหลายมิติ (multidimensional Chebyshev fitting)
- การประมาณค่าฟังก์ชันหลายตัวแปร
- Spectral methods สำหรับ PDE ใน 3 มิติ
ใช้ chebyshev.chebvander3d() สร้าง pseudo-Vandermonde matrix 3D ของเชบิเชฟ อันดับ [2,3,4] ที่จุด (1,3,5) และ (2,4,6) ได้เมทริกซ์ 2x60