I would like to write a function that has a loop in it which preforms the operations necessary for Muller’s method.
f[x_] := x^3 - x - 1;
x0 = 0.8
x1 = 1.5
x2 = 2.0
x3 = 5.0;
\[Epsilon] = 0.001;
While[(Abs[f[x3]] >= \[Epsilon]),
h0 = x1 - x0;
h1 = x2 - x1;
d0 = (f[x1] - f[x0])/h0;
d1 = (f[x2] - f[x1])/h1;
A = (d1 - d0)/(h1 + h0);
B = A*h1 + d1;
Cx = f[x2];
raiz = Sqrt[B^2 - 4.0*A*Cx];
If[Abs[B + raiz] > Abs[B - raiz], dens = B + raiz, dens = B - raiz];
x3 = (x2 - 2*Cx)/dens;
i++;
Print["Iteration: ", i, "\t root \[TildeTilde] ", x3];
x0 = x1;
x1 = x2;
x2 = x3;
]
But I get infinit loop…
Muller’s method following Eric (Always better than Wikipedia):
Thanks to Heike for pointing out a few errors in the comment below