0

I am not sure if this is the right place to ask this question, if not I will delete it if you guys tell me, but my question is related to transferring math techniques into a program. My question is:

If I were to use a program to solve the quadratic equation ax^2+bx+c=0 by using:

x_1 = (-b-sign(b)*sqrt(b^2-4*a*c) ) / (2*a) 

x_2 = (c) / (a * x_1) 

What are the advantages of using a computer over the common formula? I know it will reduce the error involved, but other than that.

ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
Q.matin
  • 287
  • 1
  • 2
  • 7
  • 5
    Why would you use a program to solve the quadratic equation if there's already a closed-form solution? I'm not entirely sure what you're really asking. – Blender Jan 30 '13 at 08:16
  • 1
    And I don't really see any program here. Just a different formula for `x_2` than the usual one. – ypercubeᵀᴹ Jan 30 '13 at 08:19
  • @Blender My question was what are the advantages other than reducing error of using a computer over the common formula. For example, you cant always determine the correct significant digits of an quadratic equation therefore you will need a computer. I am wondering what other advantages are useful? Sorry for the confusion – Q.matin Jan 30 '13 at 08:21
  • Are you asking whether these formulas will produce smaller errors than the usual ones? – ypercubeᵀᴹ Jan 30 '13 at 08:22
  • 2
    @Q.matin: The closed-form is exact. There is no error until you convert the exact results into floating point numbers. – Blender Jan 30 '13 at 08:23
  • @Blender my computer language isn't crisp, but yes that is what I meant. When you convert it into floating numbers. – Q.matin Jan 30 '13 at 08:31

2 Answers2

2

I am assuming you are asking what are the differences between using the code

x1 = -b+sqrt(b*b-4*a*c)/(2*a);
x2 = -b-sqrt(b*b-4*a*c)/(2*a);

and the code

q = (-b-sign(b)*sqrt(b*b-4*a*c))/2;
x1 = q/a;
x2 = c/q;

The book Numerical recipes in C - The Art of Scientific Computing - Second Edition just says the second code will give you more accurate roots. You can consult online the book at http://apps.nrbook.com/c/index.html and you will find the formulae at page 183 and 184 in the section 5.6 Quadratic and cubic equations.

Professor Higham's book Accuracy and Stability of Numerical Algorithms, 2nd Edition has the introductory section 1.8. Solving a Quadratic Equation which elaborates further about the second code. Maybe you can read it through Google books with the query higham 1.8. solving a quadratic equation; it seems to me he just talk about the accuracy and robustness of the second code without describing any additional advantage.

For a longer explanation (in the Python Scilab context) you can look at Scilab is not naive by Michael Baudin available here: http://forge.scilab.org/index.php/p/docscilabisnotnaive/downloads/get/scilabisnotnaive_v2.2.pdf

Alessandro Jacopson
  • 18,047
  • 15
  • 98
  • 153
0

The computer program is the only way I know to get almost instantly the solution for millions of values of a, b and c.

Automating and speeding repetitive calculus tasks is one of the reasons why computers got popular recently.

mouviciel
  • 66,855
  • 13
  • 106
  • 140
  • Thanks! What are some of the errors that computers wont make besides signficant digits? – Q.matin Jan 30 '13 at 08:55
  • 2
    At the time when humans computed logarithm tables, errors were due to tiredness or distraction. Computers don't get tired or distracted. They just reproduce errors that humans introduced when typing the program. – mouviciel Jan 30 '13 at 09:01
  • 1
    Not only does the speed allow you to calculate many values fast, it also allows you to get an almost real-time solution for constantly changing inputs, which us very useful in many fields. – Jason Jan 30 '13 at 18:08
  • So, there is no direct advantages that the computer formula I gave above over the common formula? – Q.matin Jan 31 '13 at 05:44
  • What do you call _the common formula_ ? – mouviciel Jan 31 '13 at 07:49
  • @mouviciel the common formula is [-b +-\sqrt {b^2-4ac}]/2a – Q.matin Feb 01 '13 at 03:46