hey mate,

Newtons method is a powerful tool used to iterate towards the solution of a non-linear equation, however it is not globally convergent and is based on certain attributes that the function itself must satisfy; in this case the strength of your derivative of the function is what is causing your solution to move away from the actual solution,

Thankfully there is a method or strategy to overcome and or dampen the divergence by attempting to force the newton step to be globally convergent which I will attempt to explain,

currently your iterative method would follow the form

x^(n+1) = x^(n) + dx^(n)

where dx(n) = -f(x^(n))/f'(x^(n));

here we alter the current strategy so that a dampening factor is included so that

| dx^(n+1) | < | dx^(n) | --> the solution is converging

Thus,

x^(n+1) = x^(n) + g(damp^(n))*dx^(n)

where damp or dampening factor is bounded between 0 and 1.

The choice of the function g(damp^(n)) is dependant upon the problem, but the simplest is,

g(damp^(n)) = damp^(n)

in terms of its implementation, a general method is at each iteration set damp^(n) = 1 and thus compute the newton step normally, and if the new dx is greater than the older dx, set damp^(n) = (1/2)*damp^(n) and repeat until

|dx new | < |dx old|

Give this strategy a go, and if you have any trouble in its implementation and or what I've stated, please let me know and I will be more than happy to assist further,

Regards,

David