This thread stimulated me into playing with a few ideas,
I pieced together this little newton-raphson procedure...
> newton := proc( f, # the function x0 # the initial guess n, # step count limit tol # error tolerance)
local x, g, k;
g := D(f); # the derivative f’(x)
x := evalf(x0); # initialize the iteration
for k from 1 to n do # loop for newton’s iteration
# Newton’s iteration formula
x[k] := evalf( x[k-1] - f(x[k-1])/g(x[k-1]) );
# exit early if possible, with luck
if abs(x[k]-x[k-1]) < tol then
return "Newton’s iteration fails"
If f'(x) at some stage gets very close to or becomes 0 the procedure returns "Newton’s iteration fails". I would like to modify the program some how such that when f'(x[k])x[k]+0.00001 and resumes to normal calculations. Any Ideas where or how I could put in this conditional statement? Or should I use while?
Thank you in advance!