Question: [EC1-4] ( poly1.py ) Represent a polynomial p(x) as a list L of the float coefficients of each term. L[0] is the constant ( x

[EC1-4] (poly1.py) Represent a polynomial p(x) as a list L of the float coefficients of each term. L[0] is the constant (x0) term of p(x), L[1] is the x1 coefficient, L[2] is the x2 coefficient, and so forth. Example: x2+3x+2 = 1.0*x2+3.0*x1+2.0*x0 is represented by [2.0, 3.0, 1.0].

Write a program which reads two polynomials p(x) and q(x) from the user as lists of their coefficients, then prints out the list equivalent of (a) p(x)+q(x) and (b) p(x)*q(x).

Read the two polynomials as follows. Prompt the user to enter the coefficients for p(x) as L[0], L[1], L[2],... with the user entering an empty string (ENTER) as a no-more-data sentinel. Then do the same for q(x).

[EC1-5] (poly2.py) The previous problem's representation is inefficient for polynomials where most terms have 0 coefficients, such as x100 + 3x + 1. This would be represented as L==[1.0,3.0,0.0,0.0,...1.0] with len(L)==101.

Instead, represent a polynomial p(x) as a list of tuples (exp,coeff), where the first element is the int exponent of a term, and the second is the float coefficient of the same term. With this alternate approach, x100 + 3x + 1 is represented by [(0,1),(1,3),(100,1)].

Write a program which does the same thing as the previous problem but uses this alternate "compact" polynomial representation. Your program should read two polynomials p(x) and q(x) from the user as lists of (exp,coeff) tuples, with user entry of any empty string signaling end-of-input for a polynomial. You should then print out the list representation of (a) p(x)+q(x) and (b) p(x)*q(x).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!