Compute the roots of a Legendre series in Python-NumPy
Last Updated :
23 Dec, 2022
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
from numpy.polynomial import legendre
print (legendre.legroots(( 0 , 1 , 2 , 3 , 4 , 5 , 6 )))
print (legendre.legroots(( 0 , 1 , 2 , 3 , 4 , 5 , 6 )).dtype)
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
from numpy.polynomial import legendre
print (legendre.legroots([ - 1 + 9j , 2 - 77j ,
31 - 25j , 40 - 311j ,
72 + 11j ]))
print (legendre.legroots(( 0 , 1 )).dtype)
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,)
Share your thoughts in the comments
Please Login to comment...