Raise a polynomial to a power in Python

PythonNumpyServer Side ProgrammingProgramming

To raise a polynomial to a power, use the numpy.polynomial.polynomial.polypow() method in Python. Returns the polynomial c raised to the power pow. The argument c is a sequence of coefficients ordered from low to high. i.e., [1,2,3] is the series 1 + 2*x + 3*x**2. The method returns the array of coefficient series representing the quotient and remainder.

The 1st parameter, c is a 1-D array of array of series coefficients ordered from low to high degree. The 2nd parameter, pow is a Power to which the series will be raised. The 3rd parameter, maxpower, is the maximum power allowed. This is mainly to limit growth of the series to unmanageable size. Default is 16.

This numpy.polynomial.polynomial module provides a number of objects useful for dealing with polynomials, including a Polynomial class that encapsulates the usual arithmetic operations.

Steps

At first, import the required libraries −

from numpy.polynomial import polynomial as P

Polynomial and a power −

poly = (4,1,6)
power = 3

Display the polynomial −

print("Polynomial...\n",poly)

Display the power −

print("\nPower...\n",power)

To raise a polynomial to a power, use the numpy.polynomial.polynomial.polypow() method in Python. Returns the polynomial c raised to the power pow. The argument c is a sequence of coefficients ordered from low to high. i.e., [1,2,3] is the series 1 + 2*x + 3*x**2 −

res = P.polypow(poly,power);
print("\nResult...\n",res)

Example

from numpy.polynomial import polynomial as P

# Polynomial and a power
poly = (4,1,6)
power = 3

# Display the polynomial
print("Polynomial...\n",poly)

# Display the power
print("\nPower...\n",power)

# To raise a polynomial to a power, use the numpy.polynomial.polynomial.polypow() method in Python.
res = P.polypow(poly,power);
print("\nResult...\n",res)

Output

Polynomial...
(4, 1, 6)

Power...
3

Result...
[ 64. 48. 300. 145. 450. 108. 216.]
raja
Updated on 28-Feb-2022 10:24:19

Advertisements