Math 171 - Alexiades
Lab 11
Finding roots - Newton-Raphson Method
A. Newton-Raphson root-finder
Write a code Newton.m that
implements the Newton-Raphson method for finding a root of
F(x) = 0.
It requires F(x) to be differentiable with computable derivative DF(x).
The user should provide: x0: initial guess,
maxIT: max number of iterations,
and TOL: tolerance for convergence.
Newton converges fast typically, so maxIT=20 usually suffices.
For convenience, you may set maxIT=20 and
TOL = 1.e-14 in the code
so only x0 needs to be provided as argument.
The code should: accept input x0 ,
print out the iterates:
n xn Fn
(neatly, in columns, use format: %d %f %e ),
and, upon convergence, print out
the value of the root, the residual (%e format), and
how many iterations it took.
The (formula for) F(x) and DF(x) should be coded in a
subprogram:
function [Fn , DFn] = FCN( xn )
B. To do:
1. Debug the code on a simple problem with known solution,
e.g. F(x) = x2 − 9.
2. Use your Newton code to find all three roots of the cubic:
F(x) = x3 + x2 − 3x − 3
Try various x0, like: 2, 1, 0.5, 0.1, 0.0, −0.5, −1, etc.
Do you notice anything unexpected/interesting? what?
3. Also try some big x0: 100, 1000, −100, etc
Do you notice anything unexpected/interesting? what?
4. Try some other maxIT and TOL.
5. Answer the questions:
Q1: What are the three roots you found ?
How many iterations did each one take ?
with what x0 ?
Q2: Is Newton more efficient than Bisection? how did you decide?
Q3: What is the effect of changing the initial guess x0 ?
Q4: What is the effect of changing maxIT ?
Q5: What is the effect of changing the tolerance ?
6. Now find the real root of "Newton's cubic":
x3 − 2x − 5 = 0
(comment out previous formulas in FCN and insert new ones).
This is the only equation Newton ever bothered to solve with his method, in 1671 !
C. Prepare Lab11 for submission.
In a plain text file Lab11.txt , insert:
1. Name, Date, Lab11
%=====================================%
2. Answers to the questions in B.5
(each labeled and separated by %------------------------%)
%=====================================%
3. What is the (real) root of "Newton's cubic" ?
in how many iterations, with what x0 ?
%=====================================%
4. Insert your Newton.m code.
%=====================================%
5. Insert your FCN.m code.
Using a PLAIN TEXT editor,
edit the file Lab11.txt to clean it up,
leaving only the correct version of
what's asked for in this Lab.
Then submit it on Canvas.