- 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

# Subtract one polynomial to another in Python

To subtract one polynomial to another, use the numpy.polynomial.polynomial.polysub() method in Python. Returns the difference of two polynomials c1 + c2. The arguments are sequences of coefficients from lowest order term to highest, i.e., [1,2,3] represents the polynomial 1 + 2*x + 3*x**2.

The method returns the coefficient array representing their difference. The parameters c1 and c2 returns 1-D arrays of polynomial coefficients ordered from low to high.

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

Declare Two Polynomials −

p1 = (3,1,6) p2 = (2,7,3)

Display the polynomials −

print("Polynomial 1...\n",p1) print("\nPolynomial 2...\n",p2)

To subtract one polynomial to another, use the numpy.polynomial.polynomial.polysub() method −

diffRes = P.polysub(p1,p2); print("\nResult (Difference)...\n",diffRes)

## Example

from numpy.polynomial import polynomial as P # Declare Two Polynomials p1 = (3,1,6) p2 = (2,7,3) # Display the polynomials print("Polynomial 1...\n",p1) print("\nPolynomial 2...\n",p2) # To subtract one polynomial to another, use the numpy.polynomial.polynomial.polysub() method in Python. diffRes = P.polysub(p1,p2); print("\nResult (Difference)...\n",diffRes)

## Output

Polynomial 1... (3, 1, 6) Polynomial 2... (2, 7, 3) Result (Difference)... [ 1. -6. 3.]

- Related Questions & Answers
- Add one polynomial to another in Python
- Multiply one polynomial to another in Python
- Divide one polynomial by another in Python
- Subtract one Chebyshev series from another in Python
- Subtract one Hermite series from another in Python
- Subtract one Laguerre series from another in Python
- Subtract one Legendre series from another in Python
- Subtract one Hermite_e series from another in Python
- Subtract one BigInteger from another BigInteger in Java
- Subtract one BigDecimal from another BigDecimal in Java
- How to subtract one data frame from another in R?
- Add one Python string to another
- PHP – How to subtract one arbitrary precision number from another using bcsub() function?
- Add one Chebyshev series to another in Python
- Multiply one Hermite series to another in Python