2.5 Computing Common Logarithms
For common logs, we can write any number in scientific notation and compute its logarithm by breaking it into two parts. Suppose \(x\) is written in scientific notation as \(x = a \times 10^n\) where \(1\le a < 10\) and \(n\) is an integer. Then
\[ x = a/10 \times 10^{n+1} \]
and
\[ \ln x = \ln(a/10) + (n+1)\; \ln 10 \]
from which
\[ \log x = \frac{\ln x}{\ln 10} = \frac{\ln (a/10)}{\ln 10} + n+1 . \]
Since \(a\) was defined to be between 1 and 10, then \(a/10\) is between 0.1 and 1 and we can use our power series expansion for \(\ln(x)\) in our calculations. Notice that \(\ln(a/10)\) necessarily will be negative in this instance. We are now in a position to create a function to compute common logarithms for general numbers. Here is an example computer code to do just that, re-using our previous function for computing natural logarithms:
logCom = function(x){ # ex: x = 2.827
Num = strsplit(format(x, scientific=T),"e")[[1]] # split input into two strings: Num = c(".827","2")
a = as.numeric(Num[1]) # take the 2 parts and make them numeric: a = 0.827,
n = as.integer(Num[2]) # n = 2
lnX(a/10)/ln10 + n + 1 # i.e., use our formula...
}
Below are a few examples, using our new function, of the calculation of various common logarithms:
log 0.718 = -0.14388 | log 1.25 = 0.09691 | log 2 = 0.30103 |
log e = 0.43429 | log 10 = 1 | log 42.5 = 1.62839 |
log 200 = 2.30103 | log 1050 = 3.02119 | log 3.4\(\times 10^5\) = 5.53148 |