บทนำ
ในการหาอนุพันธ์ของพหุนามที่มีสัมประสิทธิ์หลายมิติ สามารถใช้เมธอด polynomial.polyder() ใน NumPy พร้อมระบุพารามิเตอร์ axis เพื่อเลือกแกนที่ต้องการหาอนุพันธ์
พารามิเตอร์สำคัญ
- c: อาร์เรย์สัมประสิทธิ์พหุนาม หากเป็นหลายมิติ แกนต่างๆ สอดคล้องกับตัวแปรต่างๆ
- m: จำนวนอนุพันธ์ (ค่าเริ่มต้น: 1)
- scl: ตัวคูณสเกล (ค่าเริ่มต้น: 1)
- axis: แกนที่หาอนุพันธ์ (ค่าเริ่มต้น: 0)
ขั้นตอนการทำงาน
1. นำเข้าไลบรารีที่จำเป็น
import numpy as np
from numpy.polynomial import polynomial as P
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", P.polyder(c, axis=1))
ตัวอย่างโค้ดสมบูรณ์
import numpy as np
from numpy.polynomial import polynomial as P
# สร้างอาร์เรย์สัมประสิทธิ์พหุนามหลายมิติ (2x2)
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 (axis=1)
print("\nResult...\n", P.polyder(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...
[[1.] [3.]]
สรุป
เมื่อระบุ axis=1 อนุพันธ์จะถูกคำนวณตามแกนคอลัมน์ สำหรับอาร์เรย์ 2x2 แต่ละแถวแทนพหุนามในตัวแปร y (เช่น) และจะถูกหาอนุพันธ์แยกกัน ให้ผลลัพธ์ขนาด (2, 1)