DOC PREVIEW
IIT MATH 149 - Newtons method control

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Newton’s method controlPatrick Dale McCray, Ph.D.29 March, 2011IntroductionThe typical way of controling an iterative scheme is to compare successive values of the quantity being computed with thepreceding value. In order to achieve high accuracy in computed quantities, this notebook introduces a Module based on theidea of having Mathematica perform the iteration with exact values and inspecting the resulting exact values numerically with theN function.ü Exact computationDecimal numbers with a few digits are stored with limited machine precision. Here we compute a value z using (approximate)machine numbers.In[130]:=z  12.4567  37.8; z, Nz,Nz, 100Out[130]=0.329542, 0.329542, 0.329542On the other hand, numbers calculated with whole numbers are stored exactly, such as w.In[131]:=w  124567  10 000378  10;  w, Nw,Nw, 100Out[131]=124 567378 000, 0.329542,0.3295423280423280423280423280423280423280423280423280423280423280423280423280423280423280423280423280How do these two (same (??)) values compare?In[132]:=z  wOut[132]=5.55112  1017The correct, exact value of the computation, namely 124567/378000, is rational, hence has an eventually periodic decimalexpansion that never terminates, unlike the machine version, 0.329542, which is finite (and incorrect!).Sometimes extra precision may be required. The default value of the maximum extra precision is 50.In[133]:=$MaxExtraPrecisionOut[133]=50We will have to increase this in the following discussion.Code for Newton’s methodSuppose we wish to solve f(x) = 0 for x. The basic Newton step may be computed as follows.In[134]:=NewtonStepx_ : x  fxDft,t.t xFor example, evaluate the Newton step at x = 3 would yieldIn[135]:=NewtonStep3Out[135]=3 f3f3Using the function NewtonStep we may write a module for iterating until a desired level of accuracy is obtained. Thefollowing Module is intended to iterate until the iterates agree to within 40 decimal places and takes one argument, the initialvalue for the interation, namely x0.In[136]:=NewtonIterationxinit_ :Module k, test, x0, change  local variables ,k  0; test  True; x0  xinit;Whiletest  is true, repeat the following ,xk  NewtonStepx0;k  k  1;change  Absxk  x0;test  change  1  10^100;Print"x"k,"  ", Nxk, 45,", ",Nchange, 9;x0  xk ; Print"Stop"ü ExampleLet us solve the following equation:In[137]:=x  3  SinxOut[137]=x3 Sinx2 Newtons method control.nbIn[138]:=Plotx  3, Sinx, x, 0, PiOut[138]=0.5 1.0 1.5 2.0 2.5 3.00.20.40.60.81.0First we code the Newton step.In[139]:=gx_ : 3 Sinx  xIn[140]:=NewtonStepx_ : x  gxg'xIn[141]:=NewtonStepxOut[141]=x  x  3 Sinx 1  3 CosxNow we invoke our module with an initial value of 2, first checking the default value of the maximum extra precision. In[142]:=$MaxExtraPrecisionOut[142]=50In[143]:=NewtonIteration2Newtons method control.nb 3x1 2.32373206111338325354188208345366581392706335, 0.323732061x2 2.27959482163992639068772151841669254197757185, 0.0441372395x3 2.27886286684763997073119345250115932298600016, 0.000731954792x4 2.27886266007584482041679741117310186574317502, 2.06771795  107x5 2.27886266007582831269995110466710382941208700, 1.65077168  1014x6 2.27886266007582831269995110456188862881827474, 1.05215201  1028N::meprec : Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating -2 +-2 + 3 Sin2-1 + 3 Cos2+á1à-1á1à 3 á1àá1à+á3à+-2 +-2 + 3á1à-1 + 3á1à+á3à+á1àá1à+ 3Siná1à-1 + 3 Cos2 +á4à+Timesá3à+ 3Siná1à. àN::meprec : Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating á1à1 - 3Cosá1à. àx7 2.27886266007582831269995110456188862881827474, 4.3  1057N::meprec : Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating -2 +-2 + 3 Sin2-1 + 3 Cos2+á1à-1á1à 3 á1àá1à+á4à+-2 +-2 + 3á1à-1 + 3á1à+á4à+á1àá1à+ 3Siná1à-1 + 3 Cos2 +á5à+Timesá3à+ 3Siná1à. àGeneral::stop : Further output of N::meprec will be suppressed during this calculation. àx8 2.27886266007582831269995110456188862881827474, 0.  1059StopSince the internal precision limit has been exceeded, we increase it and try again.In[144]:=$MaxExtraPrecision  200Out[144]=200In[145]:=NewtonIteration2x1 2.32373206111338325354188208345366581392706335, 0.323732061x2 2.27959482163992639068772151841669254197757185, 0.0441372395x3 2.27886286684763997073119345250115932298600016, 0.000731954792x4 2.27886266007584482041679741117310186574317502, 2.06771795  107x5 2.27886266007582831269995110466710382941208700, 1.65077168  1014x6 2.27886266007582831269995110456188862881827474, 1.05215201  1028x7 2.27886266007582831269995110456188862881827474, 4.27426496  1057x8 2.27886266007582831269995110456188862881827474, 7.05386830  10114StopNow we reset the internal precision limit back to its original default value.4 Newtons method control.nbIn[146]:=$MaxExtraPrecision  50Out[146]=50ü Investigating the final iterateSolution achieved for iterates agreeing to withing 100 places:In[147]:=Nxk, 100Out[147]=2.278862660075828312699951104561888628818274740739776516525585529248344464701839186256781340580146512Mathematica high precision calculation:In[148]:=Xk  x . FindRootgx  0, x, 2.2, WorkingPrecision  250Out[148]=2.278862660075828312699951104561888628818274740739776516525585529248344464701839186256781340580146512389613012252192308094868943884998837137383845350699117003501335444216009373218571499740602576404645321970635956073298400582545637493233865175964304189The difference:In[149]:=xk  XkOut[149]=1.9211406436879307525509  10227As we may see, since the computations are done EXACTLY, the corresponding expressions for x1, x2, x3, get rather LARGE:In[150]:=x1 NewtonStep2Out[150]=2  2  3 Sin2 1  3 Cos2In[151]:=x2 NewtonStepx1Out[151]=2  2  3 Sin2 1  3


View Full Document

IIT MATH 149 - Newtons method control

Documents in this Course
QUIZ

QUIZ

2 pages

QUIZ

QUIZ

3 pages

Quiz

Quiz

2 pages

Exam

Exam

4 pages

Load more
Download Newtons method control
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Newtons method control and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Newtons method control 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?