I am trying to program Newton's Method in Mathematica to compute the roots of $f(x)=x^3-6x^2+11x-6$ using the Do command but my code gives a General::ivar error and doesn't work and I can't figure out what is wrong with it:
f[x_] := x^3 - 6*x^2 + 11*x - 6
g[x_] := D[f[x], x]
a[0] = 0;
Do[a[n + 1] = a[n] - N[f[a[n]]/g[a[n]]], {n, 0, 100}]
Table[a[n], {n, 0, 100}]
Can you explain what's wrong with it?
g[x_] = D[f[x], x]works, but the reasoning is a bit complicated for a comment. SeeSetvsSetDelayedin the documentation. This also might help with that: https://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/18487#18487 – eyorble Jan 04 '22 at 19:47