Calculate ln(x) without math.h
Moderators:Labib, bristy1588
Write a program which will calculate $ln(x)$. You can't use math.h library. And the code should also be able to find the $ln(x)$ for $x>1$
r@k€€/|/
Re: Calculate ln(x) without math.h
You can't plug 3 or 4 or 5 in the series since the series is for $-1<x<=1$ only
r@k€€/|/
Re: Calculate ln(x) without math.h
Then write a function exp(x) to calculate (e^x) and use binary search.
ধনঞ্জয় বিশ্বাস
Re: Calculate ln(x) without math.h
For $|x|>1$ determine $ln( \frac 1 x)$ and then multiply it by $-1$.rakeen wrote:You can't plug 3 or 4 or 5 in the series since the series is for $-1<x<=1$ only
Please read Forum Guide and Rules before you post.
Use $L^AT_EX$, It makes our work a lot easier!
Nur Muhammad Shafiullah | Mahi
Use $L^AT_EX$, It makes our work a lot easier!
Nur Muhammad Shafiullah | Mahi
Re: Calculate ln(x) without math.h
you mean... if logx=p then $e^p=x$. then trial and error?!Then write a function exp(x) to calculate (e^x) and use binary search.
However mahi's method worked
r@k€€/|/
Re: Calculate ln(x) without math.h
Yeah, the only difference is, binary seacrh is quite smart "trial and error" for strictly increasing functions like $\ln (x)$rakeen wrote:you mean... if logx=p then $e^p=x$. then trial and error?!
However mahi's method worked
Please read Forum Guide and Rules before you post.
Use $L^AT_EX$, It makes our work a lot easier!
Nur Muhammad Shafiullah | Mahi
Use $L^AT_EX$, It makes our work a lot easier!
Nur Muhammad Shafiullah | Mahi
Re: Calculate ln(x) without math.h
এইটা ঠিক ট্রায়াল এরর না। Newton-Raphson's Method.rakeen wrote:you mean... if logx=p then $e^p=x$. then trial and error?!Then write a function exp(x) to calculate (e^x) and use binary search.
However mahi's method worked
If a continuous function $f(x)=0$ has $f(a)<0$ and $f(b)>0$ then $a<x<b$ must hold. So check with the mid value always and see which region it belongs to. If $f(mid)<0$ then of-course $f(x)<0$ for $a<mid$. Therefore, you can set $a=mid$ and vice-versa.
And binary search is the efficient one. Because Maclaurine series may have the convergence rate very slow, also you need to find that again if you don't remember. On the other hand, binary search gives you correct result to $6/7$ digits with at most $500$ loops.
One one thing is neutral in the universe, that is $0$.