This is the first time I am using bc. I want to calculate the log (base 10) of a number. How do I this?
相关问题
- Why should we check WIFEXITED after wait in order
- UNIX Bash - Removing double quotes from specific s
- bash delete line condition
- Trying to make a permanent Alias - UNIX
- Generating signed XPI via jpm failed
Invoke
bc
with the-l
option (to enable the math library) like soUse the
l
function which is the natural log. Take the log of the number you are interested in then divide by the natural log of 10.bc does not directly gives the logarithm in other than except or in other ways, using bc, we can calculate only ln(x). So, to get any other base logarithm, it is wise to remember some identities. The basic one is -
Here I am giving you some examples of different base logarithms -
Hope this helps you.
Python can come in handy for this as,
Hope that helps!
Poster specifically requested log 10.
I have bc 1.06.95 on Ubuntu 12.10. "l(x)" in this version of BC is not base 10. It is natural log (base e). This is confirmed here and BC has worked this way since some time:
http://linux.about.com/od/commands/l/blcmdl1_bc.htm
I suspect what you need to make log base 10 work is the BC extension:
http://x-bc.sourceforge.net/extensions_bc.html
Not sure correct way to install this, and got errors trying to post it here.
Dominic-Luc Webb
If you start
bc
with the-l
switch, then there's a functionl()
that calculates the natural log of its argument.(fill in the blank there with your number)
I found tutorials at:
http://unix-simple.blogspot.com/2006/10/unix-basic-calculator.html
and
http://unix-simple.blogspot.com/2006/10/taking-roots-with-unix-basic.html