Search for question

1. Use goalSeek function to find the roots of the polynomials P₁, P₂, and P, listed in the introduction. The expected

answers are: 3, 1.5, and -4.2. Choose the limits to contain the roots you are looking for (-5 and 5 would suffice for

these three polynomials). Confirm that your program is finding correct roots.

2. Read the file poly.txt.Discard any line that starts with a symbol (thus skipping the header).

You can use operator != to check that two values are not equal. For example, the condition line[0] != '#'

is True if the first character in line is not a #

For each non-header line, split it and use float function to extract A, B, C, D, Lo, and Hi. Print them out to

confirm that your program correctly extracts these parameters.

3. Write a function makePoly that can generate a Python function representation of a cubic polynomial from its

coefficients A, B, C, D. For example, the polynomial function P1 we used earlier:

def P1(x):

return x*x*xxx 4x - 30

could be created with the generator function as follows:

P1 = makePoly(1,-1, 4, -30)

4. For each polynomial you read from the file, use makePoly to generate its Python function representation. Run

goalSeek on this function with given Lo and Hi limits to find the root. You can use WolframAlpha

(https://www.wolframalpha.com/) to check that the roots are correct.

After that, for each polynomial, print out its coefficients A, B, C, D followed by the root your found. Format the

output nicely making sure the columns line up (we also added -> to clearly separate the root from the

coefficients):

3.00 -1.80 -7.60 -20.80

2.00

5.00 14.00 24.00

2.70

7.59 9.49 3.85

0.00 -8.00 -32.00

1.00

1.80 -9.94 -29.38 -20.28

1.00 13.40 24.80 22.80

-17.86

31.35

2.10 -18.64

1.00 19.20 46.45

3.00 -23.60 -1.20 -57.40

3.00 -54.70 -87.50 -238.80

2.50 -16.30 -31.24 -26.24

0.70 12.78 10.74

3.00 -15.90 -16.90

0.90 6.46 17.64

0.90 -0.18

2.00 -5.00

5.22

-12.60

48.60

-25.18 -51.46

7.00 -30.00

2.40 -13.12 -10.76 -74.80

2.00 18.20 23.20 56.70

2.80

41.86 71.38 88.44

2.00

0.80

6.20

-2.46

11.00

4.80

-61.36

2.96

1.00

10.00 32.00 77.00

1.00 -4.00 -3.00 -10.00

2.00

3.80

7.60

-0.80

2.00 5.60 6.90

3.90

2.60

-2.00

-0.70

4.00

7.80

-11.40

9.40

-16.50

8.20

19.90

8.20

-17.40

6.30

-5.40

6.20

3.00

6.80

-8.10

-13.20

-0.60

5.20

-7.00

5.00

0.10

-1.30

Fig: 1