Friday, December 12, 2025
HomeLanguagesCompute the roots of a Legendre series in Python-NumPy

Compute the roots of a Legendre series in Python-NumPy

In this article, we will discuss how to compute the roots of a Legendre series in python.

legendre.legroots method

In python, the Legendre module provides many functions like legdre to perform arithmetic, and calculus operations on the Legendre series. It is one of the functions provided by the Legendre class. This method is used to return the roots of the given legendre series. It will take a one-dimensional array of coefficients. and return the series of an array of roots of the series. Below is the syntax of the legroots method.

Syntax: legendre.legroots((1Darray))

Parameter:

  • 1Darray: one dimensional array of coefficients.

Return: It will return the series of array of roots.

Example 1

 In this example, we are computing the roots of the Legendre series – (0, 1, 2,3,4,5,6).

Python3




# import legendre  method
from numpy.polynomial import legendre
 
# polynomial.legendre.legroots()
# method to compute roots
print(legendre.legroots((0, 1, 2, 3, 4, 5, 6)))
 
# return the datatype
print(legendre.legroots((0, 1, 2, 3, 4, 5, 6)).dtype)
 
# return the shape
print(legendre.legroots((0, 1, 2, 3, 4, 5, 6)).shape)


Output:

[-0.94803128 -0.68094906 -0.35894996  0.15452337  0.5104937   0.86836778]

float64

(6,)

Example 2

 In this example, we are computing the roots of the Legendre series using complex numbers – [-1 + 9j, 2 – 77j, 31 – 25j, 40 – 311j, 72 + 11j].

Python3




# import legendre  method
from numpy.polynomial import legendre
 
# polynomial.legendre.legroots() method to
# compute roots using complex no.
print(legendre.legroots([-1 + 9j, 2 - 77j,
                         31 - 25j, 40 - 311j,
                         72 + 11j]))
 
# return the datatype
print(legendre.legroots((0, 1)).dtype)
 
# return the shape
print(legendre.legroots((0, 1)).shape)


Output:

[-0.71259849+0.02245742j -0.06269287+0.03456655j  0.11691055+2.37064764j

  0.71665468+0.0316794j ]

float64

(1,)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32444 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6813 POSTS0 COMMENTS
Nicole Veronica
11951 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12027 POSTS0 COMMENTS
Shaida Kate Naidoo
6945 POSTS0 COMMENTS
Ted Musemwa
7198 POSTS0 COMMENTS
Thapelo Manthata
6892 POSTS0 COMMENTS
Umr Jansen
6881 POSTS0 COMMENTS