Secant Root Finding Method

secantSteps[λ_, {c0_, c1_, c2_, c3_},{ξ0_,ξ1_}]:=
Module[{poly,pl,x0,x1,xValues},
poly[x_] =  {c0, c1, c2, c3}.x^(Range[0, 3]);
pl = Plot[poly[x], {x, -2, 2},PlotStyle->{Gray}, PlotRange -> {{-2,2},{-6,6}}];
{x0,x1}=Rationalize[{ξ0,ξ1},10^-6];
If[x0==x1,{{x0,x1}},
xValues = NestList[{#[[1]] - poly[#[[1]]](#[[1]]-#[[2]])/(poly[#[[1]]]-poly[#[[2]]]),#[[1]]}&, {x0, x1}, λ ]  // N]//Quiet;
xValues=DeleteCases[xValues,{Indeterminate ,_} | {_,Indeterminate } ];
Show[{pl,
Graphics[{{PointSize[0.01], Point[{#, 0}]& /@ Flatten[xValues]},
{Thickness[0.002], MapIndexed[{Hue[0.76#2[[1]]/λ],Line[{{#[[1]], poly[#[[1]]]},{#[[2]], poly[#[[2]]]}}]}& ,xValues]},{Thickness[0.002], Black,Line[{{#, 0},{#, poly[#]}}& /@ Flatten[xValues]]}
}]
},Axes->True,Frame->True, PlotRange -> {{-2,2},{-4,4}},ImageSize->{500,300}]]

Manipulate[If[x0==x1,x1=x1+.01];
secantSteps[λ , {c0, c1, c2, c3},{x0,x1}],
{{λ,6,"steps"},1,12, 1},{{x0, -1,"(Subscript[x, 0])"}, -2, 2}, {{x1, 1,"(Subscript[x, 1])"}, -2, 2},
{{c0, -0.5, "(Subscript[c, 0])"}, -1, 1},
{{c1,-0.6, "(Subscript[c, 1])"}, -1, 1},
{{c2, 1, "(Subscript[c, 2])"}, -1, 1},
{{c3, 0.7, "(Subscript[c, 3])"}, -1, 1},
ControlPlacement->{Top,Top,Top,Bottom,Bottom,Bottom,Bottom},SaveDefinitions->True]

CAPTION

Steps of the secant root finding method for a cubic polynomial. The secant method for numerical root finding of the functions f consists of the steps (Subscript[x, k+1])=(Subscript[x, k])-f((Subscript[x, k])) ((Subscript[x, k])-(Subscript[x, k-1]))/(f((Subscript[x, k]))-f((Subscript[x, k-1]))), beginning with the two starting values (Subscript[x, 0]) and (Subscript[x, 1]). The method can converge to a root or diverge.

DETAILS

steps — number of steps to be taken

(Subscript[c, k]) — coefficients of the cubic polynomial (∑_(k=0)^3)(Subscript[c, k]) (z^k)

{(Subscript[x, 0]),(Subscript[x, 1])} — starting values

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Secant Root Finding Method" from the Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/SecantRootFindingMethod/

Contributed by: Michael Trott

A full-function Wolfram Mathematica system (Version 6 or higher) is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

© Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »