Return the scaled companion matrix of a 1-D array of Legendre polynomial coefficients in Python


To return the scaled companion matrix of a 1-D array of Legendre polynomial coefficients, use the legendre.legcompanion() method in Python Numpy. The usual companion matrix of the Legendre polynomials is already symmetric when c is a basis Laguerre polynomial, so no scaling is applied.

Returns the scaled Companion matrix of dimensions (deg, deg). The parameter, c is a 1-D array of Legendre series coefficients ordered from low to high degree.

Steps

At first, import the required library −

import numpy as np
from numpy.polynomial import legendre as L

Create a 1D array of coefficients −

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

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 Legendre polynomial coefficients, use the legendre.legcompanion() method in Python Numpy. The usual companion matrix of the Legendre polynomials is already symmetric when c is a basis Laguerre polynomial, so no scaling is applied −

print("\nResult...\n",L.legcompanion(c))

Example

import numpy as np
from numpy.polynomial import legendre as L

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

# 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 Legendre polynomial coefficients, use the legendre.legcompanion() method in Python Numpy
print("\nResult...\n",L.legcompanion(c))

Output

Our Array...
   [1 2 3 4 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [[ 0.           0.57735027     0.           -0.30237158]
   [ 0.57735027    0.             0.51639778   -0.34914862]
   [ 0.            0.51639778     0.            0.10141851]
   [ 0.            0.             0.50709255   -0.45714286]]

Updated on: 10-Mar-2022

87 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements