DOC PREVIEW
IIT MATH 149 - Newtons method Example 2

This preview shows page 1 out of 3 pages.

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

Unformatted text preview:

Newton’s method, Example 2Patrick Dale McCray, Ph.D.Initial 29 March, 2011; Revised 15 February, 2012Version 28 February, 2012.Mathematica, version 8.0Code for Newton’s methodSuppose we wish to solve the equation f(x) = 0 for x. The basic Newton step may be computed as follows.In[18]:=Clear@fDIn[19]:=NewtonStep@x_D := x − f@xDêHD@f@tD,tDê.t→ xL; NewtonStep@xDOut[19]=x −f@xDf@xDFor example, evaluating the Newton step at x = 3 would yieldIn[20]:=NewtonStep@3DOut[20]=3 −f@3Df@3DUsing 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 a specified relative error and takes two arguments: theinitial value for the interation, and the number of significant digits of precision desired. For example, if the initial value isspecified exactly, then using a precision of 100 will result in the computations being performed with 200 significant digits and theiteration will terminate when the iterates agree to within 100 significant digits.In[21]:=NewtonIteration@initialvalue_, precision_D :=Module @8k, test, x1, change <H∗ local variables ∗L,k = 1; test = True;p = precision;x1 = N@initialvalue, 2 p DH∗ capture the initial value to 2 p digits accuracy ∗L;While@test H∗ is true, repeat the following ∗L,xk = NewtonStep@x1D;k = k + 1;change = If@Abs@x1D > 0, Abs@xk − x1Dêx1, Abs@xkDDH∗ relative error test ∗L;test = Hchange > 1 ê 10^pLH∗ agreement to within "precision" digits ∗L;If@test, Print@"x"k," = ", N@xk, pD, ", rel.error =", N@change, 6DD,DH∗ display when still changing ∗L;x1 = xk D; Return@xkD; Print@"Stop"DDü Example 2From Section 3.8, Newton’s Method, in Stewart’s Calculus, Hybrid Edition, ed. 7:Let us solve the following equation:In[22]:=x^6  2Out[22]=x6 2In[23]:=Plot@82, x^6<, 8x, 1 ê 2, 3 ê 2<, PlotStyle → 88Red, Thick<, 8Blue, Thick<<DOut[23]=0.8 1.0 1.2 1.412345First we code the Newton step.In[24]:=g@x_D := x^6 − 2; g@xDOut[24]=− 2 + x6In[25]:=NewtonStep@x_D := x − g@xDêg'@xD2 Newtons method Example 2.nbIn[26]:=NewtonStep@xDOut[26]=x −− 2 + x66x5Now we invoke our module with an initial value of 1 (to be converted to a high precision format by the module).In[27]:=NewtonIteration@1, 9Dx2= 1.16666667, rel.error =0.166667x3= 1.12644368, rel.error =0.0344768x4= 1.12249707, rel.error =0.00350360x5= 1.12246205, rel.error =0.0000311951x6= 1.12246205, rel.error =2.43320 × 10−9Out[27]=1.1224620483093730In[28]:=N@2^H1 ê 6L,17DOut[28]=1.1224620483093730In[29]:=NewtonIteration@11 ê 10, 40Dx2= 1.123640441019718391482615237823215420374, rel.error =0.0214913x3= 1.122465133524977792628259884510556238149, rel.error =0.00104598x4= 1.122462048330573017319412253584555475223, rel.error =2.74859 × 10−6x5= 1.122462048309372981434534066867733235926, rel.error =1.88871 × 10−11x6= 1.122462048309372981433533049679179516232, rel.error =8.91805 × 10−22Out[29]=1.122462048309372981433533049679179516232411110613986753440409545882904005565861In[30]:=N@2^H1 ê 6L,81DOut[30]=1.12246204830937298143353304967917951623241111061398675344040954588290400556586125Newtons method Example 2.nb


View Full Document

IIT MATH 149 - Newtons method Example 2

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 Example 2
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 Example 2 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 Example 2 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?