Quick viewing(Text Mode)

Lies My Calculator and Computer Told Me

Lies My Calculator and Computer Told Me

LIES MY CALCULATOR AND TOLD ME

■ www.stewartcalculus.com A wide variety of pocket-size calculating devices are currently marketed. Some can run For a discussion of graphing calculators programs prepared by the user; some have preprogrammed packages for frequently used and with graphing software, calculus procedures, including the display of graphs. All have certain limitations in com- click on Additional Topics: Graphing 100 Calculators and Computers. mon: a limited range of magnitude (usually less than 10 for calculators) and a bound on accuracy (typically eight to thirteen digits). A calculator usually comes with an owner’s manual. Read it! The manual will tell you about further limitations (for example, for angles when entering ) and perhaps how to overcome them. Program packages for (even the most fundamental ones, which realize arithmetical operations and elementary functions) often suffer from hidden flaws. You will be made aware of some of them in the following examples, and you are encouraged to experiment using the ideas presented here.

PRELIMINARY EXPERIMENTS WITH YOUR CALCULATOR OR COMPUTER

To have a first look at the limitations and quality of your calculator, make it compute 2 3. Of course, the answer is not a terminating so it can’t be represented exactly on your calculator. If the last displayed digit is 6 rather than 7, then your calculator approxi- 2 mates 3 by truncating instead of rounding, so be prepared for slightly greater loss of accu- racy in longer . Now multiply the result by 3; that is, calculate 2 3 3 . If the answer is 2, then sub- tract 2 from the result, thereby calculating 2 3 3 2 . Instead of obtaining 0 as the answer, you might obtain a small negative , which depends on the construction of the circuits. (The calculator keeps, in this case, a few “spare” digits that are remembered but not shown.) This is all right because, as previously mentioned, the finite number of dig- its makes it impossible to represent 2 3 exactly. A similar situation occurs when you calculate (s6)2 6 . If you do not obtain 0, the order of magnitude of the result will tell you how many digits the calculator uses internally. Next, try to compute 15 using the y x key. Many calculators will indicate an error because they are built to attempt e5ln1 . One way to overcome this is to use the fact that 1k cos k whenever k is an integer. Calculators are usually constructed to operate in the decimal number system. In con- trast, some packages of arithmetical programs operate in a number system with base other than 10 (typically 2 or 16). Here the list of unwelcome tricks your device can play on you is even larger, since not all terminating decimal are represented exactly. A recent implementation of the BASIC language shows (in double precision) examples of incorrect conversion from one number system into another, for example, 8 0.1 ? 0.79999 99999 99999 9 whereas 19 0.1 ? 1.90000 00000 00001 Yet another implementation, apparently free of the preceding anomalies, will not calculate standard functions in double precision. For example, the number 4 tan11 , whose representation with sixteen decimal digits should be 3.14159 26535 89793 , appears as 3.14159 29794 31152; this is off by more than 3 107 . What is worse, the cosine func- tion is programmed so badly that its “cos”0 1 223 . (Can you invent a situation when this could ruin your calculations?) These or similar defects exist in other programming languages too.

THE PERILS OF

You might have observed that subtraction of two numbers that are close to each other is a tricky . The difficulty is similar to this thought exercise: Imagine that you walk blindfolded 100 steps forward and then turn around and walk 99 steps. Are you sure that you end up exactly one step from where you started?

