문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top