VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-subtract-one-polynomial-to-another-using-numpy-in-python/

⇱ How to subtract one polynomial to another using NumPy in Python? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to subtract one polynomial to another using NumPy in Python?

Last Updated : 15 Jul, 2025

In this article, let's discuss how to subtract one polynomial to another. Two polynomials are given as input and the result is the subtraction of two polynomials.

  • The polynomial p(x) = C3 x2 + C2 x + C1  is represented in NumPy as : ( C1, C2, C3 ) { the coefficients (constants)}.
  • Let take two polynomials p(x) and q(x) then subtract these to get r(x) = p(x) - q(x) as a result of subtraction of two input polynomials.
If p(x) = A3 x2 + A2 x + A1 
and
q(x) = B3 x2 + B2 x + B1 

then result is 
r(x) = p(x) - q(x) i.e;
r(x) = (A3 - B3) x2 + (A2 - B2) x + (A1 - B1) 

and output is 
( (A1 - B1), (A2 - B2), (A3 - B3) ).

In NumPy, it can be solved using the polysub() method. This function helps to find the difference of two polynomials and then returning the result as a polynomial

Below is the implementation with some examples :

Example 1:  Using  polysub()

Output :

[ 3. 3. 3.]

Example 2: sub_with_decimals

Output :

[-9.8 0. -1.8]

Example 3:  #eval_then_sub

Output :

[ 1.75 1.66666667 -1.8 ] 
Comment