Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

WRITE CODE IN PYTHON please. Automatic differentiation of polynomials. Realize i

ID: 3687579 • Letter: W

Question

WRITE CODE IN PYTHON please.

Automatic differentiation of polynomials. Realize it in this way. Use the 'input' function to get a polynomial and a x value (which means two 'input' functions in your program). An input polynomial should have a form of - a*x**n + b*x**(n-1)+... + constant 3*x**2 + 2*x +1 7.1*x**3+12.345*X** 0 5.3 * x ** 10 - 8.0 * x ** 1_-256 * x It shouldn't contain any variables except x. (The coefficients a, b,... and the exponent n in the above form must be just numbers. Exponents must be nonnegative integers.) You must not allow any parentheses in the input polynomial.- Use the methods of string type and the type conversion functions to calculate the output differentiation value.- Your program must be able to handle strange inputs by using the 'try-except-else' structure.-Test your program with your inputs. Add comments describing your test results.-

Explanation / Answer

import string class Polynomial: def __init__ ( self, var1 = 'x', coeff1 = [0]): """__init__(): This function is used to initialize a polynomial Default variable is x The Default polynomial is zero""" self.variable = var1 self.coefficient = coeff1 self.degree = len(coeff1)-1 def __string__ (self): """__string__(): This function is used to convert a polynomial into a string""" x = `self.coefficient[0]` for i in range (1, self.degree+1): x = x + " + " + `self.coefficient[i]` + self.variable + "^" + `i` return x def calculateDerivative(z): """Input: an instance of a polynomial Output: This is used to give that is the derivative of the input polynomial zvar1=z.var1 zcoeff1=[] if z.degree==0: return Poly (var1=zvar1,coeff1=[0]) else: for i in range(0,z.degree): d=(i+1) * z.coeff1[i+1] zcoeff1.append(d) return Polynomial (var1=zvar1,coeff1=zcoeff1) degree = input(' Please enter the degree of your polynomial') coef=[] for i in range (0,degree+1): coefficient1 = input(' now wnter the coefficient for x^ %i ? ' %i) coefficient.append(coefficient1) m = Polynomial (coeff1 = coefficient1) n = calculateDerivative(m) print "The derivative of %s is: %s" % (m,n) print " "