numpy.polysub () in Python

NumPy | Python Methods and Functions

numpy.polysub () : This function helps you find the difference between two polynomials and then return the result as a polynomial. Each input polynomial must be a sequence of polynomial coefficients, from highest to lowest degree.

  Parameters:   p1:  Input polynomial 1: 1x + 2.  p2:  Input polynomial 2: 9x  2  + 5x + 4 

Return :

 Difference of polynomials: (0-9) x  2  + (1-5) x + (2-4) 

# Code Python explaining
# numpy.polysub ()

 
# importing libraries

import numpy as np

 

p1 = np.poly1d ([ 1 , 2 ])

p2 = np.poly1d ([ 9 , 5 , 4 ])

 

print ( "P1:" , p1)

print ( "P2:" , p2)

 

a = np.polysub (p1, p2)

 

print ( "P1 - P2: " , a)

Output:

 P1: 1 x + 2 P2: 2 9 x + 5 x + 4 P1 - P2: 2 -9 x - 4 x - 2 




Get Solution for free from DataCamp guru