gt 4 x r _.:. 'o.s ----.-----------_ y6^j T r.. ^ _.._ C..._6 a i' :: _, a,ti Ck So /- { r1t`..r.t"`pd?4'' "+u "...'3,1 sx 'may r e?'.:` Fy`.`I ` -... n a - `.n Be a %... > r's egvrr'.,,,,., '... PY v la' 6 4fS 9Js.<d' C.:L,,'If... o "., ',. Q i ' _?.,.. _ f _ n rj z j ' I ;s r x a _ s rk f a --, _ t s. r _.. a,_,..., d.. "< w s _ Ed ' n C. - P C! ',?'Jds _ ' ; r td5 c E, '>'a",.mss' d;;.;., y! tj.. -b F ` Tp ' :i '. C e't s; 1 J P ts,,. -,,d.', " `y. ibs;, -p ' p L ' C "y, /t` '- _ 'tip 'v.]+2 f "` < +', I y..e ' s' a t ''/r '`' 'IM ",I 'ate...., J''?l."'j B.L.,'I ' _."l P.- s ' L' C.g " ' f -0 t _. 3t ). n _ c... ( a _ r - ;! 1 :s P' ' 2 5 f :. 1 k ;; - `:-tit" f G,.; G 2' "1"' f i{ a`t, t'1ds,sl a,?rg`` f'- ihlo(
Ire, a _... g9 ' " '= _ c adr` G? '"'.r='a' Ys 7 YL.J v G 0L b p by «1_d,f`e r i h,,r,,, C + ' = ', c ' _ C J, %.. 1, :., `F " ` y ' ';f r. ;; rr It &-7 -,y, / 1 v P,. d FCC ', '' L t, j r I 'ib., ) ' ` 'lx 1, P f L Cc J ;, +...!rte. ` nom, fro,, Fi r ' t U _ Li'^-Y 3 et c. 'j,,' re'! J```v3.r'i ' "%'"a^ b,^ c GIB ler'' GJ' a " )1/r.PrG, I ( ly a,.j F Ca, I ' l z 1 z > q,it 71 f,, / -,2 S'v g l > + inn ",_ J, i,, y 11 l `. 1,, 1 _... 1.yon, l :'f't r 'a',('-n 1 - - y'c I'P"n ( ` r7 E ` p /,/' `ale:)- _ (:ctv yjc7'+`! -y' ' ;.. 1",- 3 % :c:;f' g, :1 -t l ' + -` ' (,. 1 G.C T J.-- _._ l, r ar Z.s--(, - s ye!rr,,,,a,a r-af r r Sy,-it,ib" y;, _ a,, (_._._ ro v
3r7..,,.- %v8f' w s fl _, f,g ` + J ycy., ^+ ` q, 7 T-.1 '.(C /..4" '"P '' 4C.'`" 3 X F, 3 4 v 4d! d 4 5.+5 a. V j g D..... 1 a f 7 q',.r '..=.N'' a"ifs `a`+'fe "'a''f1 `1,tij `.'/f &` f+ltgz.f' _ - {, a 1 ' e_., 9 + :_.. _.. F P GVw 'a j t r 5 uf' l a ; y/^1-7qf /ti _/ / e `3 /Of )U b ''.._...,f, _.... U :. $f.e i'wgt,i;tlq Y> 4`,... f.. qy'"'"`'r,_ y' j f y^ @. / " y^ {g C ' '' C(-' `T tt) i tom g "- 5'd' e' "t`,,. j o w- y, iq t g iyi- 1 -a 61M :) t - ' f ' c ` a i' "'' C pro _ ptl.,.,,- y fay, --,, N rt'i (`,',,n C,) %. - a.----, r _ e, - d,,
-, 5, a " r ' ;,. w,,, G z 6.......- 1`9..+6 r`,'t 7 aee..a f... -}. _z fx ' j /.+ / f!"l d '`c/i L'ih t` v 6 Z'f J I I_,7 s Y. A / 1 b, /K' r +'6',7 y.. Ic-v,C- a!fir_- ea,i'.8 '' 4- v u,, Y, " 3 fi f _ ', Z ( I 't,,z v / AL..i C L"i '`?, `1 '7 d:t+t `1 -rp f _ < fit,-, `o'.m.a -!.J J ct. "^ C.
J {' I [ d; m. F q - r s " ;:.!( d z E't' 'al at, %ate [a.d s'!,p' f al,d;.r r,_ r_ rt.r1_ r t4 s., c x" z -,, b p (a a'y, 3 3"1 ter, r` H 'e a+ 1 6 s a r" E y(s, u pg.y^,#2 ppy { [ ) y... _ '1 i ('.tiey4s '1.. K G"fS y'pn "c:'.. rti,.-p 9G-. q7 % a l ''e/'.g,l f ' r... c,cl`., f c q ( n. g gf `/{ d,, ) q 6 Gg Gi.._,"n'8.bi U:, '`E lz7,{. pb,1(, t _"rjo _... _..., ex... p b d tigl' -U4. dn!7.,.,.., a ( ' - a 1 a. i d ' a. y 4 " e 9.I- (7 +`.:4t` 'i G/,'y''o. '! - t > u ; 7. ','M..?Gi r C +,r =' w r y a - %s y -- w. '? - t -., e Val ' :s. -.,, w - =cif
7 s', u w- ' l ln7 e?, t (" 2{ e i i IA's - 1 t! x r,a e `m., 11' 7, _ r f 'T.ate e _. _ / / f?t / U r -- ',., --... <e a
function [xc,yc,errx]=newtonldr(fun,funpr,xl,tol,kmax,pcon) Input. fun function (inline function or m-file function) funpr derivative function (inline or m-file) xl starting estimate o tol allowable tolerance in computed zero kmax maximum number of iterations o pcon=expected order of convergence, p $ Output: xc approximation to the root fun(xc)=0 o yc =fun (xc) errx = approximation to error in xc x(1)=xl;err(1)=0.;papp(1)=0.;capp(1)=0.;cap2(1)=0.; y(1)=feval (fun,x(1)) ; ypr(1)=feval(funpr,x(1)); for k = 2:kmax x(k)=x(k-1)-y(k-1)/ypr(k-1); err(k)=abs(y(k-1)/ypr(k-1)); if k<4 papp(k)=0.;capp(k)=0.;cap2(k)=0.; if k==3 cap2(3)=abs(err(k)/(err(k-1))^pcon); end %if k==3 else papp(k)=(log(err(k))-log(err(k-1)))/(log(err(k-1))-log(err(k-2))); capp(k)=abs(err(k)/(err(k-lj)^papp(k)); cap2(k)=abs(err(k)/(err(k-1))^pcon); end oif k<4 y (k) =feval (fun, x (k)) ; if abs(x(k)-x(k-1)) < tol disp('newton method has converged'); break; end ypr(k)=feval(funpr,x(k)); iter=k; end if liter >= kmax) disp(' zero not found to desired tolerance'); end n=length(x); if imag(x(1)) =0 imag(y(1)) =0 disp(' n x y err Pa1P ) else disp(' n x y err papp Capp cwithpcon') end oif for k=1:n; gout = [k' x' y' err' papp']; odisp(out) if imag(x(l))= 0 ( imag(y(1)) = 0 fprintf('%3.of o10.6f o10.6f %-13.5g o-13.5g o-13.58 o8.4f\n',k,real(x(k)),imag(x(k)),real(y(k)),,imag(y(k)),err(k),papp(k)); else fprintf('%3.of o10.6f o-13.5g o-13.5g %8.4f o8.4f %8.4f\n',k,x(k),y(k),err(k),papp(k),capp(k),cap2(k)); end oif end %for Page 1 of
>o output for problem 6 >[xc yc errx]=newtonldr("pr6fun","pr6fpr",o,l.e-11,20,2) Newton method has converged n x y err papp capp cwithpcon 1 0.000000-3 0 0.0000 0.0000 0.0000 2 3.000000 1441.5 3 0.0000 0.0000 0.0000 3 2.822099 548.43 0.1779 0.0000 0.0000 0.0198 4 2.631425 209.48 0.19067-0.0245 0.1828 6.0247 5 2.425401 80.251 0.20602 1.1167 1.3110 5.6668 6 2.201692 30.667 0.22371 1.0635 1.2005 5.2704 7 1.961003 11.48 0.24069 0.8884 0.9103 4.8094 8 1.715613 3.9921 0.24539 0.2645 0.3576 4.2359 9 1.505268 1.1135 0.21035-7.9651 0.0000 3.4931 10 1.389750 0.16916 0.11552 3.8891 49.6435 2.6109 11 1.365232 0.005603 0.024518 2.5862 6.5118 1.8374 12 1.364363 6.6398e-006 0.00086888 2.1548 2.5664 1.4453 13 1.364362 9.3507e-012 1.0321e-006 2.0167 1.5375 1.3671 14 1.364362 0 1.4535e-012 2.0003 1.3698 1.3645 xc = 1.36436159792756 yc = 0 errx = 1.45349815489365e-012 >% >o output for problem 3b >[xc yc errx]=newtonldr("pr3fun","pr3fpr",l,l.e-11,20,2) Newton method has converged n x y err papp capp cwithpcon 1 1.000000-1 0 0.0000 0.0000 0.0000 2 1.100000 0.27972 0.1 0.0000 0.0000 0.0000 3 1.082551 0.011028 0.017449 0.0000 0.0000 1.7449 4 1.081805 1.9165e-005 0.00074605 1.8055 1.1149 2.4504 5 1.081804 5.8158e-011 1.301e-006 2.0150 2.6036 2.3375 6 1.081804 1.7764e-015 3.948e-012 2.0003 2.3431 2.3325 xc = 1.08180405955982 yc = 1.77635683940025e-015 errx = 3.94804435424867e-012 >o >% output for problem 4a >[xc yc errx]=newtonldr("pr4fun","pr4fpr",0,5.e-9,26,1) Newton method has converged n x y err papp Capp cwithpcon 1 0.000000 1 0 0.0000 0.0000 0.0000 2 0.166667 0.1234 0.16667 0.0000 0.0000 0.0000 3 0.202177 0.027537 0.03551 0.0000 0.0000 0.2131 4 0.217257 0.0065717 0.01508 0.5539 0.0958 0.4247 5 0.224298 0.0016082 0.0070409 0.8893 0.2934 0.4669 6 0.227708 0.00039792 0.0034102 0.9519 0.3816 0.4843 7 0.229387 9.8979e-005 0.0016791 0.9773 0.4329 0.4924 8 0.230220 2.4683e-005 0.00083321 0.9890 0.4625 0.4962 9 0.230635 6.1631e-006 0.00041505 0.9946 0.4793 0.4981 10 0.230842 1.5398e-006 0.00020714 0.9973 0.4887 0.4991 11 0.230946 3.8483e-007 0.00010347 0.9987 0.4939 0.4995 12 0.230997 9.6193e-008 5.1712e-005 0.9993 0.4967 0.4998 13 0.231023 2.4046e-008 2.585e-005 0.9997 0.4982 0.4999 14 0.231036 6.0114e-009 1.2923e-005 0.9998 0.4991 0.4999 15 0.231043 1.5028e-009 6.4613e-006 0.9999 0.4995 0.5000 16 0.231046 3.757e-010 3.2306e-006 1.0000 0.4997 0.5000 17 0.231047 9.3924e-011 1.6153e-006 1.0000 0.4998 0.5000 Page 1 of
s j v,,.,fy z:: -.. m Y,.gip c " 1, 1 l. f'j r., a c >?.,' A ' 9 'Td 'e4 a ' ' -, ' P, p!' / i '` -a t, y `? i r '-- i i i ` r p,., d. _ f -. t ' "}8 'T-a'' 4 -a as -R "9A E 1 { (a s ' >B a'... _ v,a. R`. 2 l a ` r > r, a r `=3 ` c
0 output for problem 6 using pr6ftaylor.m to evaluate f(x)=integral 0 to x e^(t^2) dt with a Taylor polynomial >[xc yc errx]=newtonldr("pr6ftaylor","pr6fpr",o,l.e-11,20,2) Newton method has converged n x err papp cape 1 0.000000-3 0 0.0000 0.0000 2 3.000000 1441.5 3 0.0000 0.0000 3 2.822099 548.43 0.1779 0.0000 0.0000 4 2.631425 209.48 0.19067-0.0245 0.1828 5 2.425401 80.251 0.20602 1.1167 1.3110 6 2.201692 30.667 0.22371 1.0635 1.2005 7 1.961003 11.48 0.24069 0.8884 0.9103 8 1.715613 3.9921 0.24539 0.2645 0.3576 9 1.505268 1..1135 0.21035-7.9651. 0.0000 10 1.389750 0.16916 0.11552 3.8891 49.6435 11 1.365232 0.005603 0.024518 2.5862 6.5118 12 1.364363 6.6398e-006 0.00086888 2.1548 2.5664 13 1.364362 9.3494e-012 1.0321e-006 2.0167 1.5375 14 1.364362 0 1.4533e-012 2.0003 1.3700 xc = 1.36436159792756 yc 0 errx = 1.45329106454103e-012 cwithpco 0.0000 0.0000 0.0198 6.0247 5.6668 5.2704 4.8094 4.2359 3.4931 2.6109 1.8374 1.4453 1.3671 1.3643 function [y ier nfun err]=pr6ftaylor(x) [y ier nfun err]=quad("pr6fpr",o,x); This integrates the function integral 0 to x e^(t^2) dt using a Taylor polynomial. ier=0 is returned iff the integration was successful nfun=how many terms were used in the Taylor polynomial err = an estimate of the error in the solution sum=x; dfact=l.; term=x; nmax=900; efact=exp(x.^2);ier=0;k=0;err=1; if x < 0 efact=l; end oif while err > l.e-15 k=k+l; dfact=dfact+2; term=term*x^2/k; sum=sum+term/dfact; err=abs(efact*term*x^2/(k+l)/(dfact+2)); if k > nmax ier=1; break; end oif end while nfun=k; if ier==1; disp 'more terms are needed in the Taylor polynomial' x y=sum nfun err break; end %if y=sum-3; return