I fixed this up sticking with your basic loop structure as much as possible.
step[f_, inter_] := Module[{x = Mean@First@(List @@ inter)},
IntervalIntersection[inter, x - (f[x])/(f'[inter])]]
newton[f_, inter0_, eps_] := Module[{iter,inter},
inter = inter0;
iter = 0;
While[Abs[Subtract @@ First@(List @@ inter)] > eps,
inter = step[f, inter];
iter++;
Print["loop count",iter,inter,
x = N@Mean@First@(List @@ inter),f[x],f'[inter]]];
Print["Iterations = ", iter];
Print["X1 = ", N@Mean@First@(List @@ inter)];]
f[x_] = x^2 - 8 x + 7 ;
inter = Interval[{5, 10}] ;
newton[f, inter, 0.00001];
result 7.
in 4
iterations
of course in mathematical there are usually cleaner approaches than a do loop:
newton[f_, inter0_, eps_] := Module[{iter = 0},
Print["X1 = ", N@Mean@First@(List @@
NestWhile[(++iter; step[f, #]) &, inter0,
Abs[Subtract @@ First@(List @@ #)] > eps & ])];
Print["iter=", iter]]
Note this only works properly if the sign of the derivative does not change in the initial Interval
. Otherwise you end up with multiple intervals. I'm not that familiar with interval arithmetic to readily see how to deal with that.