I am reading Mark Newman's Computational Physics and at chapter 4 page 133 in Exercise 4.2 he asks
a) Write a program that takes as input three numbers, a, b, and c, and prints out the two solutions to the quadratic equation $ax^2 + bx + c = 0$ using the standard formula $x = −b± (b^2 − 4ac)^{1/2}/2a$ . Use your program to compute the solutions of $0.001x^2 + 1000x + 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∓ (b^2 − 4ac)^{1/2} $, show that the solutions can also be written as $x = 2c/−b∓(b^2 − 4ac)^{1/2}$. Add further lines to your program to print these values in addition to the earlier ones and again use the program to
I tried both ways and a) gives me
[-9.99989425e-13 -1.00000000e+00]
and
b)
[-1.00000000e-06 -1.00001058e+06]
how can I understand which one is correct ? Or why is this happening ?