Newton's method


 
# Newton's Method 
#  
# An example:
> Digits:=6:\
g := x -> x^3-x-3;
                                         3
                              g := x -> x  - x - 3
 
> plot(g(x),x=-2..2.0);
# define Newton's iteration function and use iterates function
> f := x -> x-g(x)/D(g)(x);
                                              g(x)
                              f := x -> x - -------
                                            D(g)(x)
 
> x[0] := 1.0;
                                   x[0] := 1.0
 
> iterates:= proc(g,p0,nmax)\
   seq((g@@i)(p0), i=0..nmax)\
end;
iterates := proc(g,p0,nmax) seq((g @@ i)(p0),i = 0 .. nmax) end
 
> iterates(f,x[0],5);
                1.0, 2.50000, 1.92958, 1.70787, 1.67256, 1.67170
 
> points := NULL;
                                   points :=
 
# Generate a set of points that represent tangent lines
> for n from 0 to 5 do\
   points := points,[x[n],0],[x[n],g(x[n])]:\
   x[n+1]:=f(x[n]):\
od:
> plot({[points],g(x)},x=-1.0..3.0,style=line);
> f(x);
                                      3
                                     x  - x - 3
                                 x - ----------
                                         2
                                      3 x  - 1
 
> D(g)(x);
                                       2
                                    3 x  - 1
 
 

You may open the Maple application and load the file ~berger/public_html/M471/newton.mws as a worksheet into your Maple application.


Back to Cover Page