Newton-Raphson algorithm for the root of tanh

In summary, the conversation discusses the N-R (iterative) formula and its use in finding the actual value at which the method will diverge. It is found that for the function tanh, the method diverges at x >~ 1.0886. The speaker presents an approach to determine this value by solving an inequality involving the function sinh and its derivative. However, they are unsure of how to solve the equation accurately, as their math skills are rusty.
  • #1
ognik
643
2
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 don't 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
 
Mathematics news on Phys.org
  • #2
The key here is to notice that the slope just needs to be small enough that the iteration sends $x_{i + 1}$ farther from the root (that is, $0$) than $x_i$. Then because the function is odd and the slope is strictly decreasing, the next iteration will send $x_{i + 2}$ farther from the root than $x_{i + 1}$, and so on, in other words, plain divergence (without oscillation). So your divergence condition on $x_0$ should be:
$$\left \lvert x_0 \right \rvert < \left \lvert x_1 \right \rvert$$
That is:
$$\left \lvert x_0 \right \rvert < \left \lvert x_0 - \frac{f(x_0)}{f'(x_0)} \right \rvert$$
Now since the function is odd we can restrict ourselves to studying $x_0 \geq 0$, and it is easy to see from the graph that we must have $x_1 \leq 0$, hence we can write:
$$x_0 < \frac{f(x_0)}{f'(x_0)} - x_0$$
That is, simplifying and expanding $f$ and its derivative:
$$2x_0 < \cosh{x_0} \sinh{x_0}$$
In other words:
$$2 x_0 < \frac{1}{2} \sinh{2 x_0}$$
So that you want to solve for:
$$u < \frac{1}{2} \sinh{u}$$
Unfortunately expanding the $\sinh$ term into exponential form shows that there is in fact no elementary expression for the solutions of the inequality above, but you can of course evaluate the solutions numerically. Consider the function:
$$g(u) = u - \frac{1}{2} \sinh{u}$$
Plotting it gives:
OcIdnJD.png

Notice there are exactly three roots, which are at $u = 0$ and $u \approx \pm 2.17732$ (these roots can be found by using the Newton-Raphson method on the function $g$, for which it works quite well). Now recall that we have restricted ourselves to $x_0 \geq 0$ for simplicity, hence $u \geq 0$ so we can discard the negative half of the function, so that we are only interested in $g$ taking negative values for all $u > 2.17732$ approximately, for which:
$$u - \frac{1}{2} \sinh{u} < 0 ~ ~ ~ \implies ~ ~ ~ u < \frac{1}{2} \sinh{u}$$
Substituting back into $x_0$, we find:
$$x_0 = \frac{1}{2} u \approx \frac{1}{2} 2.17732 \approx 1.08866$$
And so we conclude that the Newton-Raphson method fails to converge for all starting points $x_0 > 1.08866$ approximately, and by symmetry for all starting points $x_0 < -1.08866$ approximately, since for those $x_0$ we get $0 < \lvert x_0 \rvert < \lvert x_1 \rvert < \lvert x_2 \rvert < \cdots$.

If you can then show that the Newton-Raphson iteration does in fact converge for all $-1.08866 < x_0 < 1.08866$, which can be done anagolously by showing that for such starting values $x_0 \ne 0$ we get $\lvert x_0 \rvert > \lvert x_1 \rvert > \lvert x_2 \rvert \to 0$, then the behaviour of the $\tanh$ function over the reals under the Newton-Raphson iteration will have been fully determined, with one attractor of "radius" 1.08866 roughly near the root and divergence everywhere else.
 
Last edited:
  • #3
Awesome reply, thanks.
But what if I take u < 1/2 sinh(u), divide both side by u, multiply by 2
Then I have 2 < sinh(u)/u

Expanding sinh(x) is x + x^3/3! + x^5/5! + ...
So sinh(u)/u is 1 + u2/3! + u45! + ...
which leaves u23! + u45! + ... > 1

I stopped here because it did not look like I would get U > 1.08866 out of the above, just wondering what was wrong with the above approach?
 
  • #4
ognik said:
Awesome reply, thanks.
But what if I take u < 1/2 sinh(u), divide both side by u, multiply by 2
Then I have 2 < sinh(u)/u

Expanding sinh(x) is x + x^3/3! + x^5/5! + ...
So sinh(u)/u is 1 + u2/3! + u45! + ...
which leaves u23! + u45! + ... > 1

I stopped here because it did not look like I would get U > 1.08866 out of the above, just wondering what was wrong with the above approach?

Nothing wrong, that is perfectly fine, and that indeed gives $u > 2.17732$ (which translates to $x_0 > 1.08866$) (in your last equation you multiplied by the factorials instead of dividing). You would still have to evaluate $2.17732$ numerically, though, I believe there is no simple formula for it (but I could be wrong!). We have that $u = 2.17732$ is the solution of $\sinh(u) / u = 2$.
 
  • #5
Oops - yes, I accidentally left out the '/' when I transcribed from my paper scribblings ...but I find myself in the embarrassing position of not knowing how to go about solving the series properly. All I could do was to consider only the first 2 terms (which I know is not accurate enough) and set v=u2. Then I get v2/5! + v/3! -1 = 0 (I put = in place of > because I know the answer I get will be the value at which divergence starts)
I rewrote that as v2 + 20v - 120 = 0 and used the quadratic equation to find roots of -10 + or - 14.8323, which leaves u = 4.8323 and ultimately x = 1.09913. I'm fairly sure including at least the 3rd term in the series would make it far more accurate, but I have no idea how to solve the equation including that - my maths is somewhat rusty I'm afraid.
 

FAQ: Newton-Raphson algorithm for the root of tanh

What is the Newton-Raphson algorithm for the root of tanh?

The Newton-Raphson algorithm for the root of tanh is a numerical method used to find the roots of the hyperbolic tangent function. It is an iterative process that uses the derivative of the function to approximate the roots.

How does the Newton-Raphson algorithm work?

The algorithm starts with an initial guess for the root and then uses the derivative of the function at that point to calculate a new guess. This process is repeated until the new guess is close enough to the actual root, within a specified tolerance.

What are the advantages of using the Newton-Raphson algorithm for the root of tanh?

The Newton-Raphson algorithm is a very efficient and fast method for finding the roots of a function. It also has a high rate of convergence, meaning it can find accurate roots with fewer iterations compared to other numerical methods.

Are there any limitations to using the Newton-Raphson algorithm for the root of tanh?

Yes, the algorithm can fail to find a root if the initial guess is too far from the actual root or if the function has multiple roots. It also requires the function to be differentiable.

How is the Newton-Raphson algorithm for the root of tanh used in real-life applications?

The Newton-Raphson algorithm has various applications in fields such as engineering, physics, and economics. It is commonly used to solve equations and find roots in optimization problems, such as finding the maximum or minimum value of a function.

Similar threads

Replies
9
Views
2K
Replies
7
Views
2K
Replies
2
Views
886
Replies
21
Views
3K
Replies
20
Views
2K
Replies
2
Views
2K
Back
Top