Newton Quadratic

Andy Long
2/23/2017 -- and my cherry tree is blooming....

The Newton Quadratic method is a take-off on Newton’s method.

Clear[f,x0,eps,nits];

This is the algorithm:

NewtonsQuadratic[f_,a0_,eps_,nits_] :=
Module[
{a=N[a0], (* Use a local variable (so as not to alter passed arguments) *)
fa = f[N[a0]],
fp = f'[N[a0]],
fpp = f''[N[a0]],
i=0,
output (* Let's collect the output, since we've gone to the trouble of computing it. *)
},
output={{i,a,fa}}; 
While[Abs[fa] > eps && i<nits,
a = a-((fp-Sign[fp]*Sqrt[fp*fp-2*fa*fpp])/fpp); (* a variation on Joey's idea...*)
fa=f[a];
fp = f'[a];
fpp = f''[a];
i=i+1;
output=Append[output,{i,a,fa}];  (* once again, collect output. *)
]; 
(* Now let's augment the naive function to include printing some nice formatted output: *)
Print[NumberForm[TableForm[output,
TableHeadings->{None,{"i","(Subscript[x, k])","f[(Subscript[x, k])]"}}],16]]; 
Print["  x  = ",NumberForm[a,16] ]; 
Print["f(x) = ",NumberForm[fa,16] ]; 
Return[Transpose[output]]; (* Now I'll actually return the output, so that it can be plotted, etc. *)
]

Here’s a quadratic example, which is a best-case scenario for the quadratic algorithm:

Does it converge to the proper root? It should be the one closest to the starting value....

f[x_]=(x^2)-2;
Plot[f[x],{x,-2,2}]
x0=8;
eps=10^(-6);
nits=100;
NewtonsQuadratic[f,x0,eps,nits];
NewtonsMethod[f,x0,eps,nits];

Here’s a quadratic example which the quadratic algorithm handles, but Newton’s can’t:

Does it converge to the proper root? It should be the one closest to the starting value....

f[x_]=(x^2)+2;
Plot[f[x],{x,-2,2}]
x0=8;
eps=10^(-6);
nits=100;
NewtonsQuadratic[f,x0,eps,nits];
NewtonsMethod[f,x0,eps,nits];

Let’s try another function

f[x_]=Tan[x-Pi/2];
Plot[f[x],{x,-2,2}]
x0=.2;
eps=10^(-6);
nits=10;
NewtonsQuadratic[f,x0,eps,nits];
NewtonsMethod[f,x0,eps,nits];

As usual, the starting point matters....

Once again, the starting value is very important:

x0=5;
NewtonsQuadratic[f,x0,eps,nits];
NewtonsMethod[f,x0,eps,nits];