1 Thomson Brooks-Cole copyright 2007 Thomson Brooks-Cole copyright 2007 2 ■ LIES MYCALCULATOR ANDCOMPUTERTOLDME ogeog sn acltr o iledu ihazr,despitealltherulesinChapter1! youwillendupwithazero, long enoughusingacalculator, andtrytoguessthevalue of start withjustaboutany continuousfunction ev instance ofrestoringlostdigits. numerical analysis (It would take toomuchspacetoexplain whyallseven digitsarereliable;thesubject the .Even withthreesparedigitsexposed, (work outthedetails!)andnow thelossofsignificantdigitsdoesn’t occur: thetwo ten-digitnumbersagree in . As youcansee, particular example wecanuserationalizationtowrite theformerlysmallerrorsinsquarerootsbecomemorevisible.Inthis things worse, becomezerosbeforethefirstnonzerodigit. To make aftersubtraction, nine digitsthat, difference comesoutas and soweget The approximationsfrommycalculatorare hc sacnegn -eis().Supposeweweretotrysumthisseries, wewould stop when mal place.Inotherwords, byaddingtermsuntilthey arelessthan5intheninthdeci- correct toeightdecimalplaces, -series( which isaconvergent let’s consider theseries 10). As anexample torefutethesemisconceptions, cise Theorem) but notingeneral;amodifiedversion istrueforanotherclassofseries(Exer- . Another powerful statement istrueforcertainalternatingseries(seethe Alternating SeriesEstimation Thelatter and“theerrorislessthanthefirstneglected term.” “practically nothingtoadd” common misconceptionisthataseriescanbesummed by addingtermsuntilthereis althoughthecal- the aforementionede , isalways suchasl’Hospital’s Rule(which helpssolve Mean Value Theorem anditsconsequences, and Section 1.4. Yet another methodforavoiding computationaldifficulties isprovided bythe tool istheuseofinequalities;agoodexample istheSqueeze Theorem asdemonstratedin culated value maybedifferent. Try itwith traction issymbolicmanipulation.For instance, One ofthesecretssuccesscalculusinovercoming thedifficulties connectedwithsub- THAN CALCULATORS ANDCOMPUTERS WHERE CALCULUSISMOREPOWERFUL tan nulyarei l iista h acltri aal fcryn.Smlry ifyou entually agreeinalldigitsthatthecalculatoriscapableofcarrying.Similarly, Now youcanseewhyinExercises 1.3(Exercise 22)yourguessatthelimitof let’s calculate To illustrate, The nameofthisphenomenonis“losssignificantdigits.” The limitationsofcalculatorsandcomputersarefurtherillustrated byinfiniteseries. A x x x 8721 3 8721 8721 w sbudt owog eoe ocoet thatthevalues will becomessocloseto as boundtogowrong: s 3 s s deals withtheseandsimilarsituations.)SeeExercise 7foranother 8721 x 3 3 p e rcise andothers) 15105.21509 0.00003306 1 10,681 s 10,681 3 f p 10,681 s x s n 8721 2 2 1.001 1 1.001 h lim s

0.00003 s l 0.00003310115 n 3 tan

0 2 a

and 0.00000 0005 1 f

n x T x 1 1.001 10,681 f 1 a 8721 10 ylor’ a 7 h h 10,681 s s s Formula. b 3 2 b f 1 x s 10,681 a 2 s to seven digits 2 15105.21506 s 10 2 x 5 b Thomson Brooks-Cole copyright 2007 2. 1. A htteTyo eiswt etr isused toapproximate lus method. ln that the Taylor serieswithcenter traction takes placeinsidethe machine;explain how (assuming cant digitsdestroys yourresult. This timethedetrimentalsub- and determinewhentostopguessing beforethelossofsignifi- Guess thevalue of priate calculusmethod. your calculator.) Then findthepreciseanswerusinganappro- cant digitsdestroys yourresult.(Theanswerwilldependon and determinewhentostopguessingbeforethelossofsignifi- Guess thevalue of Click hereforanswers. x ). Then findthepreciseanswerusingan appropriate calcu- EXERCISES x lim

l h lim

0

l

0 sin

ln 1 2 x 1 h a h x 1 S 2 1 Click hereforsolutions. and necessityfor“thinkingbeforedoing.” but thereisstillconsiderablescope human capacityforhandlingnumbersandsymbols, regardless ofitssizeandspeed. A calculatororcomputerdoesstretchthe or computer, mathematical problemsthatcan’t besolved byacalculator andalways willbe, There are, eithernumericalorsymbolic. just replacementsforsomekindsofmathematicallabor, as youcanseefromExercise 6. whatdoes? A suitableinequalitysatisfiedbytheremainderofseries, the partialsums, convergence ofthisandotherseries.) Fo known astheEuler-Maclaurin obtained byusingamorepreciseformoftheIntegral Test, wewould stillobtainasum microseconds), of lessthan207comparedwiththetruesummore1000.(Thisestimateis termsoftheabove series (only intheory;amillionyearsislessthan elementary particlesinoursolarsystem.)Ifweweretoadd em,i re oapoiaeteifiiesmmr lsl.(hsnme ,calleda , googol inordertoapproximatetheinfinitesummoreclosely. (Thisnumber terms, themachineresultrepresentslessthan2%ofcorrectanswer! Thus, .(Thiswould require ahigh-speedcomputerand we have from theproofofIntegral Test, But, mating partialsum wewould endupwiththeapproxi- increased precision.) After goingtoallthistrouble, when that is, ml,andonlythenusingacalculator. The formulaprovides away toacceleratethe rmula, Computers andcalculatorsarenotreplacementsformathematicalthought. They are If thetwo precedingapproachesdidn’t give therightinformationaboutaccuracy of ups htw hnwne oadahg ubro em fti eis say, Suppose thatwethenwanted toaddahugenumberoftermsthisseries, , is outsidetherangeofpocket calculatorsandismuchlarger thanthenumberof n N 196,217,284 5. 4. 3. n ree wtht ope rtmtc hn .) when or even switchtocomplex , puter packageswould signalanunnecessaryerrorcondition, need tousetrigonometricidentities.(Recallthatsomecom- greater accuracy. ev you willlikely obtain0orjust afew digitsofaccuracy. How- on yourcalculator. These numbersaresoclosetogether that Try What isanumericallyreliableexpression toreplace [ . ? of as is greaterthan the beyond thecalculatorrange.Show thatthemaximumvalue of Even innocent-lookingcalculusproblemscanleadtonumbers s 1

S 1 r wecanusetheMean Value Theorem toachieve much er, n N f 1.001 1 to evaluate x cos n N 1 x x

10 ,e y l n 1 D 1.001 pcal hn isasmallnumber? You will specially when 1 26

10 x dx 1.001 124 ln LIES MYCALCULATOR ANDCOMPUTERTOLDME f 19.5 Hint: x 10 1000 9 s oaihs]Whatisthelimit Use .] x 1.0001 10 1 x 100 2 ln x 10 x 9 10 0 100 10 ■ 100 3 4 ■ LIES MY CALCULATOR AND COMPUTER TOLD ME

(a) Let f x ln ln x,a 109 , and b 109 1. Then the (a) Show that all these troubles are avoided by the formula Mean Value Theorem gives 9q x f b f a f cb a f c a2 3 3p 9p2a 2 3 27 q s729q2 108p3 where a c b . Since f is decreasing, we have where a f a f c f b. Use this to estimate the value of D . 2 (b) Use the Mean Value Theorem a second time to discover Hint: Use the factorization formula why the quantities f a and f b in part (a) are so close to A3 B3 each other. A B A2 AB B2 1.001 6. For the series n1 n , studied in the text, exactly how many terms do we need (in theory) to make the error less than 5 in (b) Evaluate the ninth decimal place? You can use the inequalities from the 4 u proof of the Test: (2 s5)23 1 (2 s5)23 y f x dx f n y f x dx If the result is simple, relate it to part (a), that is, restore the N 1 nN1 N cubic equation whose root is u written in this form. 7. Archimedes found an approximation to 2 by considering the 10. (a) Consider the power series perimeter p of a regular 96-gon inscribed in a circle of radius 1. n His formula, in modern notation, is x f x n n1 100 1 p 96s2 s2 s2 s2 s3 It is easy to show that its radius of convergence is r 100 . (a) Carry out the calculations and compare with the value of p The series will converge rather slowly at x 99 : find out 7 from more accurate sources, say p 192 sin96 . How how many terms will make the error less than 5 10 . many digits did you lose? (b) We can speed up the convergence of the series in (b) Perform rationalization to avoid subtraction of approximate part (a). Show that numbers and count the exact digits again. x x f x f 8. This exercise is related to Exercise 2. Suppose that your com- 100 x 100 puting device has an excellent program for the exponential and find the number of the terms of this transformed series function expx ex but a poor program for ln x . Use the that leads to an error less than 5 107 . identity n n [Hint: Compare with the series n1 x 100 , whose sum b you know.] a e ln a b ln 1 b e 11. The positive numbers

and Taylor’s Formula to improve the accuracy of ln x. 1 1x n an y e x dx 0 9. The cubic equation can, in theory, be calculated from a reduction formula obtained 3 x px q 0 by integration by parts:a0 e 1 ,an nan1 1 . Prove, using 1 e1x e and the Squeeze Theorem, that where we assume for simplicity that p 0 , has a classical limn l an 0. Then try to calculate a20 from the reduction for- solution formula for the real root, called Cardano’s formula: mula using your calculator. What went wrong? 13 The initial term a e 1 can’t be represented exactly in a 1 27q s729q2 108p3 0 x calculator. Let’s call c the approximation of e 1 that we can 3 2 enter. Verify from the reduction formula (by observing the pat- 27q s729q2 108p3 1 3 tern after a few steps) that 2 1 1 1 a c n! For a user of a pocket-size calculator, as well as for an inexpe- n 1! 2! n! rienced programmer, the solution presents several stumbling blocks. First, the second radicand is negative and the fractional and recall from our study of Taylor and Maclaurin series that power key or routine may not handle it. Next, even if we fix the 1 1 1 negative radical problem, when q is small in magnitude and p 1! 2! n is of moderate size, the small number x is the difference of two numbers close to sp3 . converges to e 1 as nl . The expression in square brackets Thomson Brooks-Cole copyright 2007 Thomson Brooks-Cole copyright 2007 12. b We usedthereversed reductionformulatocalculatequanti- (b) AconsolationafterthecatastrophicoutcomeofExercise 11: (a) whichgetsmulti- anonzeronumber, sequence to , theinitialinaccuracy would causethecomputed errors, )wereperformedwithout diverge. further calculations(afterentering . We concludethateven ifall plied byafast-growing factor converges to dai vnmr oefl develop itfortheintegrals idea iseven morepowerful, ties forwhichwehave elementaryformulas. To seethatthe again usingthisreverse approach. . Try obtain improvements oftheapproximations we canusetheinequalityusedinsqueezeargument to If werewrite thereductionformulatoread a n c e a y 1 n 0 1

1 x n

e n 1 1 ! n x

dx a a 0 n a n a 20 13. ep etr h cuayo frsal. forsmall . iscloseto helps restoretheaccuracy of Show thattheuseofaccuratelyevaluated function where , gives inaccurateresultsforsmall youmayappreciatethatthedefinition numbers, After somany warnings aboutthesubtractionofclose An advanced calculatorhasakey forapeculiarfunction: n tofive digitsofaccuracy. For , and , and quickly. Findtheintegrals fortheparticularchoice but thenumberscanbecalculated in “finiteterms”), theintegrals arenolongerelementary(notsolvable such isaconstant, where

n

0, 1, E ..., 5 x LIES MYCALCULATOR ANDCOMPUTERTOLDME sinh 1 e 0 x x x

sinh 2 1 1

e x x x 1 if if e x x x n sinh 0 0 x 0 x 1, ....

E x ■ 3 1 x 5 6 ■ LIES MY CALCULATOR AND COMPUTER TOLD ME

ANSWERS

S Click here for solutions.

1 11 1.3 3.0 5. (a) 4.82549424 10 9. (b) 1, x 3 3x 4 0 LIES MY CALCULATOR AND COMPUTER TOLD ME ■ 7

SOLUTIONS

1. The computer results are from Maple, with Digits:=16. The last column shows the values of the sixth-degree

2 2 Taylor polynomial for f(x)=csc x x− near x =0. Note that the second arrangement of Taylor’s polynomial is − easier to use with a calculator:

1 1 2 2 4 1 6 1 2 2 2 1 2 1 T6(x)= 3 + 15 x + 289 x + 675 x = 675 x + 289 x + 15 x + 3   

x f(x)calculator f(x)computer f(x)Taylor 0.1 0.33400107 0.3340010596845 0.33400106 0.01 0.333341 0.33334000010 0.33334000 0.001 0.3334 0.333333400 0.33333340 0.0001 0.34 0.3333334 0.33333333 0.00001 2.0 0.33334 0.33333333 0.000001 100 or 200 0.334 0.33333333 0.0000001 10,000 or 20,000 0.4 0.33333333 0.00000001 1,000,000 0 0.33333333

We see that the calculator results start to deteriorate seriously at x =0.0001,andforsmallerx, they are entirely

2 1 meaningless. The different results “100 or 200” etc. depended on whether we calculated [(sin x) ]− or

1 2 [(sin x)− ] . With Maple, the result is off by more than 10% when x =0.0000001 (compare with the calculator

1 result!) A detailed analysis reveals that the values of the function are always greater than 3 , but the computer

1 eventually gives results less than 3 .

The polynomial T6(x) wasobtainedbypatientsimplification of the expression for f(x), starting with

2 4 10 2 1 (2x) (2x) (2x) sin (x)= (1 cos 2x),wherecos 2x =1 + + R12(x). Consequently, the exact 2 − − 2! 4! − ···− 10!

1 value of the limit is T6(0) = 3 . It can also be obtained by several applications of l’Hospital’s Rule to the expression

x2 sin2x f(x)= − with intermediate simplifications. x2 sin2x

x25 3. From f(x)= (We may assume x>0; Why?), we have ln f(x)=25lnx x ln(1.0001) and (1.0001)x −

f 0(x) 25 = ln(1.0001). This , as well as the derivative f 0(x) itself, is positive for f(x) x − 25 0 x0. Hence the maximum value of f(x) is ln(1.0001) ≈

25 x0 f(x0)= , a number too large to be calculated directly. Using decimal logarithms, (1.0001)x0

124 log10 f(x0) 124.08987757,sothatf(x0) 1.229922 10 . The actual value of the limit is lim f(x)=0; x ≈ ≈ × →∞ it would be wasteful and inelegant to use l’Hospital’s Rule twenty-five times since we can transform f(x) into

x 25 f(x)= , and the inside expression needs just one application of l’Hospital’s Rule to give 0. (1.0001)x/25   Thomson Brooks-Cole copyright 2007 8 ■ LIES MY CALCULATOR AND COMPUTER TOLD ME

9 9 1 ln x +1 5. For f(x)=lnlnx with x [a, b], a =10 ,andb =10 +1,weneedf 0(x)= , f 00(x)= . ∈ x ln x −x2(ln x)2

11 11 (a) f 0(b)

(b) Let’s estimate f 0(b) f 0(a)=(b a)f 00(c1)=f 00(c1).Sincef 00 increases (its absolute value decreases), we − − 20 have f 0(b) f 0(a) f 00(a) 5.0583 10− . | − | ≤ | | ≈ ×

π 7. (a) The 11-digit calculator value of 192 sin 96 is 6.2820639018, while the value (on the same device) of p before 8 rationalization is 6.282063885,whichis1.68 10− less than the trigonometric result. × 96 (b) p =

2+√3 2+ 2+√3 2+ 2+ 2+√3 2+ 2+ 2+ 2+√3 · · u · v u s t s t s t s but of course we can avoid repetitious calculations by storing intermediate results in a memory:

96 p1 = 2+√3, p2 = √2+p1, p3 = √2+p2, p4 = √2+p3,andsop = p1p2p3p4 s 10 According to this formula, a calculator gives p 6.2820639016, which is within 2 10− of the trigonometric ≈ × result. With Digits:=16;,Maplegivesp 6.282063901781030 before rationalization (off the trig result by ≈ 14 15 about 1.1 10− )andp 6.282063901781018 after rationalization (error of about 1.7 10− ), a gain of × ≈ × about one digit of accuracy for rationalizing. If we sets Digits:=100;, the difference between Maple’s

π 99 of 192 sin and the radical is only about 4 10− . 96 ×

1/3 1/3 9. (a) Let A = 1 27q + 729q2 +108p3 and B = 1 27q 729q2 + 108p3 . 2 2 − k  s l k  s l Then A3 + B3 =27q and AB = 1 [729q2 (729q2 + 108p3)]1/3 = 3p. Substitute into the formula 4 − − A3 + B3 3p A + B = where we replace B by − : A2 AB + B2 A −

1 27q/3 x = 3 (A + B)= 2/3 2/3 1 2 3 2 1 2 3 − 2 27q + 729q +108p +3p +9p 2 27q + 729q +108p k  s l k  s l which almost yields the given formula; since replacing q by q results in replacing x by x, a simple discussion − − of the cases q>0 and q<0 allows us to replace q by q in the denominator, so that it involves only positive | | numbers. The problems mentioned in the introduction to this exercise have disappeared.

1 (b) A direct attack works best here. To save space, let α =2+√5, so we can rationalize, using α− =2+√5

1 and α α− =4(check it!): − 1/3 1/3 1/3 1/3 4 α α− 4(α α− ) 1/3 1/3 u = − = − = α α− α2/3 +1+α 2/3 · α1/3 α 1/3 α α 1 − − − − − − 3 1/3 1/3 1 and we cube the expression for u: u = α 3α +3α− α− =4 3u, − − − u3 +3u 4=(u 1)(u2 + u +4)=0, so that the only real root is u =1. A check using the formula − − from part (a): p =3, q = 4,so729q2 +108p3 =14,580 = 542 5,and − × 36 x = 2/3 2/3 ,whichsimplifies to the given form. 54 + 27 √5 +9+81 54 + 27 √5 −     Thomson Brooks-Cole copyright 2007 LIES MY CALCULATOR AND COMPUTER TOLD ME ■ 9

1 x n 1 x n n 11. Proof that lim an =0:From1 e − e it follows that x e − x x e, and integration gives n →∞ ≤ ≤ ≤ ≤ 1 1 1 1 n 1 x n n e 1 e = x dx e − x dx x edx= ,thatis, an , and since n +1 ≤ ≤ n +1 n +1 ≤ ≤ n +1 ]0 ]0 ]0 1 e lim =lim =0, it follows from the Squeeze Theorem that lim an =0. Of course, the expression n n +1 n n +1 n →∞ →∞ →∞ 1/(n +1)on the left side could have been replaced by 0 and the proof would still be correct.

