Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python class of Polynomials Project: In this project, we implement the class of polynomials and apply Horner's method of synthetic division to efficiently evaluate polynomials.

Python class of Polynomials Project: In this project, we implement the class of polynomials and apply Horner's method of synthetic division to efficiently evaluate polynomials.

Not that ifthen the degree of the polynomial is n-1 and the length of its coefficient list is n. You should make sure that your constructor (the __init__ method) enforces this relationship by always ensuring that the highest (the last) coefficient is non-zero. Thus, when constructing a new polynomial object with a given coefficient list, zeros at the end of the list should be removed. Notice that this implies that the zero polynomial is represented by the empty list. Please use the following class statement:

class poly(): \"\"\"The class of polynomials\"\"\" to define the class. The class should contain definitions for at least the following methods, with the indicated function definition headers:

def __init__(self,*coeffs): \"\"\"creates a new poly object, with the given coefficients\"\"\"

def degree(self): \"\"\"returns the degree of self\"\"\"

def coefficients(self): \"\"\"returns the list of coefficients of self\"\"\"

def __repr__(self): \"\"\"returns a string representation of self\"\"\"

def is_zero(self): \"\"\"returns True if self is the zero polynomial, returns False otherwise\"\"\"

def __eq__(self,other): \"\"\"returns True if self - other is the zero polynomial; False otherwise\"\"\"

def __ne__(self,other): \"\"\"returns the negation of __eq__(self,other)\"\"\"

def __neg__(self): \"\"\"returns the negative of self\"\"\"

def __add__(self,other): \"\"\"returns self plus other\"\"\"

def __sub__(self,other): \"\"\"returns self minus other\"\"\"

def __mul__(self,other): \"\"\"returns the product of self and other\"\"\"

def __pow__(self,m): \"\"\"returns the mth power of self (m is a positive integer)\"\"\"

def coeff(self,exp): \"\"\"returns the coefficient of x**exp in self\"\"\"

def derivative(self): \"\"\"returns the derivative of self\"\"\"

Then define the following magic method in the poly class:

def __divmod__(self,a): \"\"\"returns the pair (q,r) such that q is the quotient and r is the remainder when self is divided by x-a using Horners method of synthetic division\"\"\"

Follow the example given above in coding this method. To test the method, note that Python maps __divmod__ to its builtin divmod function, so typing the expression divmod(f,a) should return the pair (q,r) such that q is the quotient polynomial and the remainder r is equal to the number f(a)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions