บทนำ
เพื่อสร้างเมทริกซ์แบบヴァンเดอร์มอนด์疑似 (pseudo Vandermonde matrix) ของพหุนามลากูร์ร่า (Laguerre polynomial) พร้อมจุดตัวอย่าง x, y, z เราสามารถใช้เมธอด laguerre.lagvander3d() ใน NumPy พารามิเตอร์หลักมีดังนี้:
- x, y, z: ส่งคืนอาร์เรย์ของจุด ชนิดข้อมูล (dtype) จะถูกแปลงเป็น float64 หรือ complex128 ขึ้นอยู่กับว่ามีองค์ประกอบซ้อนหรือไม่ หาก x เป็นสเกลาร์ จะถูกแปลงเป็นอาร์เรย์ 1 มิติ
- deg: ลิสต์ของดีกรีสูงสุดในรูปแบบ
[x_deg, y_deg, z_deg]
ขั้นตอนการทำงาน
1. นำเข้าไลบรารีที่จำเป็น
import numpy as np
from numpy.polynomial import laguerre as L
2. สร้างอาร์เรย์พิกัดจุดทศนิยม (รูปทรงเหมือนกัน)
x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.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 มิติ
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n", L.lagvander3d(x, y, z, [x_deg, y_deg, z_deg]))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import laguerre as L
# สร้างอาร์เรย์พิกัดจุด ทุกอาร์เรย์มีรูปทรงเหมือนกัน
x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.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)
# สร้างเมทริกซ์แบบヴァンเดอร์มอนด์疑似 ของพหุนามลากูร์ร่ พร้อมจุด x, y, z
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n", L.lagvander3d(x, y, z, [x_deg, y_deg, z_deg]))
ผลลัพธ์ที่คาดหวัง
Array1...
[1.5 2.3]
Array2...
[3.7 4.4]
Array3...
[5.3 6.6]
Array1 datatype...
float64
Array2 datatype...
float64
Array3 datatype...
float64
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. -4.3 4.445 2.42216667 -2.30432917 -2.7 11.61 -12.0015 -6.53985 6.22168875
0.445 -1.9135 1.978025 1.07786417 -1.02542648 1.99283333 -8.56918333 8.85814417 4.82697447 -4.59214397
-0.5 2.15 -2.2225 -1.21108333 1.15216458 1.35 -5.805 6.00075 3.269925 -3.11084437
-0.2225 0.95675 -0.9890125 -0.53893208 0.51271324 -0.99641667 4.28459167 -4.42907208 -2.41348724 2.29607199
-0.875 3.7625 -3.889375 -2.11939583 2.01628802 2.3625 -10.15875 10.5013125 5.72236875 -5.44397766
-0.389375 1.6743125 -1.73077188 -0.94313115 0.89724817 -1.74372917 7.49803542 -7.75087615 -4.22360266 4.01812598]
[ 1. -5.6 9.58 -1.376 -7.3226 -3.4 19.04 -32.572 4.6784 24.89684
1.88 -10.528 18.0104 -2.58688 -13.766488 2.64266667 -14.79893333 25.31674667 -3.63630933 -19.35119093
-1.3 7.28 -12.454 1.7888 9.51938 4.42 -24.752 42.3436 -6.08192 -32.365892
-2.444 13.6864 -23.41352 3.362944 17.8964344 -3.43546667 19.23861333 -32.91177067 4.72720213 25.15654821
-0.955 5.348 -9.1489 1.31408 6.993083 3.247 -18.1832 31.10626 -4.467872 -23.7764822
-1.7954 10.05424 -17.199932 2.4704704 13.14699604 -2.52374667 14.13298133 -24.17749307 3.47267541 18.48038734]]