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

แยกความแตกต่างของชุด Chebyshev ด้วยสัมประสิทธิ์หลายมิติใน Python


ในการแยกแยะชุด Chebyshev ให้ใช้เมธอด polynomial.chebder() ใน Python Numpy เมธอดจะคืนค่าอนุกรม Chebyshev ของอนุพันธ์ ส่งกลับค่าสัมประสิทธิ์อนุกรม Chebyshev c แตกต่าง m ครั้งตามแกน ในการวนซ้ำแต่ละครั้ง ผลลัพธ์จะถูกคูณด้วย scl อาร์กิวเมนต์ c คืออาร์เรย์ของสัมประสิทธิ์จากระดับต่ำถึงสูงในแต่ละแกน เช่น [1,2,3] แทนชุดข้อมูล 1*T_0 + 2*T_1 + 3*T_2 ขณะที่ [[1,2],[1 ,2]] หมายถึง 1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) + 2*T_0(x)*T_1(y) + 2*T_1(x)*T_1( y) ถ้า axis=0 คือ x และ axis=1 คือ y.

พารามิเตอร์ที่ 1 คือ c ซึ่งเป็นอาร์เรย์ของสัมประสิทธิ์อนุกรม Chebyshev ถ้า c เป็นแบบหลายมิติ แกนที่ต่างกันจะสัมพันธ์กับตัวแปรต่างๆ โดยมีระดับในแต่ละแกนที่กำหนดโดยดัชนีที่เกี่ยวข้อง พารามิเตอร์ตัวที่ 2 คือ m จำนวนอนุพันธ์ที่นำมา ต้องไม่เป็นค่าลบ (ค่าเริ่มต้น:1)

พารามิเตอร์ตัวที่ 3 คือ scl นั่นคือ ค่าความแตกต่างแต่ละรายการจะถูกคูณด้วย scl ผลลัพธ์ที่ได้คือการคูณด้วย scl**m ใช้สำหรับการเปลี่ยนแปลงเชิงเส้นของตัวแปร (ค่าเริ่มต้น:1). พารามิเตอร์ที่ 4 คือ แกน นั่นคือ แกนที่นำอนุพันธ์มา (ค่าเริ่มต้น:0).

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

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

สร้างอาร์เรย์หลายมิติของสัมประสิทธิ์อนุกรม Chebyshev -

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)

ในการแยกแยะอนุกรม Chebyshev ให้ใช้เมธอด polynomial.chebder() ใน Python -

print("\nResult...\n",C.chebder(c))

ตัวอย่าง

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

# Create a multidimensional array of Chebyshev series coefficients
c = np.arange(4).reshape(2,2)

# Display the coefficient array
print("Our coefficient Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To differentiate a Chebyshev series, use the polynomial.chebder() method in Python Numpy.

# The method returns the Chebyshev series of the derivative.
print("\nResult...\n",C.chebder(c))

ผลลัพธ์

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...
[[2. 3.]]