24 C H A P T E R 1.Mathematcal Prellminaries Thus,the absolute crror in this approximation,x10,is the original absoluteerro multiplied by the factor 10. EXAMPLE 4 Let p =0.54617 and g =0.54601.The exact value of r p-g isr =0.00016.Suppose the subtraction is performed using four-digit arithmetic.Roundi four digits =0.5462andg 0.5460,respectively,and r=p r-digit approximation tor.Since -=0.00016-0.0002 =0.25 r 0.00016 If chopping is used to obtain the four digits,the four-digit approximations to p,q,and r are p*0.5461,g*=0.5460,and r*=p*-*=0.0001.This gives -产=10.00016-0.0001 =0.375, 10.000161 which also results in only one significant digit of accuracy. The loss of accuracy due to roundoff error can often be avoided by a reformulation of the problem,as illustrated in the next example. EXAMPLE 5 The quadratic formula states that the roots of ax2+bx+c=0.when a0,are (1.1) 2a 2a Using four-digit rounding arithmetic,consider this formula applied to the equation+ 62.10x +1 =0,whose roots are approximately x1=-0.01610723and2=-62.08390. In this equation,b2 is much larger than 4ac,so the numerator in the calculation for involves the subtraction of nearly equal numbers.Since √b2-4ac=√(62.10)2-(4.000)(1.000)1.000)=√3856.-4.000=3852 =62.06. we have f1)=-62.10+62.06 =-0.02000. 2.000 -0.0400 2.000 a poor approximation tox=-0.01611,with the large relative error 1-0.01611+0.0200≈24×10- 」“0.01611川 On the other hand,the calculation forinvolves the addition of the nearly equal numbers -b and-vb2-4ac.This presents no problem since 0-0a-写器=-0 2.000
1.2 Roundoff Erors and Computer Arithmetic 25 has the small relative error 1-62.08+62.10≈3.2×10-4 1-62.08 To obtain a more accurate four-digit rounding approximation for we change the form of the quadratic formula by rarionalizing the numertor -b-√-4ac b2-(b2-4ac) 2a -b-√m-4ac 2a(-b-vb2-4ac) which simplifies to an alternate quadratic formula -2c 1=b+√-4ae (1.2) Using (1.2)gives -2.000 -2.000 f)=62.10+62.06=242 =-0.01610, which has the small relative error 6.2x 10-4. iontechnique can also be sppfied to give the fol atemative -2c =6-√m-4ae (1.3) This is the form to use if b is a negative number.In Example 5,however,the mistaken use of this formula for x2 would result in not only the subtraction of nearly equal numbers,but also the division by the small r result of this subtraction.The inaccuracy that this combination produces, -2 -2.000 -2.000 f1)=6√=4ac=62.10-62.06-0.04000 =-50.00. has the large relative error- racy loss du andoff error can also be reduced by rearranging calculations as shown in the next example. EXAMPLE 6 Evaluate f(x)=x3-6.1x2+3.2x+1.5 at x =4.71 using three-digit arithmetic. Table 1.4 gives the intermediate results in the calculations.Carefully verify these re- sults to be sure that your notion of finite-digit arithmetic is correct.Note that the three-digit chopping values simply retain the leading three digits,with no rounding involved,and dif. fer significantly from the three-digit rounding values. Table 1.4 6.1x2 3.2x Exact 71 22.1841 4871I1 135.32301 15.072 t (chop Three-digit(rounding) 4 22 34 15.0 13 15.1
26 C HA PT E R 1.Mathematical Preliminartes Exact:f(4.71)=104.487111-135.32301+15.072+1.5 =-14.263899: Three-digit(chopping):f(4.7)=(104.-l34.)+15.0)+1.5=-13.5; Three-.digit(rounding:f(4.71)=(105.-135.)+15.1)+1.5=-13.4. The relative errors for the three-digit methods are -14.263899+13.5 -14.263899 ≈0.05,for chopping and -14.263899+13.4≈0.06,for rounding. -14.263899 As an alternative approach,f(x)can be written in a nested manner as fx)=x3-6.1x2+3.2x+1.5=(x-6.1)x+3.2)x+【.5. This gives Three-digit(chopping): f(4.71)=(4.71-6.1)4.71+3.2)4.71+1.5=-14.2 and a three-digit rounding answer of-14.3.The new relative errors are Three-digit(chopping): -14.263899+14.2 -14.263899 ≈0.0045 Three-digit(rounding): -14.263899+14.3 1≈0.0025 -14.263899 Nesting has reduced the relativeo for the chopping to of that obtained i initally.For the round on the nent bas been even Polynomials should always be expressed in nested form before performing an evalu minimizes the number of arithmetic calculations.The decreased eduction in computations from four multiplications and three additions to two multipli ations and three additio s.One way to reduce roundoff error is to reduce the number of error-producing computations EXERCISE SET 1.2 1.Compute the absojute error and relative error in approximations of p byp a.p=元,p*=22/7 b.p=π,p=3.1416 cp=c,p=2.718 d. p=√p=1.414
1.2 Roundoff Errors and Computer Arithmetic 27 e.p=e0,p*=22000 Ep=t0,p°-1400 8p=81.p*=39900 h p=91.p*=18(9/e 2. Find the largest interval in which pmust lie to for each value of p. a. b.e c.v2 d 3 e n mus with relative error at most 10-Find the largest interyal in 150 b.900 c.1500 d.90 4.Perform the following computations(i)exactly.(ii)using three-digit chopping arithmetic.and (iii)using three-digit rounding arithmetic.(iv)Compute the relative errors in parts ()and (i. +月 b. c. (()+品 d.(3+i 1-20 5.Use three-digit rounding arithmetic to perform the following calculations.Compute the abso lute error and relative error with the exact value determined to at least five digits. a.133+0.921 b.133-0.499 c(121-0.32)-119 d.(121-119)-0.327 是- 3 2e-5.4 重-10m+6e 62 g()() h. π一萼 6.Repeat Exercise 5 using four-digit rounding arithmetic. 7. Repeat Exercise 5 using three-digit chopping arithmetic. 8 Repeat Exercise5 using four-digit chopping arithmetic 9。 The first three nonzero terms of the Maclaurin series for the arctangent function are (1/3)+(1/5)x5.Compute the absolute error and relative error in the following approxi mations of using the polynomiat in place of the arctangent kl6aman(G-4aran(2码) 10.The number e can be defined by e=2(1/n!),wbere n!n(n-1).2 1 for n0 and 0!=1.Compute the absolute error and relative error in the fotlowing approximations ofe: b. 11.Let f(x)=xcosx-sin.x x-sinx a.Find lim,o f(x). b. Use four-digit rounding arithmetic to evaluate f(0.1). c PccchrgooccnctoawthctidMacaponomil,endrepep d Tbe actual value is f(0.1)=-1.99899998.Find the relative error for the values obtained in parts (b)and (c)
28 12.er f()=e-e- Find limz-ofer-e)/x. b. Use three-digit rounding arithmetic to evaluate f(0.1). c. Replace each exponential function with its third Maclaurin polynomial,and repeat part (b) d. The actual value is f(0.1)=2.3335000.Find the relative error for the values obtained in parts (a)and (b). 13. ,Use four mulas of Exampk 5 to find and relative Howing quadratic equations. 5x2 12 4x+6=0 b. +2 -6=0 c1.002x2-11.01x+0.01265=0 d.1.002x2+11.01x+0.01265=0 14. Repeat Exercise 13 using four-digit chopping arithmetic. Cse the 64-bit longrea foat tofind the decima equivalen of the foilowing floating-point machine numbers a.0100000010101001001100000000000000000C00000000000000000000000000 b.1100000010101001001100000000000000000000000000000000000000000000 001111111111010100110000000000000000000000000000000000000000000 d. 001111111111010100110000000000000000000000000000000D000000000001 16.Find the next largest and smallest machine numbers in decimal form for the numbers given in Exercise 15. rcept of the line: x=二为 y1一0 a.Show that both formulas are algebraically correct. b.Use the data (xo,yo)=(1.31.3.24)and (x1. arithmetic to co 18. Taylor polyn al of de gree n for f( )=eis∑ the Taylor polync degree nine an ee-digit chopping anthmetic to h on to e by eacho he following metho ae5≈了-5y =2-15 1 0 c.An approximate value ofe-correct to three digits is 6.74x 10-.Which formula.(a)or (b),gives the most accuracy,and why? 19.The two-by-two linear system ax +by =e, cx+dy=f. where a.b,c.d,e.f are given,can be solved for x and y as follows: