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

คูณอนุกรมเชบิชีฟ ด้วยตัวแปรอิสระใน Python

บทนำ

ในการคูณอนุกรมเชบิชีฟ (Chebyshev series) ด้วยตัวแปรอิสระ (independent variable) สามารถใช้เมธอด polynomial.chebyshev.chebmulx() ใน NumPy ของ Python เมธอดนี้จะคืนอาร์เรย์ที่แทนผลลัพธ์ของการคูณ

พารามิเตอร์

  • c: อาร์เรย์ 1 มิติของสัมประสิทธิ์อนุกรมเชบิชีฟ จัดเรียงจากดีกรีต่ำไปสูง

ขั้นตอนการทำงาน

1. นำเข้าไลบรารีที่จำเป็น

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

2. สร้างอาร์เรย์

x = np.array([1, 2, 3])

3. แสดงข้อมูลของอาร์เรย์

print("Our Array...\n", x)
print("\nDimensions of our Array...\n", x.ndim)
print("\nDatatype of our Array object...\n", x.dtype)
print("\nShape of our Array object...\n", x.shape)

4. คูณอนุกรมเชบิชีฟ ด้วยตัวแปรอิสระ

print("\nResult....\n", C.chebmulx(x))

ตัวอย่างโค้ดสมบูรณ์

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

# สร้างอาร์เรย์
x = np.array([1, 2, 3])

# แสดงข้อมูลอาร์เรย์
print("Our Array...\n", x)
print("\nDimensions of our Array...\n", x.ndim)
print("\nDatatype of our Array object...\n", x.dtype)
print("\nShape of our Array object...\n", x.shape)

# คูณอนุกรมเชบิชีฟ ด้วยตัวแปรอิสระ
print("\nResult....\n", C.chebmulx(x))

ผลลัพธ์

Our Array...
 [1 2 3]
Dimensions of our Array...
 1
Datatype of our Array object...
 int64
Shape of our Array object...
 (3,)
Result....
 [1.  2.5 1.  1.5]

สรุป

เมธอด chebmulx() คูณอนุกรมเชบิชีฟด้วย x ซึ่งเทียบเท่ากับการเพิ่มดีกรีของแต่ละพจน์ขึ้น 1 ผลลัพธ์จะมีความยาวเพิ่มขึ้น 1 องค์ประกอบ