

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 a monic polynomial with given roots in Python
To generate a monic polynomial with given roots, use the polynomial.polyfromroots() method in Python Numpy. The method returns the 1-D array of the polynomial’s coefficients If all the roots are real, then out is also real, otherwise it is complex. The parameter roots are the sequence containing the roots.
Steps
At first, import the required library −
from numpy.polynomial import polynomial as P
Generating a monic polynomial −
print("Result...\n",P.polyfromroots((-1,0,1)))
Get the datatype −
print("\nType...\n",P.polyfromroots((-1,0,1)).dtype)
Get the shape −
print("\nShape...\n",P.polyfromroots((-1,0,1)).shape)
Example
from numpy.polynomial import polynomial as P # To generate a monic polynomial with given roots, use the polynomial.polyfromroots() method in Python Numpy. # The method returns the 1-D array of the polynomial’s coefficients If all the roots are real, then out is also real, otherwise it is complex. # The parameter roots are the sequence containing the roots. # x(x - 1)(x + 1) = x^3 - x print("Result...\n",P.polyfromroots((-1,0,1))) # Get the datatype print("\nType...\n",P.polyfromroots((-1,0,1)).dtype) # Get the shape print("\nShape...\n",P.polyfromroots((-1,0,1)).shape)
Output
Result... [ 0. -1. 0. 1.] Type... float64 Shape... (4,)
- Related Questions & Answers
- Generate a monic polynomial with given complex roots in Python
- Compute the roots of a polynomial with given complex roots in Python
- Generate a Chebyshev series with given roots in Python
- Generate a Hermite series with given roots in Python
- Generate a Laguerre series with given roots in Python
- Generate a Legendre series with given roots in Python
- Generate a Hermite_e series with given roots in Python
- Generate a Chebyshev series with given complex roots in Python
- Generate a Laguerre series with given complex roots in Python
- Generate a Hermite series with given complex roots in Python
- Generate a Legendre series with given complex roots in Python
- Generate a Hermite_e series with given complex roots in Python
- Compute the roots of a polynomial in Python
- Minimize the sum of roots of a given polynomial in C++
- Compute the roots of a Chebyshev series with given complex roots in Python
Advertisements