Fixed point iteration convergence of $\sin(x)$ in Java

3.2k Views Asked by At

Is it mathematically correct to say that $\sin(x)$ converges to zero as $x$ approaches $0$?

If the $\sin(x)$ iteration is done starting at $\dfrac{\pi}{2}$ in Java, for $10^9$ iterations, the result is $5.4772255370828254\times 10^{-5}$. Even with the range of the integer data type exhausted, the result is not displaying $0$. Does this mean that it won't converge to zero on a computer?

4

There are 4 best solutions below

5
On

$\sin x$ is a function that takes on a unique value depending on what $x \in \mathbb{R}$ you put in.

So, when you say "converges to zero," the natural interpretation would be in terms of a limit.

Indeed, since $\sin x$ is continuous, to evaluate the limit as $x \to 0$, all we need to do is plug in $0$ into $\sin x$ to get $\sin 0 = 0$.


The convergence is very slow since $\frac{\sin x}{x} \to 1$ as $x \to 0$. In other words, $\sin x \approx x$ when $x$ is small, so when you put in $x_{n+1} = \sin(x_n)$, you're going to get a $x_{n+1}$ that's not very different from $x_n$ since $x_{n+1} = \sin(x_n) \approx x_n$.

2
On

The iterative sequence $\{x_k \mid x_0 {=} c,\, k\in\Bbb N^+,\, x_k{=}\sin x_{k-1}\}$ very slowly converges to zero ( $\lim\limits_{n\to\infty} x_n = 0$ ) for any values of $c$ (the seed).

As noted though, the rate of convergence is excruciatingly slow even for a considerably small seed.   You won't notice much progress even after quite numerous iterations.

The convergence is slow because the derivative approaches $1$ near the limit point; $\cos 0 = 1$.   Thus on the close approach towards the limit, minimal change in successive iterations is observed.   $\Delta x_n \to 0$ faster than $x_n\to 0$.

2
On

For small $x$, we have $\sin x\approx x-x^3/6$. So your fixed point iterations are approximately $$\begin{align} x_0 &= \frac\pi2, \\ x_{k+1} &= x_k - \frac{x_k^3}6. \end{align}$$ We may further approximate this discrete process by a differential equation $$\begin{align} x(0) &= \frac\pi2, \\ x'(t) &= -\frac{x(t)^3}6. \end{align}$$ This equation can be solved analytically, giving $$x(t) = \cfrac1{\sqrt{\frac13t+x(0)^{-2}}},$$ which is a function that goes to zero very very slowly (and evidently the initial value $x(0)$ barely matters in the long run). Indeed, plugging in $t=10^9$, our approximation gives $x(10^9)=5.477225572\times 10^{-5}$.

0
On

For small $x$, $\sin(x) \approx x-\frac{x^3}{6} $. Therefore $\frac{\sin(x)}{x} \approx 1-\frac{x^2}{6} $.

Applying this, it can be shown that $\sin^{(n)}(x)$, the $n$-th iterated sine of $x$, satisfies $\sin^{(n)}(x) \approx \sqrt{\frac{3}{n}}$.

One proof, found by doing a Google search for "iterated sine", is shown here.

This explains the slow convergence. If $n = 10^9$, $\sqrt{\frac{3}{n}} =\sqrt{\frac{3}{10^9}} \approx 5.4772255751E-5 $, which agrees very nicely with the OP's calculation.

Note that this does not depend on the initial $x$.