Compute the roots of a Legendre series with given complex roots in Python


To compute the roots of a Legendre series, use the polynomial.legendre.lagroots() 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

Compute the roots of a Legendre series −

j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))

Get the datatype −

print("\nType...\n",L.legroots((-j, j)).dtype)

Get the shape −

print("\nShape...\n",L.legroots((-j, j)).shape)

Example

from numpy.polynomial import legendre as L

# To compute the roots of a Legendre series, use the polynomial.legendre.lagroots() 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.
j = complex(0,1)
print("Result...\n",L.legroots((-j, j)))

# Get the datatype
print("\nType...\n",L.legroots((-j, j)).dtype)

# Get the shape
print("\nShape...\n",L.legroots((-j, j)).shape)

Output

Result...
   [1.+0.j]

Type...
complex128

Shape...
(1,)

Updated on: 09-Mar-2022

71 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements