Question: Please do it in python Problem 2 - Polynomials (15 Points) Consider a general form of an nth order polynomial. You are asked to implement
Please do it in python
Problem 2 - Polynomials (15 Points) Consider a general form of an nth order polynomial. You are asked to implement a polynomial of arbitrary degree using classes in python. For instance consider the polynomial: 7x4 +2x2 +5=0 For this implements the following steps: 1. Implement a class that represents a single term. 2. Implement a class for the entire polynomial 3. Implement an operator () to multiply two single terms, a term and a polynomial, and two polynomials. (Note: you can overload the operator in Python by defining a method called_mul_(self,other): and make it mutiply the self object with the other object) 4. Implement an operator(s) that enables addition of a term and a polynomial and/or two polynomials. (Note:_you can overload the +operator in Python by defining a method called_add_(self,other) : and make it add the self object with the other object) 5. Implement the following two internal methods within Polynomial class: order () , which returns the order of the polynomial (as an int) solve() , which returns solutions for the polynomial (a list of roots). Only do it for quadratic polynomials, and raise an exception for higher order polynomials. 6. Implement an external function that plots the polynomial on a domain of -10,10] (you will have to use matplotlib rountines for this) 7. Include a destructor function for the polynomial class. Use the above class definitions and operators to generate the solutions (wherever needed) for the following set of polynomials: 1. x - 3r3 +9x2 +5x +60 2. x3 - 8x5 0 4. Consider the following three polynomials: f(x) = 3x-l, g(x) = r-2 andp(x) = 8x2 + 4. Plot the function f(x)-g(x) *p(x) = 0 by taking f g p as input functions. For this, use the mul_ (self,other) and add _(self,other) methods Note: Here you are basically asked to define the basis for the vector space of real polynomials and define all the vector operations. Problem 2 - Polynomials (15 Points) Consider a general form of an nth order polynomial. You are asked to implement a polynomial of arbitrary degree using classes in python. For instance consider the polynomial: 7x4 +2x2 +5=0 For this implements the following steps: 1. Implement a class that represents a single term. 2. Implement a class for the entire polynomial 3. Implement an operator () to multiply two single terms, a term and a polynomial, and two polynomials. (Note: you can overload the operator in Python by defining a method called_mul_(self,other): and make it mutiply the self object with the other object) 4. Implement an operator(s) that enables addition of a term and a polynomial and/or two polynomials. (Note:_you can overload the +operator in Python by defining a method called_add_(self,other) : and make it add the self object with the other object) 5. Implement the following two internal methods within Polynomial class: order () , which returns the order of the polynomial (as an int) solve() , which returns solutions for the polynomial (a list of roots). Only do it for quadratic polynomials, and raise an exception for higher order polynomials. 6. Implement an external function that plots the polynomial on a domain of -10,10] (you will have to use matplotlib rountines for this) 7. Include a destructor function for the polynomial class. Use the above class definitions and operators to generate the solutions (wherever needed) for the following set of polynomials: 1. x - 3r3 +9x2 +5x +60 2. x3 - 8x5 0 4. Consider the following three polynomials: f(x) = 3x-l, g(x) = r-2 andp(x) = 8x2 + 4. Plot the function f(x)-g(x) *p(x) = 0 by taking f g p as input functions. For this, use the mul_ (self,other) and add _(self,other) methods Note: Here you are basically asked to define the basis for the vector space of real polynomials and define all the vector operations
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
