Newton-Raphson algorithm for the root of tanh

ognik

New member
Joined
Feb 3, 2015
Messages
4
The N-R (iterative) formula is: xi+1=xi - f(xi) / f'(xi). A textbook exercise states that the N-R method does not converge for an initial guess of x >~ 1.
I wrote the required program for tanh and found the method diverges at x >~ 1.0886. But I dont understand why it is this value - the N-R formula divides by f'(xi) (which is the slope of f(xi)) - so I thought where that slope/derivative approached zero would cause diverging, but with tanh that seems to happen closer to 2 than to 1.0886?

Second question is - how would I use the N-R formula itself to work out the actual value at which it will diverge? I tried differentiating the whole N-R explicit equation and got 1-sinh(x) which didn't tell me much.

Intuitions and hints much appreciated :)
 
The derivative of tanh turns 0 when seed value goes beyond 1.0886 as you state

Here using a seed value of 1.08868, resultant derivative is 0 at x=4174.1905882250585 causing division by zero in NR method

Code:
<html>
<body>
<script>

alert(nr(1.08868));

function nr(guess)
{
var i;
var x,x0,f,f_prime,eb;

x0 = guess;
eb = 0.000001;

for (i=1;i<100;i++)
{

    f = Math.tanh(x0);
    f_prime = 1/Math.pow(Math.cosh(x0),2);

    if (f_prime == 0)
        return "Diverged at " + x0 + " where f'(" + x0 + ")= " + f_prime ;

    x = x0 - f / f_prime;

    if (Math.abs(x-x0) < eb)
        return x;
    
    x0 = x;

}

return "Could find root after 100 iterations";
}
</script>
</body>
</html>
 
The N-R (iterative) formula is: xi+1=xi - f(xi) / f'(xi). A textbook exercise states that the N-R method does not converge for an initial guess of x >~ 1.
I wrote the required program for tanh and found the method diverges at x >~ 1.0886. But I dont understand why it is this value - the N-R formula divides by f'(xi) (which is the slope of f(xi)) - so I thought where that slope/derivative approached zero would cause diverging, but with tanh that seems to happen closer to 2 than to 1.0886?

Second question is - how would I use the N-R formula itself to work out the actual value at which it will diverge? I tried differentiating the whole N-R explicit equation and got 1-sinh(x) which didn't tell me much.

Intuitions and hints much appreciated :smile:
If
f(x) = tanh(x)
then
f'(x)= 1 - f2(x) = sech2(x)
Let
g(x) = f(x)/f'(x)
and suppose
2x0 = g(x0)
Then, since f(x) is an odd function and f'(x) is even, i.e. f(-x) = -f(x) and f'(-x)=f'(x), we have g(-x) = - g(x). Now look at
x1 = x0 - g(x0) = x0 - 2 x0 = -x0
x2 = x1 - g(x1) = -x0 - g(-x0)= -x0 + g(x0)= -x0 + 2 x0 = x0
So the N-R doesn't converge for an initial guess of x0.

Suppose we have an initial, say x1, guess greater than x0. Since g(x) [EDIT: g(x) - 2x I mean] is a strictly increasing function for x greater than x0, we have
g(x) > 2 x if x > x0
Work it out: That implies x2 < -x1; x1 < -x2 < x3, etc. That is, N-R diverges.

BTW: 2x0 = g(x0) for x0 ~ 1.088626
 
Last edited:
Top