Unformatted text preview:

Newton s method Example 2 Patrick Dale McCray Ph D Initial 29 March 2011 Revised 15 February 2012 Version 28 February 2012 Mathematica version 8 0 Code for Newton s method Suppose we wish to solve the equation f x 0 for x The basic Newton step may be computed as follows In 18 Clear fD In 19 NewtonStep x D x f xD HD f tD tD t xL NewtonStep xD Out 19 x f xD f xD For example evaluating the Newton step at x 3 would yield In 20 NewtonStep 3D Out 20 3 f 3D f 3D Using the function NewtonStep we may write a module for iterating until a desired level of accuracy is obtained The following Module is intended to iterate until the iterates agree to within a specified relative error and takes two arguments the initial value for the interation and the number of significant digits of precision desired For example if the initial value is specified exactly then using a precision of 100 will result in the computations being performed with 200 significant digits and the iteration will terminate when the iterates agree to within 100 significant digits 2 Newtons method Example 2 nb In 21 NewtonIteration initialvalue precision D Module 8 k test x1 change H local variables L k 1 test True p precision x1 N initialvalue 2 p D H 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 D H display when still changing L x1 xk D Return xkD Print Stop D D Example 2 From Section 3 8 Newton s Method in Stewart s Calculus Hybrid Edition ed 7 Let us solve the following equation In 22 x 6 Out 22 x6 In 23 2 2 Plot 82 x 6 8x 1 2 3 2 PlotStyle 88Red Thick 8Blue Thick D 5 4 3 Out 23 2 1 0 8 1 0 First we code the Newton step In 24 g x D x 6 2 g xD Out 24 2 x6 In 25 NewtonStep x D x g xD g xD 1 2 1 4 Newtons method Example 2 nb In 26 NewtonStep xD Out 26 x 3 2 x6 6 x5 Now 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 9D x2 1 16666667 rel error 0 166667 x3 1 12644368 rel error 0 0344768 x4 1 12249707 rel error 0 00350360 x5 1 12246205 rel error 0 0000311951 x6 1 12246205 rel error 2 43320 10 9 Out 27 1 1224620483093730 In 28 N 2 H1 6L 17D Out 28 1 1224620483093730 In 29 NewtonIteration 11 10 40D x2 1 123640441019718391482615237823215420374 rel error 0 0214913 x3 1 122465133524977792628259884510556238149 rel error 0 00104598 x4 1 122462048330573017319412253584555475223 rel error 2 74859 10 6 x5 1 122462048309372981434534066867733235926 rel error 1 88871 10 11 x6 1 122462048309372981433533049679179516232 rel error 8 91805 10 22 Out 29 In 30 Out 30 1 122462048309372981433533049679179516232411110613986753440409545882904005565861 N 2 H1 6L 81D 1 122462048309372981433533049679179516232411110613986753440409545882904005565861 25


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