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

อนุพันธ์อนุกรมเชบิเชฟสัมประสิทธิ์หลายมิติตามแกน 1 ใน Python

หากต้องการหาอนุพันธ์ของอนุกรมเชบิเชฟ (differentiate a Chebyshev series) ให้ใช้เมธอด polynomial.chebder() ใน Python NumPy

เมธอดคืนค่าอนุกรมเชบิเชฟของอนุพันธ์ คืนค่าสัมประสิทธิ์เชบิเชฟ c ที่ถูกหาอนุพันธ์ m ครั้งตามแกน axis ที่แต่ละรอบผลลัพธ์จะคูณด้วย scl อาร์กิวเมนต์ c เป็นอาร์เรย์สัมประสิทธิ์จากอันดับต่ำไปสูง ตัวอย่าง [1,2,3] แทนอนุกรม 1·T₀ + 2·T₁ + 3·T₂ ในขณะที่ [[1,2],[1,2]] แทน 1·T₀(x)T₀(y) + 1·T₁(x)T₀(y) + 2·T₀(x)T₁(y) + 2·T₁(x)T₁(y) หาก axis=0 คือ x และ axis=1 คือ y

พารามิเตอร์

  • c: อาร์เรย์สัมประสิทธิ์อนุกรมเชบิเชฟ หากหลายมิติ แกนต่างๆ ตรงกับตัวแปรต่างๆ
  • m: จำนวนครั้งของการหาอนุพันธ์ (default: 1)
  • scl: ตัวคูณสเกล (default: 1)
  • axis: แกนที่หาอนุพันธ์ (default: 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)

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. หาอนุพันธ์ตามแกน 1 (axis=1) ด้วย chebyshev.chebder()

print("\nResult...\n", C.chebder(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.chebder(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.]]

คำอธิบายเพิ่มเติม

อาร์เรย์สัมประสิทธิ์ c (shape 2×2):

[[0 1]
 [2 3]]

ถูกตีความเป็นอนุกรมเชบิเชฟ 2 ตัวแปร (x, y) โดย axis=0 คือ x, axis=1 คือ y:

C(x,y) = 0·T₀(x)T₀(y) + 1·T₀(x)T₁(y) + 2·T₁(x)T₀(y) + 3·T₁(x)T₁(y)

= T₁(y) + 2·T₁(x)T₀(y) + 3·T₁(x)T₁(y)

หาอนุพันธ์ตาม axis=1 (y) (m=1, scl=1 default):

ใช้สูตร: d/dy Tₙ(y) = 2n·Uₙ₋₁(y) โดย U คือพหุนามเชบิเชฟชนิดที่สอง

แต่ NumPy คืนค่าใน basis เดิม (Chebyshev basis of first kind) ผลลัพธ์ shape (2, 1):

  • แถว 0 (x⁰): อนุพันธ์ของ T₁(y) = 2·T₀(y) → สัมประสิทธิ์ 1 (สำหรับ T₀)
  • แถว 1 (x¹): อนุพันธ์ของ 2·T₀(y) + 3·T₁(y) = 3·2·T₀(y) → สัมประสิทธิ์ 3

ผลลัพธ์: [[1.], [3.]] แทน 1·T₀(x)T₀(y) + 3·T₁(x)T₀(y)

อนุพันธ์อนุกรมเชบิเชฟสัมประสิทธิ์หลายมิติตามแกน 1 ใน Python

ใช้ chebyshev.chebder(axis=1) หาอนุพันธ์ตาม y ของอนุกรมเชบิเชฟ 2 มิติ T₁(y)+2T₁(x)T₀(y)+3T₁(x)T₁(y) ได้ 1·T₀(x)T₀(y)+3·T₁(x)T₀(y)