I want to determine the roots for $x\cos x=\ln x$ in the interval $(0,1.6)$ with an error less than $0.02$ using the bisection method but got stuck and hoping for help to understand how I should proceed from here:
I started with rewriting $x\cos x=\ln x$ to $\dfrac{x\cos x}{\ln x}=0$ and then started applying the bisection method where $a_k=0$, $b_k=1.6$ and $c=\dfrac{a_{k-1}+b_{k-1}}{2}$:
\begin{array}{|c|c|c|c|}\hline a & b & c & f(c) \\ \hline 0 & 1.6 & 0.8 & <0 \\ \hline 0.8 & 1.6 & 1.2 & >0 \\ \hline 0.8 & 1.2 & 1 & \text{und.} \\ \hline \end{array}
But as you can see $f(1)$ is undefined for $f(x)=\dfrac{x\cos x}{\ln x}$, how should one proceed from here?
@kabin, I have solved this problem below for reference.
As noted in the comments, this equation should be written as $f(x) = x\ cos(x) - ln(x)$ to use the bisection method. The iterations should look something like this (I have used different notation):
$$ \begin{array}{c|cccc} \text{Iteration} & x_0 & x_1 & x_{new} & f(x_{new}) \\ \hline 1 & 0 & 1.6 & 0.8 & 0.7805 \\ 2 & 0.8 & 1.6 & 1.2 & 0.2525 \\ 3 & 1.2 & 1.6 & 1.4 & -0.0985\\ 4 & 1.2 & 1.4 & 1.3 & 0.0853\\ 5 & 1.3 & 1.4 & 1.35 & -0.0044\\ 6 & 1.3 & 1.35 & 1.325 & 0.0409\\ 7 & 1.325 & 1.35 & 1.3375 & 0.0184 \end{array} $$
The convergence criterion for this method is commonly defined as: $$\epsilon = |\frac{x_{new,i} - x_{new,i - 1}}{x_{new,i}}|$$ By this criterion, the method converges below $\epsilon = 0.02$ in six iterations, since:
$$\epsilon = |\frac{1.325 - 1.35}{1.325}| \approx 0.0188 <0.02 $$
However, if the length of the interval over which the root might possibly lie is used to define the tolerance (the bracket), then the method converges in seven iterations, since: $ |1.3375 - 1.35| = 0.0125 < 0.02$. (1.3375 and 1.35 would be used for the next estimate, and hence are the interval over which the root might possibly lie at that point).
Using the bisection method with a tolerance of $1*10^{-15}$ yields $1.347579862023331$. Measured by the difference from the actual root, the method achieves an error less than 0.02 from the root in five iterations. This is not used as the stopping criterion because knowledge of the true root is not assumed.
Second approach: Newton's Method
Newton's method can also be used for this problem by differentiating:
$$f^{\prime}(x) = cos(x) - x\ sin(x) - \frac{1}{x}$$
The derivative is then used in this iterative expression:
$$x_{i + 1} = x_i - \frac{f(x_i)}{f^{\prime}(x_i)} $$
With an initial root estimate of 0.1, Newton's method also converges to 1.347579862023331 for a tolerance of $1*10^{-15}$. Plugging the root back into the original equation yields:
$$(1.347579862023331)\ cos(1.347579862023331) - ln(1.347579862023331) \approx 7.77*10^{-16}$$
This calculation shows that the result achieves the associated tolerance.
Reference:
Chapra and Canale (2015). Numerical Methods for Engineers. Seventh Edition. Pages 127-131.