Return the scaled companion matrix of a 1-D array of Hermite_e series coefficients in Python

PythonNumpyServer Side ProgrammingProgramming

To return the scaled companion matrix of a 1-D array of polynomial coefficients, return the hermite_e.hermecompanion() method in Python Numpy. The basis polynomials are scaled so that the companion matrix is symmetric when c is an Hermite_e basis polynomial. This provides better eigenvalue estimates than the unscaled case and for basis polynomials the eigenvalues are guaranteed to be real if numpy.linalg.eigvalsh is used to obtain them.

The method returns the Scaled companion matrix of dimensions (deg, deg). The parameter, c is a 1- D array of Hermite series coefficients ordered from low to high degree.

Steps

At first, import the required library −

import numpy as np
from numpy.polynomial import hermite_e as H

Create a 1D array of coefficients −

c = np.array([1, 2, 3])

Display the array −

print("Our 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 return the scaled companion matrix of a 1-D array of polynomial coefficients, return the hermite_e.hermecompanion() method in Python −

print("\nResult...\n",H.hermecompanion(c))

Example

import numpy as np
from numpy.polynomial import hermite_e as H

# Create a 1D array of coefficients
c = np.array([1, 2, 3])

# Display the array
print("Our 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 return the scaled companion matrix of a 1-D array of polynomial coefficients, return the hermite_e.hermecompanion() method in Python Numpy
print("\nResult...\n",H.hermecompanion(c))

Output

Our Array...
   [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(3,)

Result...
   [[ 0. 0.66666667]
   [ 1. -0.66666667]]
raja
Updated on 11-Mar-2022 05:07:46

Advertisements