Generate Chebyshev series with given complex roots using NumPy in Python


Chebyshev series is a polynomial series referring to a series of Chebyshev Polynomials. A Chebyshev Polynomial is a Polynomial that is defined in a specific interval which is orthogonal in nature. It has a weight function $\mathrm{(1-x^{2})^{(-½)}}$. This polynomial is named after the Russian mathematician, Pafnuty Chebyshev.

Orthogonality is a specific type of relationship that defines two polynomials. Two polynomials are orthogonal in nature if their relationship satisfies certain conditions. For example, two functions can be considered orthogonal if their integration over a certain interval equates to 0.

Chebyshev Polynomials are defined as \mathTn(x). They are defined recursively as shown below:

$\mathrm{T_{0}(x)=1}$

$\mathrm{T_{1}(x)=x}$

$\mathrm{T_{2}(x)=2x*T_{(n-1)}(x)-T_{(n-2)}(x)}$

This shows that the nth Polynomial in the Chebyshev series can be calculated with the help of the preceding two polynomial values, (n-1) and (n-2). With this relation, we can recursively compute the Chebyshev series up to any order number

Each polynomial has a degree 'n' which provides these polynomials with useful properties in different areas of Engineering.

The required libraries for generating the Chebyshev series in Python are numpy and Scipy

pip install numpy
pip install scipy

Using NumPy, we can create arrays, find cosine values, and generate the value of pi, all of which we'll be using to generate the Chebyshev coefficients.

Algorithm

  • Import the necessary libraries.

  • Define a function to print the Chebyshev series to your preferred number.

  • Create an array of nodes from the interval [-1,1].

  • Transform the nodes to their respective intervals.

  • Compute the exponential value of the transformed nodes multiplied by a complex number (eix).

  • Compute the coefficients using Inverse Discrete Cosine Transform (IDCT).

  • Define the two intervals and the number of terms.

  • Call the function and print the coefficients.

Example

import numpy as np
from scipy.fftpack import idct

def chebyshev_series_complex(f, a, b, num_terms):
   # Create an array of Chebyshev nodes in the interval [-1, 1]
   nodes = np.cos(np.pi * (2 * np.arange(num_terms) + 1) / (2 * num_terms))

   # Transform the nodes to the desired interval [a, b]
   transformed_nodes = (b - a) / 2 * nodes + (a + b) / 2

   # Compute the function values at the transformed nodes
   function_values = f(transformed_nodes)

   # Compute the Chebyshev coefficients using the inverse discrete cosine transform (IDCT)
   chebyshev_coeffs = idct(function_values, type=1) / (num_terms - 1)

   return chebyshev_coeffs

# Example usage:
def complex_function(x):
   return np.exp(1j * x)  # e^(ix)

a = 0.0  # Lower bound of the interval
b = 2 * np.pi  # Upper bound of the interval
num_terms = 10  # Number of terms in the series

coefficients = chebyshev_series_complex(complex_function, a, b, num_terms)
print(coefficients)

Output

[ 4.54037708e-01-2.22044605e-16j  1.36850408e-17-6.76050971e-01j
  9.89722821e-01+2.57510063e-16j -4.31753398e-17+6.38292206e-01j
 -2.26373147e-01-7.70988212e-17j  1.48029737e-16-3.09382988e-02j
  1.00382982e-02+9.86864911e-17j -9.86864911e-17+2.14956728e-02j
 -1.15473450e-03-9.86864911e-17j  9.86864911e-17+1.70656312e-02j]

We first create an array of Chebyshev nodes by finding the cosine of the equation below:

(2*(num_term+1))/(2*num_term)

We then transform these nodes into their respective intervals [a,b] which will be given by the user by finding the difference between the intervals, and then halving them, and multiplying them with the node values: (b-a)/2*nodes. We add them to the sum of intervals halved (a+b)/2. The whole equation is:

(b-a)/2*nodes+(a+b)/2

In the user-defined function, f is used as a placeholder function in which you can customize the polynomial equation to your preference. Here, we’ve calculated the complex exponential value of the transformed nodes eix found earlier. You can add any Polynomial function.

After computing the function values, we perform Inverse Discrete Cosine Transform (IDCT) present in the SciPy library to create our Chebyshev Coefficients.

With this, we define the lower bound and upper bound of our intervals, along with the number of Chebyshev coefficients we need to be printed.

Conclusion

The Chebyshev series have applications in numerical analysis, complex mathematics and Engineering. They can also be used to solve differential equations, perform signal processing and provide mathematical approximation theories. It is a good function and has advantages over other methods when it comes to accuracy and convergence properties.

However, due to its multiple stages of processing, it can be computationally intensive. Despite its advantage in convergence properties, it too, has a limit and hence cannot cater to equations with rapid variations. Since the Chebyshev series provides the global approximation, that is, they approximate the function accurately over the entire interval space, it may require a large number of terms to increase its accuracy, hence leading to slower convergence.

Updated on: 10-Aug-2023

69 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements