demoAINumerics
Newton's method doubles the correct digits
Newton's method on , one cell at a time. From the error is after four steps and zero after five; bisection needs 39 halvings to promise as much. Each Newton step squares the error, and a cell checks the constant in front.
Open in the workbenchDownload .vivOutputs below are from the site build’s run; Run all runs it again in your browser.
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
A notebook: the prose between the cells says what each one is for, and each cell's output appears under it. Press Run all, or run a cell with Shift+Enter.
Printed
One step
The tangent to at has slope and passes through . It crosses zero at , which is what the cell above printed. Already is close to 2.
Before running the next cell, guess how many steps it takes to get every digit a double can hold, about 16.
Printed
Tests 3 of 3 pass
- after four steps the error is below 2e-12 (passes)
- after five steps the error is zero: x is sqrt(2) to the last bit (passes)
- a double holds about 16 decimal digits: 53 bits, 15.95 digits (passes)
Why the digits double
Write the error as . One step gives
so . Near the root , and the error is squared at every step and scaled by . An error of becomes , then : the number of correct digits doubles.
The cell below measures for the first four steps. Far from the root the ratio is with still far from ; by the fourth step it matches to four digits.
Printed
Tests 3 of 3 pass
- an error of 1e-3 becomes 3.5e-7, then 4.4e-14 (passes)
- the first ratio is 1 / (2 x_0) = 1/2, exactly as the algebra says (passes)
- by the fourth step e_(n+1) / e_n^2 is 1 / (2 sqrt 2) to four digits (passes)
Against bisection
Bisection keeps an interval where changes sign and halves it. After halvings of the midpoint is within of the root, one binary digit per step, and that guarantee is all it has: it never fails, and it never speeds up. The figure plots of Newton's error beside of bisection's guarantee. Newton's curve bends down; bisection's is a straight line.
Printed
Tests 1 of 1 pass
- bisection needs 39 halvings to promise what four Newton steps did (passes)