正在加载图片...
184 Chapter 5. Evaluation of Functions and 2c T= (5.6.3) -b士V2-4ac If you use either(5.6.2)or(5.6.3)to get the two roots,you are asking for trouble: If either a or c(or both)are small,then one of the roots will involve the subtraction of b from a very nearly equal quantity (the discriminant);you will get that root very inaccurately.The correct way to compute the roots is 1 q三一2 b+sgn(b)v62 -4ac (5.6.4) Then the two roots are 乃÷9 8合 and 工2=一 (5.6.5) If the coefficients a,b,c,are complex rather than real,then the above formulas RECIPES still hold,except that in equation(5.6.4)the sign of the square root should be 、远 2 chosen so as to make Re(b*Vb2-4ac)≥0 (5.6.6) Press. where Re denotes the real part and asterisk denotes complex conjugation. 9 Programs Apropos of quadratic equations,this seems a convenient place to recall that IENTIFIC( the inverse hyperbolic functions sinh-and cosh-1 are in fact just logarithms of solutions to such equations, 6 sinh-(x)=In(x+Vz2+1) (5.6.7) cosh-(x)=+In(x+Vz2-1) (5.6.8) Equation(5.6.7)is numerically robust for z >0.For negative z,use the symmetry Numerical 10621 sinh(-)=-sinh().Equation (5.6.8)is of course valid only for 21. 43126 For the cubic equation z3+az2+bx+c=0 (5.6.9) with real or complex coefficients a,b,c,first compute Q .a2-36 andR= 2a3-9ab+27c (5.6.10) 9 54 If Q and R are real (always true when a,b,c are real)and R2<Q3,then the cubic equation has three real roots.Find them by computing 0 arccos(R/VQ3) (5.6.11)184 Chapter 5. Evaluation of Functions Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). and x = 2c −b ± √ b2 − 4ac (5.6.3) If you use either (5.6.2) or (5.6.3) to get the two roots, you are asking for trouble: If either a or c (or both) are small, then one of the roots will involve the subtraction of b from a very nearly equal quantity (the discriminant); you will get that root very inaccurately. The correct way to compute the roots is q ≡ −1 2  b + sgn(b) b2 − 4ac (5.6.4) Then the two roots are x1 = q a and x2 = c q (5.6.5) If the coefficients a, b, c, are complex rather than real, then the above formulas still hold, except that in equation (5.6.4) the sign of the square root should be chosen so as to make Re(b* b2 − 4ac) ≥ 0 (5.6.6) where Re denotes the real part and asterisk denotes complex conjugation. Apropos of quadratic equations, this seems a convenient place to recall that the inverse hyperbolic functions sinh−1 and cosh−1 are in fact just logarithms of solutions to such equations, sinh−1(x) = ln x + x2 + 1 (5.6.7) cosh−1 (x) = ± ln x + x2 − 1  (5.6.8) Equation (5.6.7) is numerically robust for x ≥ 0. For negative x, use the symmetry sinh−1(−x) = − sinh−1(x). Equation (5.6.8) is of course valid only for x ≥ 1. For the cubic equation x3 + ax2 + bx + c =0 (5.6.9) with real or complex coefficients a, b, c, first compute Q ≡ a2 − 3b 9 and R ≡ 2a3 − 9ab + 27c 54 (5.6.10) If Q and R are real (always true when a, b, c are real) and R2 < Q3, then the cubic equation has three real roots. Find them by computing θ = arccos(R/Q3) (5.6.11)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有