Reading and references:

For each of the following exercises create the specified files with
your answer(s). Submit your homework using the course **submit**
utility.

In this exercise you are to improve a program for computing the roots
of a quadratic equation **ax ^{2} + bx + c = 0** and in the
next exercise, use it to explore round-off errors. I have a
version in

- Insert a test to cover the special cases
**a = 0**and**a = b = 0**. (Here it would be nice, but not required, to have your code write the solution to a linear equation.) - Insert a test to quit if the roots are not real.
- Compute the roots using the standard formula
x = [-b +/- sqrt(b^2 - 4*a*c)]/(2*a)

*and*using the alternative formulaNote: You might want to make the code exit before it reaches the end of the program. For example, if the roots are complex, you might exit with an error message. To do that you use the Pythonx = 2*c/[-b -/+ sqrt(b^2 - 4*a*c)]

**sys.exit(1)**command. Also add**import sys**to the top of the code to give you access to this exit procedure. You should compare the second formula (by hand algebra) with the standard one and notice that the root with the plus sign before the square root in one formula gives the same root as with the minus sign in the other. (Nothing to hand in.) By choosing the better formula carefully for each root you can avoid any round-off errors. Write all four answers, so you can compare them. Have your program label the two more reliable roots "robust" and the two less reliable roots "risky". - In the second formula you might be dividing by zero. There are still two valid roots. So handle this special case as well.

(a) In the conventional formula, when b is positive, which sign in front of the square root leads to a possible loss of significant digits? When it is negative, which?

(b) A large loss of significance occurs when you subtract two numbers that are almost equal. In each case the two numbers are b and sqrt(b^2 - 4*a*c). What simple mathematical condition can you put on a, b, and c that would cause the magnitudes of these two numbers to be very close?

(c) Then run your program for the cases

a = 0.02, b = 2, c = 4 a = 2e-8, b = 3, c = 5 a = 2e-8, b = 8, c = 1e-7Put your results in a text file

NOTE: It is not sufficient to give only numerical results here. You must also give a clear EXPLANATION of those results. Your explanation should say why the risky formula gives such a bad result in the worst case above, and why it gives such a good result in the best case above. Say how you could predict which case would give the worst result.

Submit the file **roundoff.txt**.