I've tried finding the $g(x)$ for the equation $f(x)=x\sin(x)+\cos(x)=0$ by squaring or multiplying, but nothing seems to fulfil the condition of $|g'(x)|<1.$
-
It's unclear, basically, what you want $g(x)$ to be - you haven't told us enough. – Thomas Andrews Apr 26 '19 at 16:57
-
In particular, there are infinitely many $x$ so that $f(x)=c$ for any $c.$ So it is unlikely that you'll find a $g(x)$ which has $|g'(x)|<1$ for all real numbers $x.$ – Thomas Andrews Apr 26 '19 at 17:00
-
The equation is f(x)=x*sin(x)+cos(x)=0 – SAm Apr 26 '19 at 17:16
-
The Newton method is always a good candidate for a rapidly converging fixed-point method. You will however need to identify a basin of attraction for the root. Explore the values of $f$ at $x=k\frac\pi2$. – Lutz Lehmann Apr 26 '19 at 17:16
2 Answers
The goal is to find an approximate root of $$x \sin x + \cos x = 0$$ by fixed-point iteration. An equivalent equation is $$\tan x = - \frac{1}{x} \tag{1}$$ Now we must ask "Which root?" because it becomes evident there are infinitely many roots. Plotting $\tan x$ and $-1/x$, it appears that one root is near $2.8$; so let's assume that is the root we want to find.
At first, we might try taking the inverse tangent of both sides of $(1)$: $$ x = - \tan^{-1} \left( \frac{1}{x} \right) \tag{2}$$ But the range of the principal value of $\tan^{-1} x$ is defined to be $-\pi/2$ to $\pi/2$, which does not include $2.8$, so $(2)$ won't work. Instead, we need the alternative branch of $\tan^{-1} x$ with range from $\pi/2$ to $3 \pi/2$, i.e. the principal value plus $\pi$, yielding $$ x = - \tan^{-1} \left( \frac{1}{x} \right) + \pi \tag{3}$$ If we define $g(x)$ to be the right-hand side of $(3)$,then it turns out $|g'(x)| < 1$ for $x$ near $2.8$, so fixed-point iteration will converge to a root.
- 14,736
-
Thank you very much, it solved the problem. The only thing I'm not quite understanding about why we need to add π – SAm Apr 27 '19 at 16:37
-
@SAm If we want to solve $\tan x = y$ for $x$, there are infinitely many possibilities. The $\tan^{-1} y$ function is defined to return the $x$ for which $-\pi/2 < x < \pi/2$ (the "principal value"), but that is only one possibility. Since $\tan y = \tan (y +n \pi)$ for any integer $n$, The full set of solutions is $\tan^{-1} y + n \pi$ where $n$ can be any integer. In your problem we want a value $x$ in the range $(\pi/2, 3\pi/2)$, so we want to choose $n=1$. – awkward Apr 27 '19 at 19:37
You get the "easy" function values $$f(k\pi)=(-1)^k~~\text{ and }~~f((k+\frac12)\pi))=(-1)^k(k+\frac12)\pi).$$ This means that there is a root between $(k-\frac12)\pi$ and $k\pi$ for every positive integer $k$. You need to show that these are the only roots, for instance by exploring the monotonicity intervals.
$f$ is a symmetric function, so that for every positive root you also get a negative root.
Fix some positive integer $k$ and set $x_k^0=k\pi$. With $A_k=f'(x_k^0)=(-1)^kx_k^0$, the simplified Newton method $$ x_k^{n+1}=g(x_k^n)=x_k^n-A_k^{-1}f(x_k^n) $$ has good chances to converge to the root closest to $x_k^0$ and $x_k^1=x_k^0-\frac1{x_k^0}=k\pi-\frac{1}{k\pi}$.
The numerical experiment
k = np.arange(1,10)
x = k*np.pi
A = x*np.cos(x);
def f(x): return x*np.sin(x)+np.cos(x)
for j in range(6):
print j,x
x = x - f(x)/A
confirms the good behavior.
n x1[n] x2[n] x3[n] x4[n] x5[n] x6[n] x7[n] x8[n] x9[n]
0 [ 3.14159265 6.28318531 9.42477796 12.56637061 15.70796327 18.84955592 21.99114858 25.13274123 28.27433388]
1 [ 2.82328277 6.12403036 9.31867467 12.48679314 15.64430129 18.79650427 21.94567573 25.09295249 28.23896612]
2 [ 2.80221509 6.12135633 9.31788012 12.48645761 15.64412942 18.79640479 21.94561307 25.09291051 28.23893663]
3 [ 2.79899888 6.12125454 9.31786669 12.48645443 15.64412838 18.79640437 21.94561288 25.09291041 28.23893658]
4 [ 2.79848472 6.12125062 9.31786647 12.4864544 15.64412837 18.79640437 21.94561288 25.09291041 28.23893658]
5 [ 2.79840195 6.12125047 9.31786646 12.4864544 15.64412837 18.79640437 21.94561288 25.09291041 28.23893658]
See also Selection of the numerical method for other approaches to a similar problem.
- 126,666
-
Ummm I need to solve it by iteration method. If I can use NR method, I would've solved it by now. The real root lies between -2 and -2.5. – SAm Apr 26 '19 at 17:39
-
The smallest roots lie at about $\pm 2.798$ which corresponds to $k=1$ in the answer with $x_1=\pi-\frac1\pi=2.82328$ a close value. There is no root in $[-2.5,2.5]$, check your function definition that the signs are correct and the trig. functions at the right place. Indeed, $f(x)=x\cos x+\sin x$ has its smallest non-zero root pair at about $\pm2.02876$. – Lutz Lehmann Apr 26 '19 at 17:55
-
@SAm : The Newton-Raphson-Simpson method is an iteration method. The simplified Newton method is one too, both fall in the iteration formula class $$x_{n+1}=g(x_n)=x_n-h(x_n)f(x_n).$$ – Lutz Lehmann Apr 26 '19 at 19:39
-
Dear @Lutzl, I know NR method is an iterative method and I also know that it has an order of convergence 2 and is faster than other methods, But I need to implement a C++ program for Fixed Point Iteration method, it's of examination purpose. I appreciate your help but I've already implemented N-R method's program with this equation. – SAm Apr 27 '19 at 02:50
-
You wrote that you had difficulties to come up with fixed-point iterations for the equation. The stated $g(x)=x-h(x)f(x)$ for arbitrary $h$ is a very large class of them, not necessarily contracting around a root. If you know points close to the root you can take $h$ a constant scalar. This is the main point of the answer. – Lutz Lehmann Apr 27 '19 at 03:43
-
Actually I have difficulties in separating 'x' on the the one side of equation such that it must satisfies the condition for every interval of f(x), |g'(x)|<1. I wrote "Fixed Point Iteration Method" that's an entirely different method. – SAm Apr 27 '19 at 04:16
-
Then you want the other answer which is similar to my answer in the linked post. While you could still bring it into the above form, it would be a rather tortured transformation. – Lutz Lehmann Apr 27 '19 at 04:33
