Search for question
Question

duf Pl(x):

def P2(x):

return x*x*x-x*x + 4x - 30

def P3(x):

#A

3

2

return x*x*x+ 0.5*x*x+x-6

2.7

1

return 3*x*x*x + 13.6*x*x 13.2 x 37.8

?

For this test, you are provided with the file poly.txt containing coefficients of 25 polynomials. The first few lines of

the file look as follows:

Roots of polynomials can be found using function goalSeek if you supply the tested

polynomial function as the function parameter, set the target parameter equal to zero, and

start with a good LowLimit and HighLimit interval enclosing the root.

B

-1.8

5

7.59

Note that goalSeek requires that the tested function f is such that f(LowLimit) s target

≤ f(HighLimit). All polynomials provided for this task will satisfy this requirement.

C

-7.6

14

9.49

-8

-20.8

24

3.85

-32

Lo

-4.28

-6.57

-1.86

Hi

11.88

0.73

5.85

10.58

Formula

3 x^3 1.8 x^2 - 7.6 x - 20.8

2 x^3 + 5 x^2 + 14 x + 24

2.7 x^3 + 7.59 x^2 + 9.49 x + 3.85

x^3 - 8 x - 32

The first line is a header, you will have to skip it when reading the file. Each of the following lines starts with the four

coefficients A, B, C, D, uniquely determining a polynomial

Ax³ + Bx² + Cx+D.

The coefficients are followed by the suggested. Lo and Hi limits. Each provided polynomial is guaranteed to have

exactly one root in the interval Lo sxs Hi. We will use goal Seek to find this root for each of the provided

polynomials.

The last column is a conventional representation of a polynomial, which you can be pasted in WolframAlpha

(https://www.wolframalpha.com) to confirm that your program correctly finds the roots. For example, here is the response

(https://www.wolframalpha.com/input/?i-3+x96E3+-1.8+xN5E2-76-x-+20.8) for the first polynomial in the file, in particular it

says that the real root is equal to 2.6.

Task

In this task, we are going to write a program test7.py that finds the roots of cubic polynomials listed in the file

poly.txt using goalSeek function.

Fig: 1