Newton法

与えられた関数 f(x) が（実数）解を持つとき、 (Subscript[x, 0]) を f(x)=0 の最初の近似解とすれば、((Subscript[x, 0,])f((Subscript[x, 0]))での接線方程式は次を満たす：
      y - f((Subscript[x, n])) = f'((Subscript[x, n]))((Subscript[x, n+1])-(Subscript[x, n])).
(Subscript[x, n+1])= (Subscript[x, n]) - ((f((Subscript[x, n])))/(f'((Subscript[x, n]))))
f[x]のMathematica微分 f'[x] または Derivative[1][f][x].

FindRoot[x^(1/3) == 0, {x, 0.1}]

FindRoot[x^2-3 == 0, {x, 1.0}]

newtonSqrt3[x_] := N[1/2  (x + 3/x)];

NestList[newtonSqrt3, 1.0, 6]

FixedPointList[newtonSqrt3, 1.0]

g[x_] := x^2 -3;

Newtonian[f_,x_] := N[x - f[x]/D[f[x],x]]

h[x_]=Newtonian[g,x]

NestList[h, 1.0, 6]

NextValue[f_,x_] := N[x - f[x]/f'[x]]

NextValue[g, 1.0]

y=2.0;

Do[y= NextValue[g,y]; Print[y], {i, 1, 10}]

g[x_] := x  Sin[x]

y=1.0;

Do[y= NextValue[g,y]; Print[y], {i, 1, 10}]

findRoot0[func_,init_, eps_:0.00001] := Module[ {y = init},
While[Abs[func[y]] > eps,
y = N[y - func[y]/func'[y]]
];
 y
]

g[x_] := x^2 - 50;

findRoot0[g,50.0]

findRoot1[func_,init_, eps_:0.00001] := Module[
 {y = init, count = 0},
 While[Abs[func[y]] > eps,
count += 1;
 y = N[y - func[y]/func'[y]]
 ];
{y,count}
]

findRoot1[g,50.0]

findRoot[func_,init_, eps_:0.00001] := Module[
{y = init, count = 0, fy = func[init]},
  While[Abs[fy] > eps,
count += 1;
y = N[y - fy/func'[y]];
fy = func[y]
];
{y,count}
]

findRoot[g,50.0]

g[x_] := x^(1/3)

findRoot[g,0.1]