Question: (Same as P8.7) Write a Python program that can store a polynomial such as ()=510+9710p(x)=5x10+9x7x10 as a list of terms. A term contains the coefficient

(Same as P8.7) Write a Python program that can store a polynomial such as

()=510+9710p(x)=5x10+9x7x10

as a list of terms. A term contains the coefficient and the power of x. For example, you would store the above ()p(x) as

 [(5, 10), (9, 7), (1, 1), (10, 0)]
  • Write functions to add_, _multiply_, _evaluate_, and _print polynomials.

  • Write a function that makes a polynomial from a single term. For example, the polynomial p can be constructed as

     p = new_polynomial( -10, 0 ) add_term( p, -1, 1 ) add_term( p, 9, 7 ) add_term( p, 5, 10 )
  • Then compute ()()p(x)p(x).

     q = multiply( p, p ) print_polynomial( q )
  • Finally, evaluate a polynomial, given the variable (say, x) value:

     v = evaulate( p, 1 )

should return 3 [(=1)=5(1)10+9(1)7110=5+9110=3][p(x=1)=5(1)10+9(1)7110=5+9110=3].

In [ ]:

 
 

(Same as P8.8) Repeat Question 3 but use a dictionary for the coefficients.

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!