## Question

Like most programming languages, Python has built-in support for only very basic data types, such as numbers, strings and arrays (lists), and a few others. More complicated data types can be built up from these, using classes for example.

However, lists are already robust enough to represent polynomials for many applications.

We simply represent a polynomial as an ordered list of its coefficients. The polynomial f(x) = 2 − x + x² could be represented in Python as the list [2,-1,1]. The polynomial g(x) = 4 − x³ could be represented as [4,0,0,-1], and so on.

In this assignment, you’ll implement a few basic functions for dealing with polynomials.

1. (10 points) Finish writing the function poly eval(f,a) which evaluates the polynomial f at the real number a and returns the result.

2. (10 points) Finish writing the function poly quad formula(f) which uses the quadratic formula to find and return the roots of the quadratic polynomial f. Your function should work whether the roots are real or complex. Your function should first verify that the degree of f is 2; if not, it should just print a brief error message and return an empty list.

3. (10 points) Finish writing the function poly derivative(f) which computes and returns the derivative of the polynomial f. This function should work for all polynomials - not just quadratic ones!

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# We will use lists of numbers to represent polynomials.# If A is such a list, A[j] is the coefficient of x^j.

# cmath is Python's library for doing some math with complex numbers.

import cmath

###################################################

# A function to return the degree of a polynomial.

def poly_degree(f):

deg = -float('inf')

# Start with deg = -infinity because this is the

# degree of the zero polynomial. Then we'll look

# for nonzero coefficients of powers of x and adjust it.

i=0

while (i < len(f)):

if f[i] != 0:

deg = i

i += 1

return deg

#####################################################

# A function that returns a string representation of

# a polynomial with real coefficients (useful for printing)

def poly_to_string(f):

d = poly_degree(f)

if (d < 0):

return "0"

i=0

firstTerm...

By purchasing this solution you'll be able to access the following files:

Solution.py.