Subtract one Chebyshev series from another in Python

To subtract one Chebyshev series from another, use the polynomial.chebyshev.chebsub() method in NumPy. The method returns an array of Chebyshev series coefficients representing their difference c1 - c2. The sequences of coefficients are ordered from lowest to highest order term, i.e., [1,2,3] represents the series T_0 + 2*T_1 + 3*T_2.

Syntax

numpy.polynomial.chebyshev.chebsub(c1, c2)

Parameters

The parameters c1 and c2 are 1-D arrays of Chebyshev series coefficients ordered from low to high degree terms.

Basic Example

Let's start with a simple example of subtracting two Chebyshev series ?

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

# Create 1-D arrays of Chebyshev series coefficients
c1 = np.array([1, 2, 3])
c2 = np.array([3, 2, 1])

print("Array1:", c1)
print("Array2:", c2)

# Subtract c2 from c1
result = C.chebsub(c1, c2)
print("Result (c1 - c2):", result)
Array1: [1 2 3]
Array2: [3 2 1]
Result (c1 - c2): [-2.  0.  2.]

Different Length Series

The function can handle Chebyshev series of different lengths ?

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

# Series of different lengths
c1 = np.array([1, 2, 3, 4])
c2 = np.array([2, 1])

print("Series 1:", c1)
print("Series 2:", c2)

result = C.chebsub(c1, c2)
print("Result:", result)
Series 1: [1 2 3 4]
Series 2: [2 1]
Result: [-1.  1.  3.  4.]

Working with Decimal Coefficients

The method also works with floating-point coefficients ?

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

# Decimal coefficients
c1 = np.array([1.5, 2.7, 3.2])
c2 = np.array([0.5, 1.2, 2.1])

print("Series 1:", c1)
print("Series 2:", c2)

result = C.chebsub(c1, c2)
print("Result:", result)
Series 1: [1.5 2.7 3.2]
Series 2: [0.5 1.2 2.1]
Result: [1.  1.5 1.1]

How It Works

The subtraction is performed coefficient-wise. If the series have different lengths, the shorter one is treated as having zero coefficients for the missing higher-order terms. The result represents the Chebyshev series: (c1[0] - c2[0]) + (c1[1] - c2[1])*T_1 + (c1[2] - c2[2])*T_2 + ...

Conclusion

Use numpy.polynomial.chebyshev.chebsub() to subtract Chebyshev series coefficient-wise. The function handles arrays of different lengths and returns the difference as a new coefficient array.

Updated on: 2026-03-26T19:42:17+05:30

193 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements