Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Chia chuỗi Chebyshev cho chuỗi Chebyshev khác trong Python

Giới thiệu

chebyshev.chebdiv() thực hiện phép chia đa thức Chebyshev: c1 / c2. Trả về tuple (quotient, remainder) - thương và dư, cả hai đều là mảng hệ số Chebyshev.

Ví dụ

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

c1 = np.array([1, 2, 3])  # T_0 + 2T_1 + 3T_2
c2 = np.array([3, 2, 1])  # 3T_0 + 2T_1 + T_2

print("c1:", c1)
print("c2:", c2)
print("c1 dtype:", c1.dtype)
print("c2 dtype:", c2.dtype)
print("c1 ndim:", c1.ndim)
print("c2 ndim:", c2.ndim)
print("c1 shape:", c1.shape)
print("c2 shape:", c2.shape)

quotient, remainder = C.chebdiv(c1, c2)
print("\nThương:", quotient)
print("Dư:", remainder)

Kết quả

c1: [1 2 3]
c2: [3 2 1]
c1 dtype: int64
c2 dtype: int64
c1 ndim: 1
c2 ndim: 1
c1 shape: (3,)
c2 shape: (3,)

Thương: [3.]
Dư: [-8. -4.]

Kiểm tra

c1 = c2 * quotient + remainder c2 * [3] = [9, 6, 3] (nhân Chebyshev, không phải nhân từng phần tử!) Trong cơ sở Chebyshev, nhân phức tạp hơn. Kết quả NumPy đảm bảo: c1 ≈ chebadd(chebmul(c2, quotient), remainder).