Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ยกกำลังอนุกรม Chebyshev ใน Python

บทนำ

เมธอด chebyshev.chebpow() ยกอนุกรม Chebyshev ขึ้นกำลัง แต่ตัวอย่างในเอกสารต้นฉบับมีข้อผิดพลาด ใช้ chebdiv() แทน chebpow()

พารามิเตอร์ของ chebpow() (ที่ถูกต้อง)

  • c: สัมประสิทธิ์ 1 มิติ เรียงจากดีกรีต่ำไปสูง
  • pow: กำลังที่ต้องการยก
  • maxpower: กำลังสูงสุดที่อนุญาต (ค่าเริ่มต้น 16) ป้องกันขนาดอนุกรมใหญ่เกินไป

ตัวอย่างจากเอกสาร (ใช้ chebdiv แทน)

import numpy as np
from numpy.polynomial import chebyshev as C

c = np.array([1, 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)

# หมายเหตุ: โค้ดต้นฉบับใช้ chebdiv แทน chebpow
print("\nResult...\n", C.chebdiv(c, 3))

ผลลัพธ์ของ chebdiv(c, 3)

Our coefficient Array... [1 2 3]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (3,)
Result... (array([0.33333333, 0.66666667, 1. ]), array([0.]))

หมายเหตุสำคัญ: ตัวอย่างโค้ดต้นฉบับเรียก C.chebdiv(c, 3) แทน C.chebpow(c, 3) สำหรับการยกกำลังจริงควรใช้ C.chebpow(c, 3)