I have implemented Newton's Method, and I am trying to find the exact value of the zero of a polynomial using Limit
. The dream is that the following code works:
g[x_] := 21 - 3 x - 7 x^2 + x^3;
newtonNextGuess[f_, guess_] := guess - f[guess]/f'[guess];
Limit[Nest[newtonNextGuess[g, #] &, 1, n], n -> Infinity]
But this returns an error:
Nest: Non-negative machine-sized integer expected at position 3 in
Nest[newtonNextGuess[g,#1]&,1,n].
The error persists if I make n
an integer by replacing it with 1+Ceiling@Abs@n
as talked about in this post. So the small question is: why is this error happening? But more importantly, is there way I can get Mathematica to tell me the limit of this sequence? The limit is $\sqrt{3}$, and it would be really nice to get Mathematica to display this explicitly (as opposed to numerically) for a presentation.
Roots[g[x] == 0, x]
? $\endgroup$RootApproximant[]
.RootApproximant@FixedPoint[newtonNextGuess[g, #] &, 1.]
$\endgroup$