Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

pls use Python to do this thank you Polynomials For this problem set, we will be representing polynomials as tuples. The index of a number

pls use Python to do this thank you

Polynomials

For this problem set, we will be representing polynomials as tuples. The index of a number in the tuple represents the power, and the value at that index represents the coefficient for that term. So for example, the polynomial

x4 + 3x3 + 17.5x2 13.39 would be represented by the tuple (-13.39, 0.0, 17.5, 3.0, 1.0). This is because the tuple represents -13.39x0 + 0.0x1 + 17.5x2 + 3.0x3+ 1.0x4 , which is the same as x4 + 3.0x3 + 17.5x2 13.39.

Problem #1

Implement the evaluate_poly function. This function evaluates a polynomial function for the given x value. It takes in a tuple of numbers polyand a number x. By number, we mean that x and each element of poly is a float. evaluate_polytakes the polynomial represented by poly and computes its value at x. It returns this value as a float.

def evaluate_poly(poly, x):
"""
Computes the polynomial function for a given value x. Returns that value.

Example:
>>> poly = (0.0, 0.0, 5.0, 9.3, 7.0) # f(x) = 7x^4 + 9.3x^3 + 5x^2
>>> x = -13
>>> print(evaluate_poly(poly, x)) # f(-13) = 7(-13)^4 + 9.3(-13)^3 + 5(-13)^2
180339.9

poly: tuple of numbers, length > 0
x: number
returns: float
"""
# TO DO ...

Derivatives

As stated before, we will need to find f'(x), where f'(x) is the derivative of f(x). Recall that the derivative of a polynomial f(x) = axb is f'(x) = abxb - 1, unless b = 0, in which case f'(x) = 0. To compute the derivative of a polynomial function with many terms, you just do the same thing to every term individually. For example, if f(x) = x4 + 3x3 + 17.5x2 - 13.39, then f'(x) = 4x3 + 9x2 + 35x.

Problem #2

Implement the compute_deriv function. This function computes the derivative of a polynomial function. It takes in a tuple of numbers poly and returns the derivative, which is also a polynomial represented by a tuple.

def compute_deriv(poly):
"""
Computes and returns the derivative of a polynomial function. If the
derivative is 0, returns (0.0,).

Example:
>>> poly = (-13.39, 0.0, 17.5, 3.0, 1.0) # x^4 + 3x^3 + 17.5x^2 - 13.39
>>> print(compute_deriv(poly)) # 4x^3 + 9x^2 + 35^x
(0.0, 35.0, 9.0, 4.0)

poly: tuple of numbers, length > 0
returns: tuple of numbers
"""
# TO DO ...

Newton's Method

Newtons method (also known as the Newton-Raphson method) is a successive approximation method for finding the roots of a function. Recall that the roots of a function f(x) are the values of xsuch that f(x) = 0. You can read more about Newtons method here.

Here is how Newtons method works:

  1. We guess some x0.
  2. We check to see if its a root or close enough to a root by calculating f(x0). If f(x0) is within some small value epsilon of 0, we say thats good enough and call x0 a root.
  3. If f(x0) is not good enough, we need to come up with a better guess, x1. x1 is calculated by the equation: x1 = x0 - f(x0)/f'(x0).
  4. We check to see if x1 is close enough to a root. If it is not, we make a better guess x2 and check that. And so on and so on. For every xnthat is not close enough to a root, we replace it with xn+1 = xn - f(xn)/f'(xn) and check if thats close enough to a root. We repeat until we finally find a value close to a root.
For simplicity, we will only be using polynomial functions in this problem set.

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

5 daubert conditions

Answered: 1 week ago

Question

Technology. Refer to Case

Answered: 1 week ago