Chapter 4: Problem 2
Consider a quadratic equation \(a x^{2}+b x+c=0\) that has real solutions. a) Write a program that takes as input the three numbers, \(a, b\), and \(c\), and prints out the two solutions using the standard formula $$ x=\frac{-b \pm \sqrt{b^{2}-4 a c}}{2 a} . $$ Use your program to compute the solutions of \(0.001 x^{2}+1000 x+0.001=0\). b) There is another way to write the solutions to a quadratic equation. Multiplying top and bottom of the solution above by \(-b \mp \sqrt{b^{2}-4 a c}\), show that the solutions can also be written as $$ x=\frac{2 c}{-b \mp \sqrt{b^{2}-4 a c}} . $$ Add further lines to your program to print these values in addition to the earlier ones and again use the program to solve \(0.001 x^{2}+1000 x+0.001=0\). What do you see? How do you explain it? c) Using what you have learned, write a new program that calculates both roots of a quadratic equation accurately in all cases. This is a good example of how computers don't always work the way you expect them to. If you simply apply the standard formula for the quadratic equation, the computer will sometimes get the wrong answer. In practice the method you have worked out here is the correct way to solve a quadratic equation on a computer, even though it's more complicated than the standard formula. If you were writing a program that involved solving many quadratic equations this method might be a good candidate for a userdefined function: you could put the details of the solution method inside a function to save yourself the trouble of going through it step by step every time you have a new equation to solve.
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.