Compute the roots of a Legendre series in Python

PythonNumpyServer Side ProgrammingProgramming

To compute the roots of a Legendre series, use the polynomial.legendre.legroots() method in Python. The method returns an array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex. The parameter c is a 1-D array of coefficients.

Steps

At first, import the required library −

from numpy.polynomial import legendre as L

To compute the roots of a Legendre series, use the polynomial.legendre.legroots() method in Python −

print("Result...\n",L.legroots((0, 1, 2)))

Get the datatype −

print("\nType...\n",L.legroots((0, 1, 2)).dtype)

Get the shape −

print("\nShape...\n",L.legroots((0, 1, 2)).shape)

Example

from numpy.polynomial import legendre as L

# To compute the roots of a Legendre series, use the polynomial.legendre.legroots() method in Python
print("Result...\n",L.legroots((0, 1, 2)))

# Get the datatype
print("\nType...\n",L.legroots((0, 1, 2)).dtype)

# Get the shape
print("\nShape...\n",L.legroots((0, 1, 2)).shape)

Output

Result...
   [-0.76759188 0.43425855]

Type...
float64

Shape...
(2,)
raja
Updated on 09-Mar-2022 06:06:30

Advertisements