บทนำ
การอินทิเกรต (Integrate) อนุกรมเลจันเดอร์ (Legendre Series) ใช้เมธอด polynomial.legendre.legint() ใน Python เมธอดนี้คืนค่าสัมประสิทธิ์อนุกรมเลจันเดอร์ c ที่ถูกอินทิเกรต m ครั้งจาก lbnd ตาม axis ที่กำหนด ในแต่ละรอบ ผลลัพธ์จะถูกคูณด้วย scl และบวกค่าคงที่การอินทิเกรชัน k
พารามิเตอร์
- c: อาร์เรย์สัมประสิทธิ์อนุกรมเลจันเดอร์ หากเป็นหลายมิติ แก้ต่างๆ จะสอดคล้องกับตัวแปรต่างๆ
- m: ออเดอร์การอินทิเกรชัน ต้องเป็นบวก (Default: 1)
- k: ค่าคงที่การอินทิเกรชัน ค่าของอินทิเกรลแรกที่ lbnd คือค่าแรกในลิสต์ ถ้า k == [] (default) ทุกค่าจะเป็นศูนย์
- lbnd: ขอบเขตล่างของอินทิเกรล (Default: 0)
- scl: สเกลาร์ หลังอินทิเกรชันแต่ละครั้ง ผลลัพธ์จะคูณ scl ก่อนบวกค่าคงที่
- axis: แกนที่ทำการอินทิเกรชัน (Default: 0)
ขั้นตอนการทำงาน
1. นำเข้าไลบรารี
import numpy as np from numpy.polynomial import legendre as L
2. สร้างอาร์เรย์สัมประสิทธิ์
c = np.array([1, 2, 3])
3. แสดงอาร์เรย์
print("Our Array...\n", c)
4. ตรวจสอบมิติ
print("\nDimensions of our Array...\n", c.ndim)
5. ตรวจสอบชนิดข้อมูล
print("\nDatatype of our Array object...\n", c.dtype)
6. ตรวจสอบรูปร่าง
print("\nShape of our Array object...\n", c.shape)
7. อินทิเกรตอนุกรมเลจันเดอร์ (m=3)
print("\nResult...\n", L.legint(c, m=3))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import legendre as L
# สร้างอาร์เรย์สัมประสิทธิ์
c = np.array([1, 2, 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)
# อินทิเกรตอนุกรมเลจันเดอร์ m=3
print("\nResult...\n", L.legint(c, m=3))
ผลลัพธ์ที่คาดหวัง
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [ 1.66666667e-02 -1.78571429e-02 4.76190476e-02 -1.73472348e-18 1.90476190e-02 9.52380952e-03]