บทนำ
ในการประเมินอนุกรมเชบิชีฟ 2 มิติ (2-D Chebyshev series) ที่จุด (x, y) สามารถใช้เมธอด polynomial.chebval2d() ในไลบรารี NumPy ของ Python เมธอดนี้จะคืนค่าของอนุกรมเชบิชีฟ 2 มิติ ที่จุดที่สร้างจากคู่ของค่าที่ตรงกันจาก x และ y
พารามิเตอร์สำคัญ
- x, y: จุดที่ต้องการประเมิน ต้องมีรูปร่าง (shape) เหมือนกัน หากเป็นลิสต์หรือทูเพิล จะถูกแปลงเป็น ndarray อัตโนมัติ
- c: อาร์เรย์ของสัมประสิทธิ์ จัดเรียงโดยที่สัมประสิทธิ์ของพจน์ที่มีมัลติดีกรี i,j จะอยู่ใน c[i,j] หาก c มีมิติมากกว่า 2 ดัชนีที่เหลือจะนับเซตของสัมประสิทธิ์หลายชุด
ขั้นตอนการทำงาน
1. นำเข้าไลบรารีที่จำเป็น
import numpy as np
from numpy.polynomial import chebyshev as C
2. สร้างอาร์เรย์สัมประสิทธิ์ 1 มิติ
c = np.array([3, 5])
3. แสดงข้อมูลของอาร์เรย์
print("Our Array...\n", c)
print("\nDimensions of our Array...\n", c.ndim)
print("\nDatatype of our Array object...\n", c.dtype)
print("\nShape of our Array object...\n", c.shape)
4. ประเมินอนุกรมเชบิชีฟ 2 มิติ
print("\nResult...\n", C.chebval2d([1, 2], [1, 2], c))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import chebyshev as C
# สร้างอาร์เรย์สัมประสิทธิ์ 1 มิติ
c = np.array([3, 5])
# แสดงข้อมูลอาร์เรย์
print("Our Array...\n", c)
print("\nDimensions of our Array...\n", c.ndim)
print("\nDatatype of our Array object...\n", c.dtype)
print("\nShape of our Array object...\n", c.shape)
# ประเมินอนุกรมเชบิชีฟ 2 มิติ ที่จุด (x, y)
print("\nResult...\n", C.chebval2d([1, 2], [1, 2], c))
ผลลัพธ์
Our Array...
[3 5]
Dimensions of our Array...
1
Datatype of our Array object...
int64
Shape of our Array object...
(2,)
Result...
[21. 34.]
สรุป
ตัวอย่างนี้แสดงวิธีการใช้ chebval2d() เพื่อประเมินอนุกรมเชบิชีฟ 2 มิติ ด้วยอาร์เรย์สัมประสิทธิ์ 1 มิติ ผลลัพธ์ที่ได้คืออาร์เรย์ของค่าที่คำนวณได้ที่แต่ละจุด (x, y)