Open In App

Return the scaled companion matrix of a 1-D array of Chebyshev series coefficients using NumPy in Python

Last Updated : 03 Jun, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to return the scaled companion matrix of a 1D array of Chebyshev series coefficients in python.

chebyshev.chebcompanion() method 

chebyshev.chebcompanion() method provides the eigenvalue estimates than the unscaled case and for basis polynomials. We can say that the eigenvalues are guaranteed to be real if numpy.linalg.eigvalsh is used to obtain them. This method will take the coefficient array as a parameter which is a 1-D array of Chebyshev series coefficients ordered from low degree to high degree and return the  Scaled companion matrix of dimensions.

Syntax: chebyshev.chebcompanion(coefficient_array)

Parameters:

  • coefficient_array: It will take coefficient array as parameter which is an1-D array of Chebyshev series coefficients ordered from low degree to high degree.

Return: Scaled companion matrix of dimensions (deg, deg)

Example 1:

In this example, we are creating a one-dimensional array with 3 coefficients and returning the scaled companion matrix along with shape, dimensions, and datatype. It returned a 2D scaled companion matrix.

Python3




# import packages
import numpy as np
from numpy.polynomial import chebyshev
  
# array of coefficients
c = np.array([2,2,3])
print(c)
  
# shape of the array is
print("Shape of the array is : ",c.shape)
  
# dimension of the array
print("The dimension of the array is : ",c.ndim)
  
# Datatype of the array
print("Datatype of our Array is : ",c.dtype)
  
# return the scaled companion matrix 
# of a 1-D array 
print(chebyshev.chebcompanion(c))


Output:

[2 2 3]
Shape of the array is :  (3,)
The dimension of the array is :  1
Datatype of our Array is :  int64
[[ 0.          0.23570226]
 [ 0.70710678 -0.33333333]]

Example 2:

In this example, we are creating a one-dimensional array with 5  coefficients and returning the scaled companion matrix along with shape, dimensions and datatype.  It returned 2D scaled companion matrix.

Python3




# import packages
import numpy as np
from numpy.polynomial import chebyshev
  
# array of coefficients
c = np.array([1,2,3,4,5])
print(c)
  
# shape of the array is
print("Shape of the array is : ",c.shape)
  
# dimension of the array
print("The dimension of the array is : ",c.ndim)
  
# Datatype of the array
print("Datatype of our Array is : ",c.dtype)
  
# return the scaled companion matrix of 
# a 1-D array 
print(chebyshev.chebcompanion(c))


Output:

[1 2 3 4 5]
Shape of the array is :  (5,)
The dimension of the array is :  1
Datatype of our Array is :  int64
[[ 0.          0.70710678  0.         -0.14142136]
 [ 0.70710678  0.          0.5        -0.2       ]
 [ 0.          0.5         0.          0.2       ]
 [ 0.          0.          0.5        -0.4       ]]


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads