
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generate Legendre Series with Given Roots in Python
To generate a Legendre series, use the polynomial.legendre.legfromroots() method in Python. The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real. The parameter roots are the sequence containing the roots.
Steps
At first, import the required library −
import numpy as np from numpy.polynomial import legendre as L
To generate a Legendre series, use the polynomial.legendre.legfromroots() method in Python −
print("Result...\n",L.legfromroots((-1,0,1)))
Get the datatype −
print("\nType...\n",L.legfromroots((-1,0,1)).dtype)
Get the shape −
print("\nShape...\n",L.legfromroots((-1,0,1)).shape)
Example
import numpy as np from numpy.polynomial import legendre as L # To generate a Legendre series, use the polynomial.legendre.legfromroots() method in Python print("Result...\n",L.legfromroots((-1,0,1))) # Get the datatype print("\nType...\n",L.legfromroots((-1,0,1)).dtype) # Get the shape print("\nShape...\n",L.legfromroots((-1,0,1)).shape)
Output
Result... [ 0. -0.4 0. 0.4] Type... float64 Shape... (4,)
Advertisements