请告诉我,在Mathematica中是一个可以找到间隔宽度的标准函数吗? 我必须为每次迭代找到它。
(*Newton's method*)
step[f_, iter_, inter_] :=
Module[{x = Mean@First@(List @@ inter)//N},
Print["Iteration ", iter, ".\n", "Interval is: ", inter,
"; \nx0_=", x, "; \nf(x0_)=", f[x], "; \nf'(interval)=", f'[inter],
";","\nIntervalsWidth=",(*??????????*),"\nX1=",IntervalIntersection[inter, x - (f[x])/(f'[inter])]]; IntervalIntersection[inter, x - (f[x])/(f'[inter])]]
newton[f_, inter0_, eps_] :=
Module[{iter = 0},
N@Mean@First@(List @@
NestWhile[(++iter; step[f, iter, #]) &, inter0,
Abs[Subtract @@ First@(List @@ #)] > eps &])];
f[x_] := x*x - 8*x + 7 ;
inter := Interval[{5, 17}] ;
newton[f, inter, 0.00001];
//////试图做
(*Newton's method*)
step[f_, iter_, {a_, b_}] :=
Module[{inter = Interval[{a, b}],x =(a+b)/2},
Print["Iteration ", iter, ".\n", "Interval is: ", inter,";\nIntervalsWidth=",b-a,
"; \nx0_=", x, "; \nf(x0_)=", f[x], "; \nf'(interval)=", f'[inter],
";","\nX1=",IntervalIntersection[inter, x - (f[x])/(f'[inter])]]; IntervalIntersection[inter, x - (f[x])/(f'[inter])]]
newton[f_, {a_, b_}, eps_] :=
Module[{iter = 0},
N@Mean@First@(List @@
NestWhile[(++iter; step[f, iter, #]) &, {a,b},
Abs[b-a] > eps &])];
f[x_] := x*x - 8*x + 7 ;
newton[f, {5, 17}, 0.00001];