Pré-visualização parcial do texto
Baixe Numerical Methods using MATLAB - Mathews and Fink e outras Notas de estudo em PDF para Engenharia Elétrica, somente na Docsity!
Numerical Methods Using MATLAB Contents Third Edition Tv mn 5 Preface vii 3 = o o 1 Preliminaries 1 1 John H. Mathews » California State Utuversiry, Fulteror 1] Reviewof Calculus 2 ER 12 Binary Numbers 45 [to] Kurtis D, Fink 3 Error Analysis pi Ra Nortimes: Missour Site University 2 The Solution of Nonlinear Eguations fw=0 40 Iteration for Solving x = g(x) 4! 22 Bracketing Methods for Locatinga Root 54 23 Anitia: Approximation and Convergence Criteria 62 . Newion-Raphson and Secant Methods 70 25 Aitken's Process and Steffensen's and Muller's Methods (Oprional 80 Hegskolen i Vestfoid 3 Eiblinteker - Borre The Solution of Linear Systems AX = B 182 31 Introduction to Vectors and Matrices 204 se E Prensice Hall, Upper Sadále River, NJ 07458 CONTEST iy CONTENTS y 32 Properties ot Vectors and Mavices 109 8 Numerical Optimization 399 3.5 Uppeciriangular Lincar Systems 420 81 Minimization of a Function 460 3A Gaussian Elimination and Pivoting 725 35 Triangular Factorizaton 147 36 lerative Methods for Linear Systems 156 9 Solution of Differential Equations 426 27 Iteraon for Nontinear Systeris: Seidel aná 91 Introduction to Diffesential Eguarions 427 Newton's Methods (Optional) 167 92 Euers Method 433 93 Heum's Method 443 . 94 Taylor Series Method 45! 1 i º 4 —Naterpolation and Polynominh 95 Ramekme Menem 50 pproximation 96 Predictor-Corector Methods 47 41 Taylor Series and Culcularion of Functions 187 92 Systems of Differentia! Eguations 487 42 Introduction to Inlerpolaton 459 9.8 Boundary Velue Problems 497 33 Lagrange Approximaion 206 99 Finite-dilTerence Method 505 aa Newton Polynomials 220 48 Chebyshev Polynomials (Optional! : : n . e - ebyshev Polynomials (Optional) — 230 10 Solution of Partial Differential Equations 514 46 Padé Approximations 243 10.1 Hyperhoiic Equations St6 10.2 ParabolicEguaons 526 5 Curve Fitting 252 103 Elipiic Equativos 59% 51 Leasrsquares Lire 253 53 Curve Fiting 263 1 Eigenvalues and Eigenvectors 555 53 Interpolation by Spline Functions 279 . “4 Fourier Series amu Trigonomençie Polynomizis 297 iLi Homogêneous Systems: The Eigenvalue Problem 556 U2 PowerMethod 568 113 JacobisMehod 587 6 Numerical Differentiation 318 11,4 Eigenvalues of Syrametric Matricet sá 61 Approximating The Derivarive 3/7 e , 6.2 Numerica: Differentiation Formulas 329 Appendix: An Introduction to MATLAB 60% Some Suggested References for Reports 616 7 Numerical Integration 342 71 Introduction to Quedrature 343 Bibliography and References 619 12 Composite Trapezcidal ano Simpson's Rule 354 . 73 Recursive Rules and Romberg Integration 368 Answers to Selected Exercises 631 74 Adaptive Quadrature 382 75 GaussLegendre Integration (Opiomal) 389 Index 655 ing resources. Experimentaúon with the MATLAB subrowine iibraries is encouraged. These.matenials can be used Lo assist students in the completion of the numencal anal- component of computer laboratory exercisos. This Third Edition grows oul of much polishing of the narralive for the Second Edition. For example, the (GR method has been added (o the chapter on Eigenvalues and Eigenvectors. New to this edition is the explicit use of the software MATLAB. An appendix gives an intodueuion to MATLAB syntax. Examples have been added chroughout the test with MATLAB and complete MATLAB programs are given in each section. An instruetor's disk is available upon request from the publisher. Previgusly we took the attitude that any soflware program thar students rastered would work fine. However, many students entening this course have yet to master à programming tanguage (computer scjence students excepted). MATLAB has become the lool of neariy al! engineers and applicd matematicians. and His newest versions have improved the programming aspects. So war ihink that studenis will have am casier and more productive time in this MATLAS version of our text. Acknowledgments We would hke to express my gratmade to all she people whose efiorts contributed to the various editions of this book. | Jobp Mathews) thank the students at California State Umversity. Fullerion. | thank my colleagues Stephen Cioede. Mathew Koshy, Edward Sabotka, Harris Schultz audSoo Tanz Tan for:heir supporr in the firstedibon; Preliminaries Censider the function f(x) = cos(xi. rs derivaúve f(x) = —sin(x). and its am- tderivative F(x) = sintx) + €. These formulas were studied in calculus. The former dtod inethe-sh = Em > slopem-=Ltagho! addutiorally. | thank Russel! Egbert, William Gearhart. Ronald Miller. and Greg Pierce for their suggesticos for he second edition. | also zhank james Friel, Chairman of the Mathematics Department at CSUF, fur his encouragement Resiewers who made useful recommendations for the first edition are Walter M. = + F io UR and the latter is used to compute lhe area under the curve fora < x < b The slope at the point (7/2, O)ism = f'tr/2) = — 1 and can be used to find lhe tangent line at this point (see Figure 1.1(a)): Patrersom TE Lander College; George Bo Miller Central Connecticut State Univer- sity; Peter ). Gingo. The University of Akron; Michael A. Freedman, The University of Alaska, Fairbanks, and Kencein P. Buhe, U rsity Of California, Los Angeles. For the second editiv. we thank Richard Bumby, Rutgers University: Robert L. Cu U.S. Army; Bruce Edwards, University vf Florida; anc David R. Mi, Temple Univer- sity Evr this third edition we wisi to thank Tim Saver, George Mason University; Ger- ald M. Pitstick, University of Oklahoma: Victor De Brunner. University o Oklahoma, George Trapp. West Virginia University: Tad Jarik, University of Alabama, Huntsville, Jeffrey 5. Scroggs, North Carolina State University, Kurt Georg. Colorado State Uni- versity: and James N. Craddock, Southem Hlinois University at Carbondale. Suggestions for improvements and additons to the book are always welcome and can be made by corespondire directly wnth the authors. Jahn ES. Marhews Kuntis D, Fink Maihemases Depariment Department of Muthematics California State University Northwest Missouri State University Fullerton, CA 92634 Maryvilie, MO 64468 cathewsOfullerton.edu kfinkQuail .nwmsssouri.edu tosa) derem v= cos) “o Figure 1.1 (a) The tangent fine to the curve + = cus(x) at the paím ta/2.0) 3 2 CHar | PRELIMINARIES *=coty Figure 1.1 (h) The area under the curve y — cosix) over lhe interval 10. x/2]. The arca under the curve for O < x < 7/2 15 computed Dsing an integral (sce Fig- ure J.J (by): x area — [O cossras 6) -HO=sio(>) -0= Sec. 1.1 REVIEW OF CALCULOS E] Definition 1.2, Assume thar f (x) is definsd on à set S of rcal nutabers and lerxg € S. Then f is said to be continuons ai X x xo it LED) Jim f6)= SG). a The function / is sai to be continuous on 5 if it is continuous at each point x e S. The notation €"($) stands for he set of all funcliors / such that f and às first n derivatives are continuous on S. When 5 is an interval. say [a. b). then lhe nocation Crja. b) is used. As an example, consider Me function f(x) = x*? on (pe inter- vas [1,17 Clearty f(x) nad f(x) = (4/3212 are continnous on [= 1, 1), while LS) = (4/94 5 is not continuons at x — 0. 4 Definition 1.3. Sopposc that (zn)££., is an infinite sequence, Then the sequence ix n=] said ta have the limit £.. and we write (4) lim x7 —£, msg if, given any e > 0, there exista a positive integer N = N(e) such that r > 4 implics thailx, — Lj < e a These are some ví lhe results that we will necd to use from calculus, When a sequence has a limit, we say that it is à corvergent sequence. Another commonly used notationis "x, > Lasn — 50” Equation (4) is equivalent to Review-of Calteulus €5) tim Ca 1)=0 It is assumeu that the reader is tamiliar with the notation and subject matter covered in Thus we can view lhe sequence fenJX, = (xy — LYX, às an error sequence, The le undergraduate calculus sequence, This should have included the topics of limits. continaity, differentiation, integration, sequences, and series. Throughout the book we refer to the following results. Limits and Continuity Definition 1.1. assume thal f(x) is defined on a set $ of rzal numbers, Then f is said to have the Emit L atx = x9, and we write €) lim fo) =4, 1>8p if. given any e > U, there exislsa 5 > O such thai, wheneverx e S,0 < ix xo) < à implies that f(x) — Lf < e. When the A-increment notation x — xp + k is used, equation (1) hecomes (2) lim (tro th)=L. N = following theorem relutes the concepts of conúinuiry and convergent sequence. Theorem 1.k. Assume that f(x) is defined on the set S and ag E 5. Lhe following statements are equivalent: (a) The function fis continuous at-xo- f6 [192] Tim, Xn — xo, lhen atm fm) = f(xo. Theorem 1.2 (Intermediate Value Theorem). Assume titar / € Cla, b]and £ is any number between (a) and f(b), Then there exists à number c, with c E (4,b). such that f(c) = L. Example 3.1. The functiva f(x) = cos(x — L)1s continuous over (0, 1), and the constant L — 0.8 € (cos(f)),cos(!)). The solution to f(x) = 0.8 aver [0, is ci = 0.356499, Similardy, ftx) iscomtinuousover (1, 2.5] and L = 0.8 € (cos(2.5), cos(t)). The solutian to f(1)=0.8 over [1,2.5Jisc3 — 1643507. These cwo cases ate showm in Bigure 1.2. a 6 CHap | PRELIMINARIES “e F6)) “a fan, a 05 10 Figure 1.4 The mean value theorem applied to fix) = sine) over the interval (0.1. 2.1] Theorem 1.7 (Generalized Ralle's Theorem). Assume that f e Cla, b] and that FCF [Mx exist pver (a, b) and xo, 2, ...,Xn E Ta. b]. If fop=0 tor j=0,1....,8, then here exists à numberc, with c € (a, b), suchthat FO)(c) = 0. SEC. 1.1 REVIEW OF CALCULUS 7 Figure 1.5 The mcan value theorem for integrals applied to f(x) = Sings) + Fsin(3x) over the imterval (0,25) — Example 1.5. The function f(x) = sin(x) + | sin(3x) satisfies the hypotheses of The- orem 1.10 over the interval [0.2.5]. An antiderivative of f(x) is F(x) = —cos(x) — À cos(3x). The average value of the function f(x) aver the interval (0, 2.5] is: Integrals Theorem 1.8 (First Fundamental Theorem). If f is continuous over [a, b] and F is any antiderivative of fon la, b), then 1. ft) de = PED EO 0762629 - (111110) FERA MET as T Z5 1.873740 = = 4046 There are three solutions to the equation f(e) = 0,749496 over the interval (0.2.5): ci = 0,440566,62 = 1268010, and c; — 1.873583, The area of the rectangle with a» ) flo)da= Fi) - Fla) where FG) = JD. Theorem 1.9 (Secend Fundamental Theorem). Jf f is continuous over [a, h] and xeta,b), ihen . dp o. 3 &l faro fe). Example 1.4. The funcion f(x) = cos(x) satishes ihe hypotheses of Theorem 1.9 over che interval (0, m/2]. thus by the chain rute 5 E) costs) dt = cos(x?)(x2y = 2x cos(r?). = a Theorem 1.10 (Mean Value Theorem for Integrais). Assume that f € Cla, 6). Then there exists a number c, with e c (4, b), such that [ bh ml Fixdx= fc). boat The value fc) is the average value of / over the interval [a, 6). daseb—a = 2.5 and height flcy) = 0,7494965 f(c; Kb — 0) = 1873740. The area of the rectanglo has the same numerical value as the integral of f(x) taken aver the inter- val [0, 2.5]. A comparison of the area under the curve y = f(x) and that of the rectangie can be seen in Figure 1.5. a Theorem 1.11 (Weighted Integral Mean Value Theorem). Assume that f.g < Cla, bJand gtx) 2 O for x € fa, bJ. Then there exists a number c, with c € (a, b). such that bd bh as ) Sgt) dr = [60 f swda. Example 1.6. The functions f(x) = sin(x) and g(x) = 42 satisfy the hypotheses o “Theorem 1.11 over the interval [0, 1/2]. Thus there exists a number c such that H/2 3 d; sino) = o E sinG)dx LHS o ggaça RP dz 1.29193 in” 1(0.883631) = 1.08356. = 8 CHAPI PRELIMINARIES Series Definition 1.5, Let [as EX, be a séguence. Then VIE, ay is an infinite series. The nt partial sum is Sn = 54.., 4% The infinite series converges if and only if the sequence [Sh |, converges t0 a limit S. tharis. n “15) aim, Sa = dm ba =s. Fa series does noi converge, we say that il diverges. a pos Example 1.7. Consider the infinite sequence (ar]2., = | = . Then he ah partial sum is nen AD) bt Fo LL say Elim) SBc. 1.1 REVIEW OF CALCDLUS 9 y Lo y= Po) 0.5 do x 1 2 3 4 5 ó —0,5 o s= St) Figure 16 The graph of f(2) = siníx) and the Taylor polymomial P(x) — x — 3/31 4 25/51 x! 89/81, the following derivatives at x = Q and auhstituting the numerical values into formula (17 kml kal e 5 Fot=sintry HO=0. Therefore, the sum of the infinite series is Fay = custo), FO=1, Fe) = —sintxy, fD=o, lim 84 = tim (1 no n=00 n Ce cost), SOU =, Theorem 1.12 (Taylor's Theorem). Assume that f « C"Há.b] and let xo € le. b]. Then, for every x € (a. b), there exists a number c = cix) (the value of c depends on the value of x) that lies between xo and x such fhat us FG) = Prtx) + Ra). where AIC) k um BA) 3 ta cão) t=0 " and tab, om Bata) = rate at . Example 1.8. The function f(x) = sin(x) satishies the hypolheses of Thesrem 1.12. 15 Taylor polynomial Px) of degree m = 9 expanded about ro = O is obtained by evalust!r 16) = costa), 19oj=1, x x Ed xº si tao A graphof both and Pg over the interval [O. 2:77] is shown in Figure [.6 ” Corollary LL. TF Pa(x) is the Taylor polynumial of degree a given in Tieorem 1.12, then ao Po — fio) fork>0 1.0... Evaluation of a Potynomial Letthe polynomial P (x) ot degree n have the form 0 PG) — ag” + app + oo apxê pr ajx dog. 12 CHAR | PRELIMINARIES Exercises for Review of Calculus ta Ed » 1. (um Find £ = limy sxotb! + 14/42n = 14. Then determine je, | — |L xnf and find Sima +90 éar (b) Find Z = Em oo(20226n- 1)/(402+2n+1), Then determine (e,) = |L—1n) and find lim, €u . Let fan)X, be a sequence such that limas o Zn = 2 (b) Find ima, -. o Int). Eine the numberts) « referred ta in the intermediate value Meorem for each function over lhe indicaled interval and for the given value of 1. (fi 24+2x+3over[-LOusingL = 2 (bj fivi= vx7> 5x Zover[6.8]using Find the upper and lower buunds referred to in lhe extreme value theorem for each funziion over the indicated interval, (a) fi)=si- 34 toverl-t.2] fix) = costgo — sintx) over [0,27] Find the numbers; c referred to in Rolic's thcorem for cach function over the indi- (a) Find linia so Sinta i- 1.2 BINARY NUMBERS E a) | j r q) [21º a 2 ” n= lo «s É so Lima do Lui 12. Find the Taylor polynamial of degree n =. 4 for cach funciiun expanded about 1» givea value of x. (0 fiy=4rmw=l O fo=tfrstu+iao= (e ftx)=cos(r), xo =0 13. Giventhat f(x) = sin(x) and P(x) = x — 22/34 12/5127 771429798. Show tl: PRO) = [O fork=1,2,....9. 14. Use synthetic division (Horner's method) to find P(c). (a) Pl)=atpxl-laxt-x—12,0=3 O Pojy=n!+atsro tor +23c=—1 15. Find the average area of all circles centereg at the origin wich radii between 1 and 3. i6. Assume that a polynomial, P(x). has » neai roots in the interval fa, b). Show tha pln-D(x) has at least one real root in the interval fa, 63. cated interval, ia) fit)=a!- ar over|-2,2] (b) fia) = sinta) + sint2x) over |O, 27] Find lhe numbers) e referred to in the mean value theorem for each function over the T7. Assume thai f, 7”, and f” are defined on the interval la. 6]; f(a) = (6) = Oianc Fte) >» Oforc € (a, b), Show that there is number d é (a, b) such that (a) < ) e Tadicarcd interval, td f(x) = 4% over [0,4] 2 x db) Ho = over |U, 1] . Azply the generalized Rolle's thaorem to f(x) = x(x — 1XXx — 2) oxer [0,3]. Apply the ársi fundamental theorem of calculus to each function over the indicated interval, ta) SO) = xe over (2 Ê do fuj= CÉoveri=l a) “+ . Applv the second fundamental theorem of calculus to each fmetion td É Broa pd fter a . Find the nuriberts) e referred to in the mean vale Encorem for integrais for each function, over the indicated interval. ia) flxy= 6x" over|-3.4 id) 169 reosta over [0,372] . Find the sum of euch sequence or series. Binary Numbers Human beings do arithmatic using the decimal (base 10) number system. Most com puters do arithmetic using the binary (base 2) auriber system. 1 may seem otherwise since commun:cation with the computer (inpuvoutpat) is in base 10 numbers. Thi transparency Goes not mean that the computer uses base 10. In fact, it converts input. 19 base 2 (or perhaps base 16), then performs base 2 arithmetic, and finally translate the answer into base 10 before it displays a result. Some experimentation is requires to verify his. One computer with nine decimal digits of accuracy gave the answer 100,000 D >» Ui = 9999 90447 a Here the imtent was to add the number 7 repeatediy :00, 000 times. The methemutica answer is exactly 10. 000. One goal is lo understand the reason for the computer's ap parently flawed calculation. At (he end vf this section, it will be shown bow somethin; is jost when ihe computer translates the decimal fraction 1j into à binary number. 14 CHAR E PRELIMINARIES Binary Numbers Base 10 mumbers are used for most mathematical purposes. For illustration, the number 1563 is expressible in expanded form as 1563 = (Lx 10%) 65 x 10) 408 x 10) +63 x 10). In general, let N denote a positive integer, then the digits ao, a. ..., ex exist so that A has the base 10 expansion N = (az 108) + (apoy x LD coçar x 10) e (ay x 109), where the digiis a; are chosen from [0,1,...,8,9] Thus N is expressed in decimal notation as o Nati arado, (decimal) Hit is uncerstood that 10 is the base, then (2) is written as Naa mara. For example, we understand that 1563 = 156hec. SFC. 1.7 BivaRy NUMBERS 15 Lis usually the case that the binary representation for Nº will require more digits than the decimal representation. This is due tu the fact that powers of 2 grow much more slowly than do powers of 10. An efficien algorithm for tinding the base 2 representation of the integer Nº can be derived from equation (4). Dividing both sides of (4) by 2 yields 4 EE Hence the remainder. upon dividing Nº by 2, is the digit ba. Now detemmice by. UU tó is writenas 4/2 = Oo + bu/2. hen Do Qo=bx27Brtbaaxa cd tha x 2) + by x 2 Now divide hoth sides uf (7) by 2 10 get 1 b a = (by x 208 hp a 2) oia x AD Hence the remainder, upon dividing Go by 2, is che digit by, Tais process is continued and generates sequences (94; ard [b;) of quotients and remainders, respectively. The process :s terminated when an integer J is found such that Q; = 0. The requences «hey the followirg formulas: nda jr. xi < =tbpx2 De thpryx2) Doo Using powers of 2. the number 1563 cam be written N=20,-b 1563 = (Lx 20) 4 (1x 28) + (05028) + (0x 27) + (0 x 26) Go =201 bi (3 0x5 +0x2)+0x2)+ (0x2) +01 x2]) (8 + ab, By2=207+kya This car he verified by performing the caleulation 1563 = 1024+512+16+8+2+1. .by existso that N In generel, let N denote a positive integer; the digits bo. bi. has the base 2 expansion e = (by 24 bra x 24 co (by x 21) 4 Lho x 2), wherc each digit &, is either a O or 1. Thus N is expressed in binary notadon as (5 N= bars ccbrbidomo — Qinar). Using the notatior: (5) and the result in (3) yields 1863 = 1100001107 o. Remarks. The word “two” will always be used as a subscript at the end of a binary number. This will enable the reader to distinguish binary numbers from lhe ordinary sase 10 usage. Thus 1 11 means one hundred eleven. whereas [1 liso stands for seven. Qr1=204+b, (Q4=0. Example [.10, Show how to obtain 1563 = 110000110] Stan with N = 1563 and consiruct lhe quotients and remainders according 10 the equadions in (87: 1563=2x 78] +E, 7l=2x390+1, 390=2x 195 +, 195=2x 9N+1, 972» 48+1, 48=2x 2440, 2A4=2x 120, 6+0, 3+0, 1h 0+1, There are many real numbers whose binary representation requires infinitety many digics. The fraction 7/10 can be expressed as 0.7 in base 10, yet its base 2 representa- tion requires infinitely many digits: 7 —— (18) To = 00 Oro The binary fraction in (18) is à repeating fraction where the gruup of four digits ONO às repeated forever. An efficient algorithin for finding base 2 representations van now be developed. lí both sides of (16) are muitiplied by 2, the resuit is “19 2R = dy + (do x 4a (dy are qo, The quantity in parentheses on the right side of (19) is à positive number and is less than 1. Therefore dy is the integer part of 2R, dennted dj = iri (28). To coninte the process, take ihe fractional part of (19) and write (207 Fisfecam= (urbe rx + where frac(2R) is the fractional part of the rea! number 28, Multiplication of boih sides of (20) by 2 results in an Ifi= do + Qdix 2 De tdo x MB o) Sec 1.2 Binary NUMBERS 19 Note ihat 273 = 1.6 = 2%. The paltems cy = ds ani Fi = Pisa will occur fork = 2. 34. Thus 7/10=0.10/0wo . Geometric series can be used o find the base IO rational number tha à binary number represents. Example 1.13. Find the base Hó rational number thar the binary number 0.01 wo 1epre- semss. In expanded form. 00h = (0x2!) 46h x 2) (0x 234 (1x 2% + ' + Sort i= Binary Shifting If a rattonal number that is equivalent to an infinite repeating binary expensior. is to be ot, then a shift in the digits can be helpful. For example. let $ be given by vm 5 = 0000007 1006... Now take the integer part of (21) and obtain dy = int(2F4). The process is continued, possibly ad infinitum cif & has an intinite nonrepeatine base 2 representation), and two sequences (dk] and 4F5) are recuisively gonerates: Muitiply ing both sides 0f (23) by 2º will shift the binary point five places to the right aid 3258 has the form (ar 328 = 0,11MXkso. dr inter, io &= Fi = fac(ZR), where dy = int(2R) and £, = frac(2R). The Binary decimal representation of R is then given by the convergent geometric series o R=5 dy. J=1 (22) Example 1.12. The hinary decimal representation of 7/10 given in ( 18) was found using the formulas in (22). Let R = 7/10 = 0.7, then 2R=t4 a=imig=] fi=fracl4)=04 2F,= 0.8 do = nO.) = 0 F; = fract0,8) = 0.8 2h=L6 d=imog=1 Fi = fraecle) — D.6 2h=12 d=in(l=1 fa = Tail = 02 Es = Trac(0.4)= 04 2h=04 di=im(D4)=0 2E:=08 de = int(0.8) = 0 Fa frac(0.8)= 08 2h= 16 d=im(6=l Similar) . muliplying both sides of (23) by 27 will shift the binary point ten places to the rishtand 10245 has the form (25) 10248 = HOMO MMA o The result of naively taking the differences benween the left- and righi-hard sides of (248 and (25) is 9925 = 1100040 01 9925 = 24, since 1100G4o = 24, Therefore. S— 8/35 Scientific Notation A siasnhonl way to present a real number, called scientific notation, is obtained by slyfeng tite decimal point and suppíying an appropriace power of 10. For example, 0,0000747 = 7.47 107º, 31,4159265 = 3.14159265 x 10. 9.700,000.000 = 9.7 x 10º. In cyemistry, an important constant is Avogadro”s number, which is 602252 x 102, 1 is the number of atoms in the gram atomic weight of an element. In computer science, FE LO x 0, HU CHap. 1 PRELIMINARES Table 1,3 Decimal Equivalents for a Set of Binary Numbers with 4-Bit Mantissa and Exponent ofn = —3,-2,...,3,4 Exponent: Mantissa | n=-3 | n=-2 [| n=0] | n=0 | =] 0.1000mo | 0.0625 0.125 0.25 os 1 2 4 g 0.100lwo | 00703125 | 0.140625 | 0.28125 | 0.5625 | 1.125 | 2.25 45 9 0.10!0wo | 0078125 | 0.15625 | 0,3125 0.625 | 1.25 | 25 5 10 0101lmo | 0,0859375 | 0.171875 | 0.34375 | 0.6875 | 1.375 | 275 as N D.1100kwo | 0.09375 0.1875 0.375 075 15 3 ó 12 0110 | 0.1015625 | 0.203125 | 0.40625 | 0.8]25 | 1,625 | 3.25 6.5 13 01110 | 0.109375 | 021875 | 04375 | 0873 | 1.75 | 35 q 14 01H) lwo | 0,1171875 | 0234375 | 0.46875 | 0.9375 | 1.875 | 3.75 75 15 Machine Numbers Computers use à normalized flvating-point binary representation for rea) numbers. This means that the mathematical quantity x is not actually stored in the computer. Instead, the computer stores a binary approximation to x: SEC. 1.2 BINARY NUMBERS 2 = 0ll0lox23 = 0010ug x 2? (29) À = 0110lwox27? 0,110iyw x 27? ER 0D0il vo x 22. H The computer must decide how to store the number 0.001 wo X 272, Assumo that n is rounded to 0.101OGua x 271, The next step is Tb = 01010xo x27] = 010104, x27! = 0.101lgo x272 = 0010 x 27! Es 0111 x 2-1. The compnter must decide how to store the number 0.111t yo x 271 Since rounding is assumed to take place, it stores 0.10000wa x 2º, Therefore, the computer's solution o the addition problem is (26 asdgx", The number q is the mantissa and it is a finite binary expression satisfying the inequal- ity 1/2 < 9 < 1. The integer n is called the exponent, 1 ter-enly a Usubsetof th: L ber systé K d. Typically this (30 E E 0.10000mo x 28. The error in the computer's calculation is (32) É — 010000 = [1466667 — 0,500000 2: 0.033333. Pp subset contains only a portion of the binary numbers suggested by (26). The number of hinary digits is restricted in both the numbers q and n. For example, consider the ser of all positive real numbers of the form 27 O didodidao X 2º, where di = | and do, ds, and dy arc cither O or 1, and n é (3,2, 1,0,1,2,3,4). There are eight choices for the mantissa and eight choices for the exponent in (27), and this produces a sez of 64 numbers: (8 UIOOO o X 2720.1005 x 272... 001Oyo x 25,01 Tiro x 2º]. The decimal forms of these 64 numbers are given in Table 1.3. Lt is important to leam that-when the mantissa and exponent in (27) are restricted the computer has a limited number of values it chooses from to store as an approximation to the real number x What would happen if à computer had only a 4-hit muntissa and was restricicd tn perfoem lhe computation (1) + É) + 4? Assume that (he computer rounds all real numbers to the closest binary number in Table 1.3. At cach step the reader can look at the table ro see that the best approximation is being used Expresscd as a percentage of 7/15, this amounts to 7,14%. Computer Aceuracy To store numbers accurately, computers must have floating-point binary numbers with at least 24 binary bits used for the mantissa; this translates to about seven decimal places. Tf a 32-bit mantissa is used, numbers with nine decimal places can he stored. Now, again. consider the difficulty encountered in (1) at the beginning of the section, when à computer added 1/10 repeatedly. Suppose that the mantissa q in (26) contains 32 binary bits. The condition 1/2 < implies that the first digit is dy — 1. Hence q has the form (33) 9 =0.Idody- -dasdaargo When fractions are represented in binary form, it is ofien the case thar infinitely many digits are required. An example is l (34 5 = 0000 o. 2 CHAP É PRELIMINARIE: SEG. 1.3 ERROR ANALYSIS. 13, Use Table 1.3 to determine what happens when à computer with a 4-bit mantissa perform the following calculations. ta (+ 6) (has)! o (B+a)+4 to (m+i)+5 14. Show that when 2 is replsced by 3 in all the formulas in (B) the result is à method for finding the base 3 expansian of a positive integer. Express the following integers in base 3, (a) 10 FO) (e 42 (0) I784 15. Show that when 2 is replaced by 3 in (22) the result is & method for finding the base 3 expansion of à positive number R that lies in the interval O < R < +. Express the following numbers in base 3. tm 1/3 0 172 to 100 tm 11/27 16. Show that when 2 is replaced by 5 in all the formulas ta (8) the result is à method for finding the base 5 expansion of a positive integer. Express the following integers in base 5. ta) 10 mw 35 to 7a 1) 734 17. Show that when 2 is replaced by S in (22) the result is a method for finding the base 5 expansion of a positive number R that lies in the interval O < R < 1. Express the Let y = 1,000,000 and 5 = 999,996; then the exvor is ab) Ey =p — $] = [1,000,000 — 999, 996] — and the relative error is b=9 4 R= 2 o = OQVONOA. "= 1,000,000 > É Letz = 0.000012 and 7 = 1.000008, then the error is Je — 3 = |0.000012 — 6.000009 = 0,000003, de) — 0.000003 >> = 0.25 d.000012 = 22 " Jn case (1a), there is not too much difference between F, and R,, and eitber could be uscd ro determine the accuracy of 7. In case (1h), the value of y is of magnitude 105, the error E, is large, and the relative error &, is stoall. In this case, $ would probably » idered a go0d approximation to 3-1 t is of itude 10 nd. following numbers ín base 5. fay 1/3 0 172 (eo 1/10 td) 154/625 In the practice of numerical analysis it is important to be aware that computed solutions are not exact machematical solutions. The precision of a numerical solution can be diminished in several subtle ways. Understanding these difficulties can often guide the Practitioner in the proper implementation and/or development of numerical algorithms. Definition 1,7. Suppose that P is an approximation to p. The absolute error is E, =|p- PJ, and the relafive erroris Rp = fp — fl/jpi providedthatp £ O. 4 The error is simply the difference berween the true value and the approximate value, whereas the relative error is a portion of the tcue value. Example 1.14. Find the error and relative crror in the following three cases. Let x = 3.141592 and € = 3,14; then the error is (la) Es =|x — F] = |3.141592 — 3.14! = D.001592, and the relative emor tr = - 0001592 BrT Stqusso 00050: Rr y g the error E, is the smallest of all threc cases, but the relative error R, is the largest. Tn terms of percentage, il amoupts to 25%, and thus T is a bud approximation to 2. Oserve that as || moves away from 1 (greater than or less than) the relative error R, às a better indicator of the accuracy of the approximation than E. Rel Definition 1.8. The number fis saíd to approximate p to d significant digits if d is the largest positive integer for which -a te Bi ot a o [dl 2 Example 1,15, Determine the number of significant digits for the approximatians in Example 1.14. (Sa) Tx = 3.141592 and E = 3.14. then |x — 2]/]x] = 0.000507 < 102/2, Therefore, Xapproximates x 10 two significant digits. (3h) FE y = 1,000,000 and 7 = 999,996, then 1y — 91/19] = 0.000004 < 10-5/2. Therefore, 7 approximates y to five significant digits. (3) Ifz = 0,000012 and 7 = 0,00009, then |z — £]/Jz] = 0.25 « 10-72. Therefore, 7 approximates z to no significant dígits. = 24 CHarl PRE x Truncation Error The motioa of truncation ermor nsmally refess to « Figure 1.7 The graphs of y = Haj= e”, y = Pa(x), and the ares under the curve for 0 < 1 54 s mtroduced when a more com plicated mathematical expression is “replaced” with a more elementars formula, This terminology originstes from the technique of replacing a com:plicated funetios with a truncated Taylor serie». For exampie, the iníinite Taylor seres Rounil-OfT Error A cumputer's representation of real numbers is limited to the tixcd precision of the mentissa. Tiue values ure sometimes not stored exactly by a computer's represen- tarem This is called round-aff errar. Iu the preceding section the real number 10 0.000) Luo was HUncated when 1 was stored in a computer. The actual num- per that ts stored in the computer may undergo chopping or rounding of he last diga, Therefore, since che compurer hardware works with only a limited number of digits in machine Lusubers, rounding esrors are introduced and propagated in successive com. patas Chepping off Versus Rounding Off Consader any real number p that is expressed in à mormalized decimal form: Mm p= =Odidids.. dade O" vieres <9md0 sd; <9forj > 1 Suppose that k is the maximum qumber ví decimal digits carned in the Aoating-point computations of 2 computer. then the real nunber p is represented by fE-nopi2). which is given by : 2 4 a — — =tetrs done when approximating an integral numericaily. Exemple 1.16. Given tha ()/2 28 dx = 0.544987104184 = p, determine the securacy of the approximation obtained by replacing the integrand f(0) = e with the trunemed Taylor series Pa(x) — 1x? 44645 E Term-by-term integration produces 2=112 12 é 1 9 2 4 E = + ) (1 C*gta Ton É nam xo Id T2 za 46 Sa6 110.592 2.109.451 = E = 0,544086720817 = 7. 370720 — 0:544986720817 = D Since 10-5/2 > [p= P]/ip| = 7.03442x 107º > 1078/2, the approximatiou P agrees wiih the mue answer p = 0.544987 04184 10 five significant digits. The graphs of f(x) — andy= Phtx) and the arça under lhe curve forO < 2 < 1/2 are shown in Figure 1.7 m FlenonkE) = atidads... da x 10". «dy <9andO = dy 9forl< j< dk The number fiaotp) is called in representation o! p. in is case the fit digicor logo) Fnaling-point represemtatiom [toma (Pl shichas given by o) Ttigund(D) — &adydado rr 07 uherei xd s9andO O anda positive integer 1 so that e—lth+ ata Om) and costij=1— ata om LF Ch) — pt] ai Determine the arder of approximation for their sum and product, (9) TR O such that aa — a <& fora suffciently large. a PO am SL 0=R,+Rp o Ryog = 884 ” pq 7º» “This Shows thai the relaise error in the prod 4 pg is approximately the sum uí the This às indicated by writing xp = x 4 Off), or xy — x with arder of convee- gence O(r,). a Example 1.23. Letx, = cos(n)/n? andor, = 1/03; tea limas 00 xr = O with n vaio of convergente 061 in?) This follows fimumediatety from the relaúon Leos(nypn? Hm =Icostn)]<1 for ab m , Propagation of Error Let us investigate how ertor might be propagared in successive computations. Con-der the addition of tro numbers p and q (the uve values) with the approximate valces 2 sod 7, which contain errors cp and 69, respectively. Staring wii p = 9 +€ and g=E+egthesumis 6; pég= (Pratt = PAD cet) Heve, for addition, the error in the sum ís the sum of the errors in the addends. relative errors in the approximations f and 7. Ofem an initial error will be propagated in a sequence of caleulations. A quality thatis desiraoh: tor any numecical process is that a small error in the initial conditions sli peaduce «n::1) changes in the final result. An algoritiyn with shis feature is called atadle; otherwise. it is called unsénble. Whenever possible we shall choose methocs that ate stable, “Lhe following definition is used to describe the propagation of error. Definition 1.13. Suppose that e represents an initial error and e(x) represents the groxH of he croraíter n steps. E le(m); = me, lhe growth of error is said 10 be linear. (Fleca)! e Ke the growth of error is called exponential. 1f K > [, the exponential ercor grow without bound as n —> oc andiflt < K < 1, he exponential error dirunishes to zonas a — 00, A “he next bro examples show how an initial esror can propagaie in either a stable o: an snstubie fashion. In the first example, three algorithms are introduced. Each algorithm cocursively generates the same sequence. Then, in the second example, small ehanges will be made to lhe initial conditions and the propagation of error will be ênaivzod,