Add two polynomials
Given two polynomials A and B, write a program that adds the give
two polynomials A and B.
Output
Print the addition of polynomials A and B.
If the term with highest degree is negative, the term should be represented as -Cix^ ^ Pi .
For the term where power is 1 represent it as C1x instead of Cl*^ ^ 1 .
If the degree of polynomial is zero and the constant term is also ero, then just print 0 to represent the polynomial. For Lerm Cix^ ^ p i if the coefficient of the term Ci is 1, simply print x ^ P * i
instead of 7x p1
Explanation
If M = 4 and for polynomial A
For power 0, co-efficient is 5
For power 1, co-efficient is 0
For power 2, co-efficient is 10
For power 3, co-efficient is 6.
If N = 3 and for polynomial B
For power 0, co-efficient is 1
For power 1, co-efficient is 2
For power 2, co-efficient is 4.
And if result is zero print 0.
And if result has 1x solution it only x.
from numpy import poly1d
def disp_poly(i):
list1 = []
for i in range(i):
n = input('Enter coefficients')
list1.append(int(n))
poly_input = poly1d(list1)
return poly_input
print(disp_poly(4) + disp_poly(3))
Enter coefficients6
Enter coefficients10
Enter coefficients0
Enter coefficients5
Enter coefficients4
Enter coefficients2
Enter coefficients1
3 2
6 x + 14 x + 2 x + 6
Comments
Leave a comment