1

I am trying to find the root of $f(x)=ln(x)-cos(x)$ by writing an algorithm for bisection and fixed-point iteration method. I am currently using python but whenever I'm running it using either of the two methods, it prints out "math domain error". I guess this is due to ln(x) when x becomes 0 or negative.

So, I asked myself if this manipulation is valid:

If $f(x)=ln(x)-cos(x)=0$, then $ln(x)=cos(x)$. It also follows that $x=e^{cos(x)}$ so we have a function, say $h(x)=x-e^{cos(x)}$, that has same root with $f(x)$. So, I tried using $h$ to find the root of $f$ and I resolved the error prompt I am getting whenever I use $f$ in my code. This is for bisection method, and I got the root that I want to get.

I still don't know what is the appropriate $g(x)$ should I take for fixed-point iteration method such that if $f(x)=0$, then $x=g(x)$ and $g'(x)<1$ for some open interval.

First question: Is using an alternative function $h$ to solve for the actual root of $f$ valid?

Last question: What could be a possible $g(x)$ to use to find the root using fixed-point iteration method?

Any help would be appreciated.

mathnewbie
  • 13
  • 4
  • 1
    What you did is completely valid in case of $\ln x$ as it's a bijective function. – Vasili Mar 29 '22 at 16:46
  • If you start with an interval $[a,b]$, with $f(a)<0$ and $f(b)>0$ the bissection method will work in your case, unless you choose $a$ very close to $0$. – José C Ferreira Mar 29 '22 at 17:01
  • After a few iterations with the bisection method, Newton's method can be used to solve the equation $f(x)=0$. Unless you've chosen a very large interval in the bisection method, and you'll need more iterations there. – José C Ferreira Mar 29 '22 at 17:07
  • @mathnewbie - look at part b: https://www.chegg.com/homework-help/questions-and-answers/1-root-equation-f-x-ln-x-cos-x-e-lies-xe-1-2--calculate-root-using-bisection-method-false--q45518772 – Moo Mar 29 '22 at 18:53

2 Answers2

1

You don't need to change the function $f(x)$. Choose $a=0.1$ and $b=e$ and you will find that $f(a)<0$ and $f(b)>0$. The bisection method will work.

If you do some iterations in the bisection method, you'll find an approximation to the root, say $c$.

Use this $c$ as initial guess to the Newton's method , as fixed point method given by $x=x-f(x)/f'(x)$.

Here is a link to my code in R.

You can find many results by searching for "\(x=x-f(x)/f'(x)\)" on SearchOnMath.

0

$g′(x)<1$ for some open interval

What you need is the stronger $|g′(x)|<1$ for some interval containing the zero $x_0$ of $f$.

Your choice $g(x) = e^{\cos x}$ has derivative $g'(x) = -e^{\cos x}\sin x$. But with $x_0\approx 1.303$ that evaluates to $g'(x_0)\approx -1.26$. Hence $g$ will not work.

First question: Is using an alternative function $h$ to solve for the actual root of $f$ valid?

Yes, you can do that. The question is for which purpose you are doing it...

One annoyance with $f$ and fixed-point methods can be that you come to a halt without a result whenever $x<0$ because $\ln x$ is not defined there. However, using $h$ instead has the issue that whenever $x<0$, the iteration will trickle to $-\infty$ an not produce a result, either.

Last question: What could be a possible $g(x)$ to use to find the root using fixed-point iteration method?

As $x=g(x)=e^{\cos x}$ does not work, you can try splits like $$x=\alpha x + (1-\alpha)x = g(x)$$ and from there $$ x = \frac1\alpha \big(g(x)-(1-\alpha)x\big)=g_\alpha(x)$$ for some constant $\alpha$, and then try to find some $\alpha$ such that $$|g'_\alpha(x_0)| < 1$$

emacs drives me nuts
  • 10,390
  • 2
  • 12
  • 31