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.