บทนำ
ในการหาปริพันธ์ของอนุกรม Chebyshev สามารถใช้เมธอด chebyshev.chebint() จาก NumPy เมธอดนี้คืนค่าสัมประสิทธิ์อนุกรม Chebyshev ที่ผ่านการปริพันธ์ m ครั้งจากขอบเขตล่าง lbnd ตามแกน axis ในแต่ละรอบ ผลลัพธ์จะถูกคูณด้วย scl และบวกค่าคงที่การปริพันธ์ k
พารามิเตอร์สำคัญ
- c: อาเรย์สัมประสิทธิ์อนุกรม Chebyshev
- m: ลำดับการปริพันธ์ (ค่าเริ่มต้น: 1)
- k: ค่าคงที่การปริพันธ์ (ค่าเริ่มต้น: 0)
- lbnd: ขอบเขตล่าง (ค่าเริ่มต้น: 0)
- scl: ตัวคูณสเกล (ค่าเริ่มต้น: 1)
- axis: แกนที่ทำการปริพันธ์ (ค่าเริ่มต้น: 0)
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import chebyshev as C
2. สร้างอาเรย์สัมประสิทธิ์หลายมิติ
c = np.arange(4).reshape(2, 2)
3. แสดงอาเรย์และตรวจสอบคุณสมบัติ
print("Our coefficient 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. หาปริพันธ์ตามแกน 1
print("\nResult...\n", C.chebint(c, axis=1))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import chebyshev as C
# สร้างอาเรย์สัมประสิทธิ์หลายมิติ
c = np.arange(4).reshape(2, 2)
# แสดงอาเรย์
print("Our coefficient 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)
# หาปริพันธ์ตามแกน 1
print("\nResult...\n", C.chebint(c, axis=1))
ผลลัพธ์ที่คาดหวัง
Our coefficient Array... [[0 1]
[2 3]]
Dimensions of our Array... 2
Datatype of our Array object... int64
Shape of our Array object... (2, 2)
Result... [[0.25 0. 0.25]
[0.75 2. 0.75]]