
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Generate a monic polynomial with given complex roots in Python
To generate a monic polynomial with given complex 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 libraries -
from numpy.polynomial import polynomial as P
Given complex roots −
j = complex(0,1) print("Result...\n",P.polyfromroots((-j,j)))
Get the datatype −
print("\nType...\n",P.polyfromroots((-j, j)).dtype)
Get the shape −
print("\nShape...\n",P.polyfromroots((-j, j)).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. j = complex(0,1) print("Result...\n",P.polyfromroots((-j,j))) # Get the datatype print("\nType...\n",P.polyfromroots((-j, j)).dtype) # Get the shape print("\nShape...\n",P.polyfromroots((-j, j)).shape)
Output
Result... [1.+0.j 0.+0.j 1.+0.j] Type... complex128 Shape... (3,)
- Related Articles
- Generate a monic polynomial with given roots in Python
- Compute the roots of a polynomial with given complex 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
- 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
- Compute the roots of a Chebyshev series with given complex roots in Python
- Compute the roots of a Laguerre series with given complex roots in Python
- Compute the roots of a Hermite series with given complex roots in Python

Advertisements