[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include(/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php) [function.include]: failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 122: include() [function.include]: Failed opening '/home/shoeb/public_html/www.matholympiad.org.bd/forum/includes/phpbb-latex.php' for inclusion (include_path='.:/opt/php53/lib/php')
[phpBB Debug] PHP Warning: in file [ROOT]/includes/session.php on line 1042: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4786: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4788: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4789: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4790: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3887)
BdMO Online Forum • View topic - Calculate ln(x) without math.h

Calculate ln(x) without math.h

Discuss Computer Science and Programming related problems

Moderators: bristy1588, Labib

Facebook Twitter

Calculate ln(x) without math.h

Post Number:#1  Unread postby rakeen » Fri Nov 16, 2012 10:16 am

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€€/|/
User avatar
rakeen
 
Posts: 384
Joined: Thu Dec 09, 2010 5:21 pm
Location: Dhaka

Re: Calculate ln(x) without math.h

Post Number:#2  Unread postby Corei13 » Sat Nov 17, 2012 7:35 pm

Use Maclaurin Series of ln(x).
ধনঞ্জয় বিশ্বাস
Corei13
 
Posts: 153
Joined: Tue Dec 07, 2010 9:10 pm
Location: Chittagong

Re: Calculate ln(x) without math.h

Post Number:#3  Unread postby rakeen » Sun Nov 18, 2012 12:09 pm

You can't plug 3 or 4 or 5 in the series since the series is for $-1<x<=1$ only
r@k€€/|/
User avatar
rakeen
 
Posts: 384
Joined: Thu Dec 09, 2010 5:21 pm
Location: Dhaka

Re: Calculate ln(x) without math.h

Post Number:#4  Unread postby Corei13 » Sun Nov 18, 2012 3:40 pm

Then write a function exp(x) to calculate (e^x) and use binary search.
ধনঞ্জয় বিশ্বাস
Corei13
 
Posts: 153
Joined: Tue Dec 07, 2010 9:10 pm
Location: Chittagong

Re: Calculate ln(x) without math.h

Post Number:#5  Unread postby *Mahi* » Sun Nov 18, 2012 8:43 pm

rakeen wrote:You can't plug 3 or 4 or 5 in the series since the series is for $-1<x<=1$ only


For $|x|>1$ determine $ln( \frac 1 x)$ and then multiply it by $-1$.
Please read Forum Guide and Rules before you post.

Use $L^AT_EX$, It makes our work a lot easier!

Nur Muhammad Shafiullah | Mahi
User avatar
*Mahi*
 
Posts: 1175
Joined: Wed Dec 29, 2010 12:46 pm
Location: 23.786228,90.354974

Re: Calculate ln(x) without math.h

Post Number:#6  Unread postby rakeen » Sun Nov 18, 2012 10:02 pm

Then write a function exp(x) to calculate (e^x) and use binary search.

you mean... if logx=p then $e^p=x$. then trial and error?!

However mahi's method worked :)
r@k€€/|/
User avatar
rakeen
 
Posts: 384
Joined: Thu Dec 09, 2010 5:21 pm
Location: Dhaka

Re: Calculate ln(x) without math.h

Post Number:#7  Unread postby *Mahi* » Sun Nov 18, 2012 10:14 pm

rakeen wrote:you mean... if logx=p then $e^p=x$. then trial and error?!

However mahi's method worked :)


Yeah, the only difference is, binary seacrh is quite smart "trial and error" for strictly increasing functions like $\ln (x)$
Please read Forum Guide and Rules before you post.

Use $L^AT_EX$, It makes our work a lot easier!

Nur Muhammad Shafiullah | Mahi
User avatar
*Mahi*
 
Posts: 1175
Joined: Wed Dec 29, 2010 12:46 pm
Location: 23.786228,90.354974

Re: Calculate ln(x) without math.h

Post Number:#8  Unread postby Masum » Wed Jan 09, 2013 1:46 am

rakeen wrote:
Then write a function exp(x) to calculate (e^x) and use binary search.

you mean... if logx=p then $e^p=x$. then trial and error?!

However mahi's method worked :)

এইটা ঠিক ট্রায়াল এরর না। Newton-Raphson's Method.
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$.
User avatar
Masum
 
Posts: 592
Joined: Tue Dec 07, 2010 1:12 pm
Location: Dhaka,Bangladesh


Share with your friends: Facebook Twitter

  • Similar topics
    Replies
    Views
    Author

Return to Computer Science

Who is online

Users browsing this forum: No registered users and 1 guest