Compute the derivative of a polynomial. A polynomial can be represented by a dictionary as explained in Chapter XXXXXXXXXXWrite a function diff for differentiating such a polynomial. The diff function...


Compute the derivative of a polynomial.


A polynomial can be represented by a dictionary as explained in Chapter 6.2.3. Write a function diff for differentiating such a polynomial. The diff function takes the polynomial as a dictionary argument and returns the dictionary representation of the derivative. Recall the formula for differentiation of polynomials:


This means that the coefficient of the x
j−1

term in the derivative equals j times the coefficient of x j term of the original polynomial. With p as the polynomial dictionary and dp as the dictionary representing the derivative, we then have dp[j-1] = j*p[j] for j running over all keys in p, except when j equals 0.


Here is an example of the use of the function diff:


>>> p = {0: -3, 3: 2, 5: -1} # -3 + 2*x**3 - x**5


>>> diff(p) # should be 6*x**2 - 5*x**4


{2: 6, 4: -5}


 Name of program file: poly_diff.py.

Nov 26, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here