# Finding root of $\cos(x)$ by Newton-Raphson method

The exercise asks me that if I want to find the root of $f(x) = \cos(x) = 0$ using Newton-Raphson method, does the initial value matters? I know that Newton-Raphson method is a special case of the fixed point iteration method, therefore, I can use that theorem that says that if the initial guess is inside an interval where $|f'(x)|<1$ then the iteration converges.So if I want the method to converge, I have to pick $x = \{x; x\in \mathbb R, x\ne k\pi, k\in\mathbb Z\}$. Because we must have $|-\sin(x)|<1$.

Am I right?

UPDATE: what's the functon I must use in order to apply the fixed point iteration theorem? Is it $f(x) = \cos(x)$ or $g(x) = x-\frac{\cos(x)}{-\sin(x)}$?

UPDATE 2: in this case, $g'(x) = -\cot²(x) \implies |g'(x)|<1$, so it should converge

• Use the second function. Better call it something else other that $f$. – lhf Nov 3 '15 at 1:47
• Note that there is only one fixed point of $\cos x$, approximately equal to $0.739$, so it's unlikely to be that. – Brian Tung Nov 3 '15 at 2:03
• it is not true that $|g'(x)|<1$ always. – lhf Nov 3 '15 at 2:15
• Who is Raphson? – DanielWainfleet Nov 3 '15 at 4:29
• Note that the $f$ from the fixed-point iteration is not the $f$ from Newton's method. To clarify, if you're after $x$ such that $f(x)=0$, a fixed-point iteration to solve this looks like $x = x + h(x)f(x)$ where $h$ is a "user-choice" function. Users Newton and Raphson chose $h(x)=-f'(x)^{-1}$ because it provides quadratic convergence, i.e., the fastest possible among all choices of $h$. So the "fixed-point iteration" is $x=g(x)$ with $g(x)=x-f'(x)^{-1}f(x)$, provided $f'(x)\neq0$ if $f(x)\neq0$. – Oskar Limka Nov 3 '15 at 11:47

The initial value does matter: for $x_0=1$ the method converges to $\pi/2$ but for $x_0=4$ the method converges to $3\pi/2$. As the theory predicts, for $x_0$ close enough to each root $(2k+1)\pi/2$, the method converges to that root.

The basins of attractions for each root are likely to be complicated fractal sets.

• but if we take $g(x) = \cos(x)-\frac{\cos(x)}{-\sin(x)}$ we'll have that $|f'(x)|$ is always less than zero: wolframalpha.com/input/… – ramata Nov 3 '15 at 2:07
• ops sorry, $g(x) = x - \frac{\cos(x)}{-\sin(x)}$ then $|g'(x)|<1$, here: wolframalpha.com/input/… – ramata Nov 3 '15 at 2:09
• wolfram alpha says that $g'(x) = -\cot²(x)$, but in modulus it is greater than zero always, and sometimes greater than 1, right? – ramata Nov 3 '15 at 2:12

Yes, the initial seed matters quite a lot. If you're "close" to one of the roots, you'll converge to that root. Exactly how close is required is complicated, though.

The image below shows the regions of attraction for the cosine function in a neighborhood of the origin in the complex plane. Initial seeds chosen from green region on the left converge to $-\pi/2$ while initial seeds chosen from yellow region on the right converge to $+\pi/2$. As you move closer to the origin, you can converge to points farther away.

• Thanks for the nice picture illustrating the last remark in my answer. – lhf Nov 3 '15 at 12:03
• Does the picture repeat itself periodically when you zoom out? – lhf Nov 3 '15 at 12:04
• @lhf No, the picture is not exactly periodic. The Julia set itself (the boundary between the colors, of course) is periodic but the colors shift as you move horizontally. That makes perfect sense, of course, as the colors indicate which root we converge to and there's a new attractive fixed point with each horizontal step of length $\pi$. – Mark McClure Nov 3 '15 at 13:12
• yes, thanks, I meant whether the geometry was periodic, not the colors. – lhf Nov 3 '15 at 15:15