1 2 1 Calculations: Using the formula an = e 1 + + + n! with an 11-digit calculator: − − 1! 2! ··· n!   

n an n an n an 0 1.7182818284 7 0.1404151360 14 5.07636992 − 1 0.7182818284 8 0.1233210880 15 77.1455488 − 2 0.4365636568 9 0.1098897920 16 1235.3287808 − 3 0.3096909704 10 0.0988979200 17 21001.589274 − 4 0.2387638816 11 0.0878771200 18 378029.60693 − 5 0.1938194080 12 0.0545254400 19 7182563.5317 6 0.1629164480 13 0.2911692800 20 −143651271.63 − −

It is clear that the values calculated from the direct reduction formula will diverge to . If we instead calculate an −∞ 14 using the reduction formula in Maple (with Digits:=16), we get some odd results: a20 = 1000, a28 =10 , − 17 a29 =0, and a30 =10 , for examples. But for larger n, the results are at least small and positive (for example,

a1000 0.001.) For n>32,175,wegetthedelightfulobject too large error message. If, instead of using the ≈ reduction formula, we integrate directly with Maple, the results are much better.

x x x 13. We can start by expressing e and e− in terms of E(x)=(e 1)/x (x =0), where E(0) = 1 to make − 6 x x E continuous at 0 (by l’Hospital’s Rule). Namely, e =1+xE(x), e− =1 xE( x) and − − 1+xE(x) [1 xE( x)] sinh x = − − − = 1 x[E(x)+E( x)], where the involves only positive numbers 2 2 − E(x) and E( x), thus presenting no loss of accuracy due to subtraction. − Another form, which calls the function E only once:

(ex)2 1 [1 + xE(x)]2 1 x 1+ 1 x E( x ) E( x ) We write sinh x = − = − = 2 | | | | | | , taking advantage of the fact 2ex 2[1 + xE(x)] 1+ x E( x )  | | | | sinh x that is an even function, so replacing x by x does not change its value. x | | Thomson Brooks-Cole copyright 2007