![]() |
VOOZH | about |
In this article, we will make a NumPy program to multiply one polynomial to another. Two polynomials are given as input and the result is the multiplication of two 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) and output is ( (A1 * B1), (A2 * B1) + (A2 * B1), (A3 * B1) + (A2 * B2) + (A1 * B3), (A2 * B2) + (A3 * B2), (A3 * B3) ).
This can be calculated using the polymul() method of NumPy. This method evaluates the product of two polynomials and returns the polynomial resulting from the multiplication of two input polynomials ‘p1’ and ‘p2’.
Syntax:
numpy.polymul(p1, p2)
Below is the implementation with some examples :
Example 1:
Output :
[ 10. -29. 30. -29. 10.]
Example 2 :
Output :
[ 0. 0. 21.56 0. 8.8 ]
Example 3 :
Output :
[ 0. -2.91666667 0. 3. ]