Newton Raphson

The Newton Raphson method is fixed point iteration designed so as to make convergence as quick as possible.  Here is the first example.  We will figure the answer to 50 significant figures to illustrate the speed of convergence.

f[x_]=(x^2)-2;
a=1;
b=3;
g[x_]=x-((f[x])/(f'[x]))

Clear[p]
p[0]=3;
Do[p[n]=N[g[p[n-1]],50],{n,1,100}]

TableForm[Table[{n,p[n]},{n,0,10}]]

Here is a nice plot to illustrate what the Newton Raphson method is doing.

ppp=Plot[f[x],{x,a,b}];
ListAnimate[Flatten[Table[{
		Show[ppp,
			Epilog->{Table[Line[{{p[k],0},{p[k],f[p[k]]}}],{k,0,n-1}], 
					                 Table[Line[{{p[k],f[p[k]]},{p[k+1],0}}],{k,0,n-1}]}],
		Show[ppp,
			Epilog->{Table[Line[{{p[k],0},{p[k],f[p[k]]}}],{k,0,n}],
					                 Table[Line[{{p[k],f[p[k]]},{p[k+1],0}}],{k,0,n-1}]}]},
	{n,0,6}]]]

Now lets look at the Secant Method.

Clear[p]
p[0]=3;
p[1]=2;
Do[p[n]=N[p[n-1]-((f[p[n-1]] (p[n-1]-p[n-2]))/(f[p[n-1]]-f[p[n-2]])),50],{n,2,100}]
TableForm[Table[{n,p[n]},{n,0,14}]]

ListAnimate[Flatten[Table[{
		Show[ppp,
				Epilog->{Table[Line[{{p[k],0},{p[k],f[p[k]]}}],{k,0,n-1}],
					                   Table[Line[{{p[k],f[p[k]]},{p[k+2],0}}],{k,0,n-1}]}],
		Show[ppp,
		  	Epilog->{Table[Line[{{p[k],0},{p[k],f[p[k]]}}],{k,0,n}],
					                   Table[Line[{{p[k],f[p[k]]},{p[k+2],0}}],{k,0,n-1}]}]},
	{n,0,6}]]]

Now let us illustrate a situation when the Newton Raphson method does not work so well.

f[x_]=Exp[2 x]-2 Exp[2+x]+Exp[4];
g[x_]=x-((f[x])/(f'[x]));
Clear[p]
p[0]=3;
Do[p[n]=N[g[p[n-1]],50],{n,1,100}]
TableForm[Table[{n,p[n]},{n,0,20}]]

If we want to get rid of the divide by zero errors, try using the Simplify command to simplify some of the expressions:

g[x_]=x-Simplify[((f[x])/(f'[x]))];
p[0]=3;
Do[p[n]=N[g[p[n-1]],50],{n,1,100}]
TableForm[Table[{n,p[n]},{n,0,50}]]

The reason for the slow convergence is that f[x] has a double root at x=2, that is, a root of order 2:

f[2]
f'[2]
Plot[f[x],{x,1,3}]

The method used here is the Modified Newton Raphson Method:

f[x_]=Exp[2 x]-2 Exp[2+x]+Exp[4];
mu[x_]=((f[x])/(f'[x]));
g[x_]=x-((mu[x])/(mu'[x]));
Clear[p]
p[0]=3;
Do[p[n]=N[g[p[n-1]],50],{n,1,100}]
TableForm[Table[{n,p[n]},{n,0,10}]]

If you want to remove the problem caused by the divide by zero, try some simplification of the expressions.  (This won't always work!)

mu[x_]=Simplify[((f[x])/(f'[x]))];
g[x_]=x-Simplify[((mu[x])/(mu'[x]))];
Clear[p]
p[0]=3;
Do[p[n]=N[g[p[n-1]],50],{n,1,100}]
TableForm[Table[{n,p[n]},{n,0,10}]]