Numerical Methods Using MATLAB
Numerical Methods Using MATLAB
|p~AV/pl = 70344210"! > 109/2tbe approximation Faytees wit the me answer p = 0'544987104184 to five significant digi. The graphs of f(x) ~ o* andy = Far) and the area under the curve for O = 4 5 4/2are shown in igure 7 Ste 14 ERROR Anatvsis a Round-Off Error ‘computer's representation of real numbers is lime to the lined precision of the sa, Thue values are vometimes not stored exactly by: a computer’ repreeen taton THs is called round-off error. In the yreveding section the real curaber 1. O.008TTiwo was truncated when 1! was Stored in @ compute. The actual num hort is stared in the compar may undereo chopping or rounding af the last digt Therefore. singe the computer hardware works with oaly a limited numberof digits im rachie cunbers, ounwhing errors are murodueed and propagated in successive com Chopping off Versus Rounding Of CGonsser any real number p that is expressed ina normalized decimat form: 4 = 20didady cde -p... X10" there | gy ¢ Gand < dy < Oforj > 1. Supyce that fis the maxim aomier .dcimal digits carried in he loatng- point computations of a computer: den the rel fuer pS FePFESEMIeD DY ftp Pe WHEN Ys gIVEA Dy B0didods.. dy ¥ 10° 1 Flex? where |< dz ¢ Yand 0 < dj = Ofor 1 < j x k. The number Flguep) is calied Inechoppedflazing-point representation ot inthis case the kth gt Of ejg( P) srs with the dah digit of p. An altemative k-digit eprescnation is the rounded Boating point represemation Fla P shich given by 4 Slaea(P) ~ £0drdady 14 10? here Fs = Gm Od, ¢ Ofor 1L.itfollows that x? +1 < 20 forx > 1. Therefore, f(x) = O(@(2)).30 Cary eeLaarvaRis The big Oh notation provides a useful way of describing the rate of growth of a function in terms of well known elementary functions (x".!", a, Jog, £, st). The rate of convergence of tequences can be described in a similar manner, Definition 1.10. Let 4352, and (yal, be two sequences. The sequence (rq) is said to be of order big On of {yx}. dented xq ~ O(yq) if there exist constants C ane such dia & Val € Clyel whenever m 2 1 a Example 1.21. =f whenever 2 1 : tien 2 fonction F(A) is approximated by a Function p(k) and the error bound is known to be 41)". This leads tothe following defimion Definition 1.11. Assume that f(A) is approximated by the funetion p(k) and that {here exis a teal venstant Bf > O anna punitive integer n 9 ha % 17! rst sl ‘We say that p(h} approximates /(h) with order of approximation O(k") and write 10) Sth) = pth) + O(n"). ‘When relation (9) is rewritten in the form | (A) ~ p(h)i < MIN" we see that the notation O(5") sands in place ofthe error bound Hi"). The following results show lan to apply the defiitinn to simple combinations of two Functions ‘Theorem 1.15. Assume that fh) = poh) + OU"). gh) = yh) + OH), and info. ni}. Then ay Fin) + ah) = ph) | ath) + O18"), a J hygth) = pihyath) + OF") and Over a a AR hoary It ic instructive o consider p(x) t0 be the mth Taylor polynvnsial approximation ‘of f(r: then the remainder term is simply designated O(H"*"), which stands for the presence ot omitied terms staring with the power "The remainder term converses to 7ero with the same rapidity that WT"! converges to vera ac h approaches zen © expressed inthe relationship Provided that g(h) #0 and g(h) #0. ty we MBM wy LOMO pat aay Oth) se MBE we LOO yt “wn wer iy Sr. 1.3 BRROR AwaLysis a for suficiently small A, Heace the notation 0 (h"~!) stands im place ofthe quantity Ai’ *1 where M is. conetamt or “hehaves ike a constant” Theorem 1-16 (Taylor's Theorem). Assume that f € C** "fa, ). IF both x9 and say fhe la, bl. then os FO) A el as soon = nh 5 om, & The following example illustrates the above theorems. Te computations use the addition properties (i) OH?) + OA?) = O(AP), (b) BUH") + OU) = OtH'), ‘shore # — min{p.q}, and the mobiplicative property (ii) OUKP)O (he) = Ara) wheres = p tg Example 1.22. Consider the Taylor polynomial expansions Poe ca sare eM out amt conet Bik out Deere te ode of pronation fr dcr susan pr Forte sum we have A secon owes CA eae 2h EO 4 F400, Since Oth") 4 Sy = O(h*) and O¢H4) + Oth®) = OU), this reduces to As conthy 2m COU, and the order of approximation is Oh"). Penna (1+ae8 4 pom! ~(11-8-¥)( ’ a(n + On} OG5) eee 7 Hata + 04h) + Oh) + OHV O1H"). +ha2 CHART PReLiannantes Since OOOH) = Oth) and she & eae eae - Ty FO + 04 +04 7 the preceding equation i simples fo yield H ey ones Pronth) = 1h Ka aunty 5 +a and the order of approximations OCH) . Order of Convergence of a Sequence ‘Numerical approximations are oflen arrived at by computing a sequence of appro nations thar get closer and closer to the desires answer. The definition of big Ob fox sequences was given ia Definition 1-10, and the defiition of order of convergence for a sequence ie analogs that given foe fetions ix Definition 133, enminon 5.12 Suppose IMA ye 5p aE Pay 8 a seqUERKE vt Nima fa = 0. We say that {201% converses to x will the order of conve: gence (ra) there exits aconstat R > 0 such that SK form saffciently large This is indicated by writing xy = x + Ol'y), oF xy > x with onder of conve sence Ora) * Example 123, Let x, = cos(n)/n? and ry = 1/n?; te ity-oo Fg = O with at rate of comvergence (1/42), This follows immediately fom the elation Leostey| <1 for all m . Propagation of Error [Lecus investigate how ervor might be propagated in successive computations. Cun ser the addition of to numbers p and q (the tre vais) with the approximate veluca F nd 9. which contain eros ¢p and, respectively. Stating with p= ji-+ © and a= a +e, the sums 61 p+a P+ D+ ep +) P+ elt Gre) ‘eae, for addition, the ero in the sum isthe sum of the errors in the addends SECTS ERROR ANALYSIS. 3 ‘The propagation af error in multiplication is more complicated. The produc: is an 14 B+ NB 6) = BO Bey b Fn + Ceo ene. Band fare larger than I in absolute value, erin Peg and Jey show una ere isa possiblity of magnification ofthe original error €» and cy. Insights are gained if \we look a the relative error. Rearrange the terms in (17) 10 get oo) 24 — BG = Bea + dep ~ toby Swppote il py £ Oa y # 0; then we van vide (18) by py 0 obain dhe eave eon the prove py Pa Bey tote ia ha (9) Ry Pa pa” Pa Farhermet, sippoce that and ave god appesimanions for p and 9: thew Fip%1,8/@ ~ |, and RyRy = (€p/p)(¢q/q) ~ 0 (Ry and Rg are the relative exors iin app numadions Bani qj. Then maxing these suosinsions io (9) yes Simpler elaticnship @o Rog = Ry + Ry OG “This chours that the relive eror in the prodoct a is approximately the sum « relative errors inthe approximations B and 9. ‘Often an inal error will be propagated in a sequence of calcvlations. A quality ‘huts desiranle for any numerical process is that a small errr in the initial conditions. wil prodce sh changes in the final result. An algorithm with this feature is called stable, alrerwise its called unstable. Wheaevet possible we shall cose meibods that are stable. ‘he following definition is used to describe the propagation oferor. Letiniion 1.13, Suppose that « represents an miual error ana ¢(n) represents the ‘rowth of he enw aterm steps. I lef © ne. the growth of errr is sai t be linear. If c/ayt © Ke, the growth of error i called exponential. IF K > 1, the exponent cron grows without bound 4s + os, and if 0 < K <1, the exponential erroe Alcsnishes to 7210 86 9 a he nect two examples showy how an inital errr can propagive i either a stele ‘or an unstable fashion. In the first example, the algorithms are introduced. Each _lgoritim recarsvely generates the sare sequence. Then. inthe second example, small ‘anges will be made to the initial conditions and the propagation of error will he onalyaed,34 CHARI PRELIMNARIES ‘Table 14 The Sequence {5} = (1/3" andthe Approximations [rs (pe an (gal SHC. LSBRROK ANALYSIS s Tohle 1.5 The Bror Sequences (x4 ~ ras (te ~ Palsand ta — a 0 ‘oano000000 | e.9999600000 | 10000000000 | .0900000000 ete “010000800000 “0000000000 ‘e.0000000000 : bors oom Comporsss 1 siasssss | osm | osama | qss:sm0 ea Saporsss3 90001333 fl O11) | 0.1111066667 01110933330 01110666667 ‘4 (0.0000014815 ‘0,0000192593 0,0001348 148 | : omens o.o83t fotos. 3) foams | anss6 | om | omvoam : Gomeme commer cowmioes ooinesse | consis | ooiansnse | oonsurr ‘ Secon Saat 26 Sonsous) 4) romain | | : cor oe oe 3] sbeomsuns | vam | enn | amen tf Copomnest oo 3990 fonzenioe2 1p econ sre | oootsirees | commas 3 | enw Sonate 6{ qycomnnracr | conser { oonnsinas | coax oo esis 7] gdyceemsnas | eomusrner | nesnerses | nonce —|__seomoneg 2| cer=oomsoass | coooszas | covotsames | -ooxssosss 9| elar=oonsenss | oocmsoeos: | commasss | ~oosecuies 10| seb =o.000018351 | oommiess4s | -oommnsis | -o29s2280688 Example 1.24. Show that the following thee schemes can be used with infnte-precision aithmedc fo recursively generate the trms inthe sequence (1/3*}2q aww foc = 1,2, 21) po= ber 0 le go= 191 and n= F 4? form = 2,3, ec ana AI". Thincanbe vented des ean ’) jporei(ne4) {G65° = (4-2)a-(f-}ecabsnen ans (will generate the desired sequence. In 21e) the difference pet 3 Sewing A = 1 and B Sling A = 1 and B = 0 genortes the requited sequence . ample 25. Generate approximations to the sequence (r=) = (1/3") using the 229 0.99986 aul ry = rant formate for n= 2, 3, H) post, pi = 0.33332, and py for n= 2,3, 0.33332, and an 2) tn (22) the initial error in rq is 0.00004, and in (226) and (22c) the initial errors in py, sn gy are 0.000013. Investigate the propagation oferor for each scheme, Table 1. gives the rt ten numerical appronimason: for cach sequence, and Table LS escathe emor in each formula, The ero for (r) is stable and decreases in an exponenial ‘rane. Lne errr Yor {pa} 18 stable. Ine ero Tot (gy 8 unstable and grows a a expo- nomial rte, Although the error for [pq is sible, the terms fy > 0.85 > 20, 50 that the aor eventually dominates and te terms past pg have no sigmificant dis. Figures 18, 19, and 1.10 chow the erors in irq] [pals ad (gy Feepetivly. : Lanoowors} 2.000010 0000s . ie ge 2 + ‘ 5 10 Figure 1.8 A stable decreasing enor sequence (xg ~ rl ‘Uncertainty in Data Daa from real-world problems contin uncerainty or eros. This typeof eror is forred\o 2 noice, It wil affect the accuracy of any mumerial computation tha is bed on the data, Aa improvement of precision isnot accomplished by performing succes ‘Sve computations using noisy data. Hence, if you start with data with significant digit of aecuracy then the rest ofa compaton should be eared in d significant sigs of accuracy. For example, suppose that the dta py = 4.152 and p2 = 0.07931 bot have tour sigsneanc agus of accuracy, hen wis tempting to report al the digas that appear on your ealulator Vie. oy + py = 4.23131), This is en oversight because Ane 03 . 02 on . 3 7 6 3 0 Figure 1.10 An unstable increasing eror sequence (4 — dl SECIS ERROR ANALYSIS x you should not report conclusions from noisy data that have more significant digits ‘han the orginal data. The proper answer in tis situation 18 p+ p2 = 4.231, Exercises for Error Analysis 1 Find the error F and relative errr Ry. Also determine the numberof significant ‘igs nce approximaton, G@) v2 7198189, 7 27-718 ©) y= 98,350,5 wo: Complete he ftlowing computation [Pe sen [ (e548) ame ‘State what type of eerie present in thie siuaticn. Compare your answer with the teu value p = 0,2553074606. 3. (a) Consider the data p) = 1.414 and p> = (209125, which have four significant Aigits of accuracy. Determine the proper anewer forthe sum py + pa and the product py (b) Consider the data py = 31.415 and pp = 0.027182, which have dive significant ign of scenracy. Determine the proper answer forthe sum pi + pa and the product pip 4. Complete the following computation and state what type of error is preset in tis fay 8 (E-+0.00001) —in(§) _ 070711388222 — o707LO67811 aD “como 20.0005) — Inc) _ .69s172IMMDS —a¢ast4ETINNG ‘O.0008 ‘0.90005 5. Somedmes the ls of significance er can beavoided by rearranging termi the function using a known identity from tigonomety or algebra. Find an equivalent formula forthe following function that avoids a loss of significance. Ge) ba(e 1 1) InGs) for large « @) JP FT~ 2 forlargex (© costa) ~ sina) for © 2/4 Freeman, Oe 6. Polynomial Evauation, Let P(x) = x—33+3x~1, OC) and Roxy = (2 = 1)" (2) Use fourdigitrounding arithmetic and compute P(2.72), Q(2.72), and R272) Inthe computation of P(x), assume that (2.72)? = 20.12 and (2.72)? = 7.368 (343-13B CHAR. PRELIMINARIES () Use foursisit rounding arithmetic and compute P(O.975), (0.975). and (0.975). In the computation of P(x), assusse that (0.975)> = 0.9268 and (0975)? = 0.9706. 1. Use thee-igit rounding arithmetic 1 compere the following gums (sum in the given ©) Lint 8 Dinas de pean of ev forthe flowing (a) The sum of tie numbers: B+ enh+G+eq)t Fre tat (8) The quodent of two numbers: (©) The product of dee mambers: PU EP HepGree rer 9. Given the Taylor polynomial expansions Lthe +i? +0064) aie +00, Deter te order of approximation fr thelr sur and produc. 10. Given the Taylor polynomisl expansions conth) = and singh Determine the order af appronimatin fo her um and pe 11, Given the Taylor polynomial expansions Boe cot 1 Fy Ee oy snd » sin(hy =h— 0) =a Determine the order of approximation fr ther sur and princ. SBC.1.3 ERROR ANALYSIS » 12, Improving the Quadratic Formal. Assumethata 4 and 6?--dec > Oandconsider the equation ax?-+bx-+¢ = O. The roots can be computed with the quadratic formalas © =b+ Va Tae wpb Vee 2a Ce gaara ‘Show that mpese roos can he calculated wit che equivalent formulas ne x C n= amd o ers ers ‘Hint, Raiomalize the numerator in), Remark in the cases when |b] VOF—Aac, ‘one must proceed with caution 1 avoid loss of procision due to catastrophic can- cellaton. If 6 > 0, then 1 should be computed with formula (i) and x2 should be computed using (). However if < 0, then xy should be computed asg () aid 42 should be computed using (i. 13, Use the appropriate formula forx1 and x2 mentioned in Exercise 12 to find the roots ofthe following quadrats equations (a) x2 1.000001 +1 =0 (b) x? ~ 10,000.00" +1 = (©) 29 ~ 100,000.000015 + 1 (a) x? ~ 1,000,000,0000015 + 1 = Algorithms and Programs 1. Use the results of Exercises 12 and 13 to construct an algorithm and MATLAB pro- gram that will accurately compute the rots of 2 quadatie equation in all stations, ineluding the woublesome ones when bl = v6? = fae 2, Follow Example 1.25 and generate the frst ten numerical approximations for each ofthe following tree difference equations. In euch ease a small itil ear ie in ‘woduced. If there were no inital eer, then eich of the difference equations would _enerate the sequence (1/2"]z. Produce ourpuranalogous1o lables I and 1.9 anc Figures 1.8, 1.9, and 1.10. @ © po © phe Pract, form =1,2, = 0497, a6 Pa = Ppt ~ Parte form = 2.3, ent anos form = 24,The Solution of Nonlinear Equations f(x) =0 Consider the physical problem that involves a spherical ball of radius r that is sub- tnesged to adept din water (see Figure 2.1), Assume thatthe bal is constructed from « varizy of longleaf pine that has a density of p = 0,638 and tht its radius measures r= 10cm, How much ofthe ball wil be submerged when itis placed in water? ‘The mass My of water displaced when a sphere is submerged to « depth is y= {m2 nde OD ‘and the mass of the balls My = 4xr3p/3. Applying Archimedes’ law My = Mo. prodiucns the following equation that must he solved: x! =r +47, ~ a a Tg 24 mp 1 1 ‘sphere of radius r that is t0 be sub- ot ee Qt StC.2.1 ITERATION FOR SOLVING = (2) = 304g? {In our ase (with r = 10 and p = 0.638) this equation becomes a2 0. 3 ‘The staph of the cubic polynomial y = 2552 — 30d? +d is shown in Figure 2: from it one can se thatthe solution lies near the value d = 12 ‘The gual ofthis chapter is o develop a variety of rains for fining aur approximations for the roots of an equation, For example, the bisection method « be applied to obtain the tree Toots dy = ~8.17607212, dy = 11,86150151 4; = 26.31487061. The frst root di ia nota feasible solution for thie problem, be: d cannot be negative. The third root di is larger than the diameter of the sphere ¢ isnot the desired solution. The root d) = 11.8615015I lies inthe interval [0, 20 4s the proper solution. Its magnitude is reaconable because alinle mare than on ofthe sphere must be submerged. Iteration for Solving x = g(x) ‘A fundamental principle in computer science is iteranon. As the name sugge process is repeated unl an answer 1s achieved. erative techniques are used t 1.0 Finear and nonlinear systems of equations sed eo ‘of differential equations. In ths section we study the process of iteration sing rey substation, ‘A rule or function g(x) for computing successive terms is needed, together starting value po, Then a sequence of values (ps} is obtained using the iterativ42 CHAR2 THF SOLUTION OF NONLINEAR EQUATIONS (3) = eet = giped. The sequence asthe peters po (starting value PL = (0) p= stp) ao ‘Wat can we Jeara from a unending sequence of numbers? W une numbers ter to lint, we feel thar something has been achieved. But what ifthe numbers diveree or ae periodic? The next example addresses this situation, Example 2.1. The iterative rule po = 1 and pigs = 1001 pi fork = 0,1... produces divergent Sequence, ihe Mt 109 Lermns ok es follows: ‘P1 = 1.001 pp, = (1.001)(1.000000) = 1.001000, P= 1.001 p) = (1.001)(1,001000) — 1.002001 _P3 = 1.001 p2 = (1.001)(1.002001) = 1.003003. pica = 1.001 pp = (1.001), 1.104012) = 1.108216. “The process can be continued indefinely, and it is easily shown that lintgn. Ds = =. In Chapter 9 we will see that the sequence [pj is @ numerical solution tothe ditferenial equation y= 0.001. The gluten is known tobe yx) = e202, Indeed, if we compare ‘the 1000 term sn the sequence with »(100), we se ut pian = 1.108116 ~ 1.195171 2 = 1W, . In dis sectin we are concerned with the types of tuncuons g(x) that procuce convergent sequences 174). 1 Fixed Points Definition 2.1 (Fixed Point. A fred point of a funtion g(1) is areal aumbsr such bot 2 = 6) o fixed pointe ofa function y — g(x) ae the point of intersection Definition 22 (Fixed-point Iteration). The serstion pest = tips) for n = 0. 1... is called fived point iteration a 90.2.1. [HeRsTION FoR SLING 4 = 4K * Thesrem 21. Assume that is continoes function and tha! (pa 9s x sequence seveate by fn pint raion. Hime p= Pesca P va hxed pane gs). Froaf {Vite Pa = Po te biBieeae Pa) = P11 follows from this result the fonts of g, and the elation Pay (Ps) that (2) iP) = 6 (i, Po) = im.) = fi Pat = Cea een : Example22. Consider the convergent iteration pos0S and pis ze ‘Te first t0 terms are obtained bythe cal pre S800 =o, p09931 95829 9 10703, 034609 9 567560 95080 4. 9, 586507 pw “The sequenet is converging. and further clcultions reveat that ig Pe = 0567143 ‘Taus we have found an approximation forthe fixed poin ofthe function y ‘Tre followicg two theorems establish conitions for the exinence of a fied point ‘andthe convergence ofthe fxed-poimt iteration process toa fixed paint “Theorem 22. assume that ¢ € Cla, b}. 2) Uf the range of the mapping y = g(x) satisties y € (a,b! for all x ¢ fab], then g hae a Bred pointin (2,5) (4) Furthérmore.cuppose that g(x) is defined over (a, b) and that apositise constant A < J exists with |g'(e)i < K <1 for sll x © (a,b) then g has 2 urique fixed pint Pin ab)4° Cnar.2. Twe SOLUTION OF NONLINEAR EQUATIONS (x Proof of (3}. If gla) = a or g(b) = b, the assertion is true. Otherwise, the values ‘of g(a) and g(b) must satisty g(a) € (a,d] and g(4) € [a, 6). The function f(x) = gC) has the property that say Now apply Theorem 1.2, the Intermediate Value Theorem, to f(s), with the constant 1. = 0, and conclude that there exists a number P with P € (a, 6) so that f(P) ‘Therefore, P = g(P) and P is the desired fixed point of g(x). Proof of(4), Now we must show tha this solution is unique, By way of contradic~ tion, let us make the addtional assumption that there exist two fixed points Py and Pa, Now appiy Theorem 1.6, the Mean Value Theorem, and conclude that there exists @ number d ¢ (a, b) so that ~ 610) > 0 sla) <0 and fd) 6 gtd) Next, use the facts that g(Pi) = Pj and g(Ps) = P to simplify the right side of equation (5) and obtain re RA Bur this contradicts the hypothesis in (4) chat la"(x)| = 1 over (a,b), 60 it is not possible for two fixed points to exist, Therefore, g(x) has a unique fixed point P in a, 6] under the conditions given in (4), . ed) Example 23. Apply Theorem 22 to rigorously show that g(x) = cos(x) hes a unique Fixed poin in (0, 1} Clearly, ¢ € C{0, 1). Secondly, g(x) = cos(+) isa decreasing function on 10, 1, thus its range on (0. 1s 051). 1] ¢ (0, 1]. Thus condition (3) of Theorem 2.2 is satisfied and sg ha a fixed point in [0,1]. Filly. if ¢ (0, Ie them [sx)] = | sin(x)! = sints) = Sin(1) < 0.8415 < 1. Thus K = sin(1) < 1, condition (4) of Theorem 2.2 is satisfied, and {as 2 unique hxed point n 10, 1. . ‘We can now state a theorem that can be used to determine whether the ixed-point iteration process given in (1) will prose a convergent or divergent sequence Theorem 2.3 (Fised-point Theoren). Assuie that (i) g. 4” © Cla, b} Gi) K is postive constant i) 70 € (a, Band (iv) #(x) € fa, 6] forall x € Ta. bl (6) WF [g's K <1 forall x © {a,b} then the iteration py = (Py) wil ‘converge tothe unique fixed point P € {a,b}. In this ease, P is Said 10 be an auractive fixed point (Ty Af Leo! > 1 for all x € (a,b), then the iteration po = 2¢px-1) will not converge to P.Inthis case, P is aid wo bea repelling fixed poin and he iteration ceahibits local divergence. Sue. 2.1 ITERATION FOR SOLVING = gtx) 4s We-p|—4=-—! pd —e} a ™ % Figure 23. The retationship among P, po, Ps |P — pol and |P — pil ‘Remark 1, Ris assumed that po # P in statement (7). Remark? Because gis continuo: on an interval containing itis petmissile w use the simpler criterion g'(P)| < K <1 and |g'(P)! > 1in (6) and (7), espectvely Prodf, We fist show that te pots (pu) alle in (a. 2). Starting with po, we apply Tacorem 1.6, the Mean Valve Theo, These en a vale € a. 9) 50 hat VP ~ pil = 1g) — gtpo)1 = le"{eo)l po? = IP po KU pol <1 = po @) Therefore, pr is mo further foour F thas po was, an it follows that pi € (a,b) (See Figure 2.3). In general, suppose that p»1 € (a,b): then le P) = ere = fe DP ~ pe DI [ea DIP ~ Peal SKIP = penil 1, and «sy P= pal s Ue Pol for all n> 1 Sec.2.1 ITERATION FoR SoLVING x 0 ence when I< (P), Figure 25 (b) Divergent oscilla aon when g'(P) <1 Graphical Interpretation of Fixed-point Iteration Since we seek a fixed point P t0 g(x) i is necesary thatthe graph of the curve y= g(a) and ie line y — 4 intersect at he point (P, P). Two supe type of ‘converter iteration, monotone and oscillating ar illustrated in Figure 2a) and (), respectively "To visualize the process, sat at py on the Aan nd have verily Wo the point (po, pd) = (po, 8(po)) on the curve y = g(x). Then move horizontally from (po, P1) to the point (py, pi) onthe line y = x. Finally, move vertically downward to p) on the x-ans. Tho rooutsion ces = 6(pr) is wed to constact the pot (Ps Prt) 00 the graph, then a horizontal motion locates (py 41. Py) on the line y = x, and then a vertical moverentends up at py. onthe x-ats. The situation is shown in Figure 2448 Cuiae 2 THe SoLUTION oF NontiNeaK EQUATIONS fix) ~0 If |g'(P)] > 2, then the iteration py 1 = g(pn) produces a sequence that diverges wey from P, The two simple types of divergent iteration, monotone aud oscillating, ae ilustrated in Figure 2.5(a) and (b), respectively. Example24. Consider the iteration p,1 = g(ps) when the function g(x) = +x~27/4 'sused. The ied points can be ound by solving the easton x = (x). The tw slutons (oa piven ebarev — -Pand r~9 The drain ofthe fimston sq) ~ 12/2, fn there are only two cases consider. 2 casei: 20s Sa ih 2 owes tenet 2 Tanaris = daira Covet P: then get slg, me=t ‘Since ig < 4 on [1,3], by Theo- oi Sin ig (21> $on{-3, —1.by The- cram 28 tere il comers 3 |r ‘Theorem 2.3 does not state what will happen when @/(P) = 1. The next example ins been specially consrucied su that the sequence {pe} converges whenever po > and it diverges if we choose po < P. 8(Px) when the function x) = 2¢2— 1/2 Example 25. Consider the iteration py exists. The derivativeis e(2) = 1/(e— 1) forx 2 1 is used. Only one fixed point and g'(2) = 1, a0 Theorem ?3 dace not apply. There ser wo cxses to concider when the starting value lies othe left or right of P = 2. i Case i: Str with py = 15, Case i: Stax with py tener ey = ALOIS den ge 87 pas te7teest P= 240789513. ps Lares 37309914 ps =0.53890832 5aasen84 ps= 2 -awurtony"? 2B, Pe =z, Since pg lies ooece tne domain of ‘Tm sequence 1s converging 10 slowly £13), the tem pe canna be computed (o the vulue P = 2; inded, Phono = ‘oosssria. Ste. 2.1. IrBRaTio FoR Sotvina 4 = 5(2) ” Absolute and Relative Error Considerations In Example 2.5, case (i), the sequence converges Slowly, and after 1000 iterations the three consecutive terms are roo = 2.00398714, pico = 2.00398317, and proms = 2.00397921 This should not be disturbing; after all, we could compute few thousand more terms and find « better approximation! But what about a criterion for stopping the iteration? Notice that if we use the difference between consecutive terms, lero Proce! ~ 12.00398317 2.00397921| ~ 0.000396. Yet the absolute error in the approximation poop ie known ta he |? ~ presa| = |2.00000000 ~ 2.003987141 = 0.00398714. This is about 1000 times larger than |pico1 — pion! and it shows that closeness of consecutive terms does not guarantee that accuracy has been achieved. But itis usually {We only criterion available and is often used to terminate an iterative procedure. Program 2.1 (Fixed-Point Iteration), To approximate a solution to the equation | + = ie) sarin wit te iat 055 py a ‘function Oe,pyorr,P]-fixpt (@,p0, tol mast) f laput ~ 6 ie she sceration function input ae a string “4° ~ pO is the initial guess for the fixed point i tol is the tolerance % ~ maxi is the maximum nunber of iterations Yourput ~ k io tho nunber of iterations that vere carried out = p 4a the approximation to the fixed point x = err is the error in the approximation % ~ P contains the sequence {pn} PAD p05 for ke2:maxt POO=feval (g,PQ1)); erreabe(P(i)-P(z-2)) relerr-err/(abe(P(R))+eps); PPP: Af (arrctot) | (relerretol) ,breaksand rimim number of ‘iterations excceded’) ‘Remark. When using the user-defined function fixpt, it is necessary to input the Mofile g.m as a string: "(see MATLAR Appendix)50 CHAP. 2 THE SOLUTION OF NONLINEAR EQUATIONS. f(x) = 0 Exercises for Iteration for Solving x = g(x) 1. Deteemine rigoroly if ech fnetion has & nique ied point on the given interval (llow Exampie 23) (a) 60) =1~7/40010.1) ) 9s) =2-F on 0,1] (@) ex) = Ix on f05.5.21 2. laveigate the nature ofthe ined pon iteration when aya, (@) Solve g(x) = + and show that P = 2and P = 4 are ined point. {b) Use me staring vale py = 1 and.eompute pi, po, and ps (©) Use the sting vale po ~ 3.8 and compute ps, ps, ad ps (@) Find the errs Ei and relative ers Re forthe vals pin pats) ad (6) (©) What conclusions can be deawn from Theorem 2.3? 4 raph (2) Be ne y = x, andthe gWven xed point # onthe same coordinate system. Using the given starting value po. compute and pa, Consist figures similar to Figures 24 and2.5. Based on your graph, determine geometrically if fixed point tration converges. (@) £02) =6-+2)"?, P=3,and po =7 2s.P 23P (8) ghey 42842, Pe Dando = 4, Let g(x) = x* +1 ~4, Can Bxed-point iteration be used to find the solution(s fo the 22 equation x= a(x)? Why? 5, Let gx) = xeostx), Solve x = g(2) and find all he fixed points of ¢ (there ae in finitely many) Can fxe-pin iertion be weed to fnd te olin) othe equation x= g(a)? Why? 6 Suppose that (x) and («are defined and comtinuouson (a6), Pos pa € (a0) and p; ~ a(po) and Ps ~ gps). Also czar tht there exit 3sorataat sch tage) = K. Show that [p> ~ pti < K'py ~ po. Hint. Use the Mean Value ‘neorem 7. Suppose that g() ang) ase continous on (4,6) and Maa jy’G)| = Lou dis interval. Ifthe fixed point P and ihe inital approximations py and ps lien the itera (2.2), the show that p, = gpa) implies that Ei] =P pil = IP ~ po! = IEol once sateen (1) of Theorem 23s etablished (local divergence) 8 Let 2) = ~0 00014? + x and ao = and consider fixed-point iteration, (a) Show that po > pa >> Pa > Past >> (©) Show mat py > O fora SEC.2.2 BRACKETING METHODS FOR LOCATING 4 ROor st (©Since the sequence {9} is decreasing and bounded below, it has limit. What is the init? 9. Let g(x) = 0.5x + 1.5 und pp = 4, and consider fixed-point teravon, (@) Show that the fixed point is P = 3 (©) Show that |P ~ py = |P — py/2 for (©) Show that 1# — pal = 1" — poi/2" torn 10, Let g() = 1/2, and consider fixed-point iteration (a) Find the quantity p11 pal/|pvatl (©) Discuss what will happen if only the relative error stopping criterion were use in Program 2, 11, For fixed point iteration, aiseuse why iti an advantage to have (P) Pe y i Algorithms and Programs 1, Use Program 2.1 to approximate the fixed points if any) ofeach function. Answers cane a yr of eae Zaeion ai tne that clearly shows any fixed points. (a) gle) =x ~3e8 28 2 ©) g(a) = corcsinte)) (©) etx) sintx + 0.19) er @ a Bracketing Methods for Locating a Root Consider afaniliae topic of interest. Suppose that you save money by making eeu monthly deposits P andthe annual interest rate is 1; then te toal amount A after depositsis (Digs See = +P (i+ 5) +P(i+5) +. sees ‘The fistterm on the right side of equation (1 isthe last payment, Then the nextlast payment, which has eared one period of interest, contibutes P (1+ 45). Te second- ‘from-last payment has earned two periods of interest snd contributes P (1+ 4)*, and soon. Finally the last payment, which hac earned interest for N 1 periods, connvtes (14 4)""" coward the total. Recall chat the formula for the sum of the N terms of a geometric series is 22 Cuar2 THESOLUTION oF NontaNean EQUATIONS fis) =O ‘We can write (1) in the form, e(ia(ep)a(- and se the sobstttion x= (1+ /12)n (2) t0 obtain a+" ‘This canbe simplited to obtain the annuity equation, P ry" ® se ((4d)"=) ‘te following example uses the annuity-due equation and requires @ sequence ot repeated calculations t find an answer A Example 2.6, You save $250 per smo fr 20 years and desie dha he total value of all payments and interest is $250, 000 atthe end ofthe 20 years. What interest rate 7 is Deeded to achieve your goal? If we hold N = 240 fixed, then A is a function of I alone: that A = ACD), We wil tart with two guesses, fo = 01? and fy = 013, and perform sequence ofcaleuations to narrow down te final answer. Starting with fp = 0.12 yields 1) 250 oy Since this value is litle short ofthe goal, we next ry fy = 0.13: a0 gia (+82) viare(('=2) -!) =a ‘This is lite high, so we ty the value inthe mide fy = 0.125: 250 0.125)" 40.125) aisha ((1+ ) -1) “This i wpain high ad we conclude that de desived rate Hes iu the interval (0.12, 0.12 164, 623. The next uss isthe midpoint Is = 0.1225: 250 0.1225) a = 1) =255, 803. nee) = ras (1+ 8) —) asa This is high and the interval is now narrowed wo [0.12, 0.1225]. Our las calculation uses the midpoint approximation fg = 0.12125: 5 1) =2sisie Sec.2.2 BRackETING Merilops Fok Locarina a Root s (ofa (ofa) Pa éfle) ee Nite a > fo) ~——_+ fbn ero (2 11 7.a) and fey nave “opposite signs then squeeze from the right. (80 fee) and fb) have onposite sins then squeeze from the left ‘igure 2.6 The decision process forthe bisection process unter iterations can be done to obtain as many significant digits as required The purpose ofthis example was to find the valuc of { dat produced a specified level L of the Funetion value, tha is to find a solution to AC) = L. Ie is stand practice 10 place the constant Zon the lft and solve the equation A(Z) — . Definition 23 (Root of an Equation, Zero of a Function). Assume that f(x) 18 a continuous function. Any number r for which f(r) = Qis called araot ofthe equation I(x) = 0. Also, we say ris azero ofthe function f(x). 4 For example, the equation 2x? + $x — 3 = 0 has two real roots ry = 0.5 and r2 = 3, whereas the corresponding function f (x) = 2x7-+5x—3 = (2x—1)(r+3) hhas two real eros. 7) = 0.5 and re = —3 ‘The Bisection Method of Bolzano In this section we develop our fist bracketing medhod for using a ze ura continuous function. We must start with an initial inerval fa, b], where f(a) and f(b) have ‘opposite signs. Since the graph y = f(x) of a continuous function is unbroken, it will crosethe x-axis at zero.x = r that lies eomewherein the interval (sce Figure 2.6). The bisection method systematically moves the end points ofthe interval closer and closer together until we obiain an interval of arbitrarily small width dhat brackets the zero. ‘The decision sep for this process of intorval halving is fist to choose the midpointS4CHAR.2 THE SOLUTION oF NONLINEAR EQUATIONS f(x) = 0 (¢= (@-+0)/2 and then to analyze the three possbiltes that might aise: a If Flay and fc} nave opposte signs. & zero Hes in (a. c 6) If Fle) and f(b) have opposite sign, 42270 lis in [e, 5) 6) If Fle) =O. then the zer0 is either ease(4)or(5) occurs, we have found an interval haf as wide asthe original intervel that contains the root, and we are "squeezing down on it” (see Figure 2.6). To wontinue the process, selabel the uew salle inteval fu b] and tepeat the process until the interval is as small as desired, Since the bisection process involves sequences of nestcd intervals and their midpoints, we will use the foliowing notation to keep wack sof the details i the proves jag, Bo} the starung interval and cy = 85% is the midposat. 1-6 ]is the second interval, which brackets the zero, ané i its mudpoint; (7) helinterval (a1, by] is Hallas wide a Lao, Boh tier ariv:ng atthe nth anierval ft, By Which Drackers r and "as Mudpoint 0 the interval [ac boa] i constructed, which also brackets r and is half {8 wide (09, Dal Tt is Heft as an exercise forthe reader to show thatthe sequence of left end points is imereasing and the sequence oP right end puis 5 dcvieasing, hat i, 8 Says eager Se Sb se Sh ho were og = BH, an Flor P Fag < 0.160 lana OF Wdgets Beet = Lens Bad f08 all (9) Laat. bye tT ‘Theorem 2.4 (Biseetion Theorem). Assume the: f € C[a, b] and that there exists a vumberr © fu.d] such that f(r) = 0. IF fa) and £6) have opposite signs’ and ‘er} Fepresents the sequence of midpoints generated by the bisection process of (8) and (9), then for n=0, 1, U0) rae < and therefore the sequetce (¢4]%iq converses 0 the zero x =r; that 1, wy Jim cy =r. Proof Since both the 7era sed the midpoint cx He in the interval [ap Be) the die- tance between cy and r cannot be greater than half the width ofthis interval (see Fig- ure 2.7). Thus «2 W-ols for all n Sec. 2.2 BRACKETING METWODS FOR LOCATING A ROOT s Figure’27 The root rand midooint cy of fs. by) forthe bisection meted (Observe that the successive interval widths form the pattern Itis eft as an exercise forthe reader o use mathernatical inductioe and show thet oy ees Combining (12) and (13) results in aay for all n [Now an argument similar 0 the one given in Theorem 2.3 can be used to show that 114) implies thet the sequence (cy converges tar aod the proof ofthe theorem is complete : Example 2.7. Te funciion n(x) = x sinix) occurs mn We study of undamped forced ‘oscillations. Find the valve of x that ies in the interval (0.21. where tae function takes on the value x) = 1 (the function sin(x) is evalvaed in radians) ‘We use the bisection method o finda zeroof the function f(a) — sina) 1, Stating with ap = Oand by = 2, we compute #0) = -1.000000 and f12 sias9s 50 a root of f(1) — 6 Nes in the interval [0.2]. At the midpoint