Pages

Showing posts with label Logarithms. Show all posts
Showing posts with label Logarithms. Show all posts

Tuesday, April 26, 2011

Hand Calculation of Fractional Decimal Exponents

You have probably looked at numbers like this one: 30.7 and wondered how one actually calculates a number like that. We understand exponents as meaning multiplication of the number by itself exponent times. Thus 32 means 3 x 3. But how do you render that when the exponent is a fraction? Suppose that it was 30.2?

This is not a practical question. Any decent spreadsheet or scientific calculator (Excel or TI-36X in my case) can produce the number in the flash of an eye. But sometimes we wonder how it is really done. This question started to irritate me a while back. In the process I discovered that I shared this irritation with lots of other people. And if they go on the Internet, they will not, repeat, will not, get a satisfactory answer. The answers that are on offer are trivial. They never address questions like the above—three to the power of 0.7. At best you will be told to use log functions or log tables. And that works. But I got to wondering how log tables were calculated. That turned out to be a bit of a nightmare presented here a while back.

Since then I’ve discovered that there are no straight-forward ways to solve that puzzle above except by methods just as complicated as finding the log of a number by hand. When the exponent is an integer value, the process is serial multiplication. To be sure, if the exponent is big, you’ll be at it for a while, e.g. 3139. It turns out that if the exponent is a fraction, the process is serial root pulling. And if a whole number and an fractional power are both present, e.g. 32.7, you have to engage in both operations. First 3^2=9 (by multiplication), then 3^0.7 (by root pulling), equal to 2.15766928, and the last action required is to multiply those two numbers (9 x 2.15766928) in order to get the answer, 19.419.

I went through a dog-in-a-junk-yard process of finding an algorithm that did not itself involve doing anything beyond multiplication, division, and pulling square roots. No powers or exponential functions, no logarithms, common or natural. Finally I hit on the idea of using the very same method the eighteenth century Euler used to find logarithms—to solve for the value of a number raised to a fractional decimal exponent.

I will explain the method here. I first did it using Excel, as before. Next (the process is mind-numbingly slow), I automated it using a Visual Basic program. Both are in an Excel spreadsheet that you can download here.  If you have problems, e-mail me. You can find my e-mail in the About tab. The spreadsheet also has the Visual Basic program embedded within it, accessible by Alt-F11; it also handles negative fractional exponents.

Here is how the process works. And for my example I am using 30.7.

It occurred to me that every number to the power of 1 is that number itself, thus 31 = 3. At the same time one to the zeroeth power (10) is also always 1. This gave me the anchorage for applying Euler’s method—two values that, as it were, bound any fractional decimal. 0.7 is greater than 0, the exponent of 1 and is less than 1, the exponent of any whole number to be raised.

Therefore I started with three numbers. The first is 1. The second is the number to be raised. Third is the decimal fraction to which I want to raise the second.

I arranged the first two as follows:

Col ACol B
NumbersPowers
10
31

I wished to raise 3 to the power of 0.7. (30.7) 0.7 then became my target in Column B — and the value corresponding to it in Column A would then become my answer.

The first two, and their powers, are knowns. Their powers are obtained without any calculation. The number and the target are supplied by the user, in this case me.

The procedure is as follows:

In Col A we multiply 1 * 3 and take the square root of the result (=1.7320508). The formula is SQRT(1*3).

In Col B, we add 0 and 1 and then divide by 2 (0.5). The formula is (0 + 1)/2

The results are entered as the next item in each column:

10
31
1.73205080.5

Our target is 0.7. In the next step, we look in Column B for one value that is higher than the target and one that is lower— and then repeat the process. In this case the next step is to obtain the square root of (3 * 1.7320508) and to divide (1 + 0.5) by 2. The results are shown below. Needless to say, if our last value is the target, we don’t have to go on.

10
31
1.73205080.5
2.2795051 0.75

Once more we find the two values that bracket our target most closely (0.5 is lower, 0.75 is higher) and once more undergo the process.

What we are looking for is 0.7 in column B. When it appears, we’re done—and our answer is in Column A.

This process is automated as a computer algorithm in the spreadsheet I offer for downloading. The program is set to run maximally 35 iterations. It may cycle fewer times if the exponent in Column B matches our target to 10 decimal points. In the case shown above, the answer after 35 cycles is:

10
31
1.73205080.5
2.2795051 0.75
. . .
2.1576692790.6999999997

My TI-36X Scientific Calculator produces 2.15766928; so does Excel. Both round one decimal earlier.

Now it turns out, of course, that in “real life,” meaning life before electronic calculators, finding square roots was an equally painful and slow process of division and multiplication until the right number of digits was found. Which tells me why, in the post-Renaissance period western humanity’s mad nerds (whose characteristics I seem to share) developed all kinds of helpful tables, not least root tables and the logarithms.

Have as much fun as I did!
---------------
Added later: In this later post I describe the process of getting your own square roots by hand as well...

Saturday, April 9, 2011

Calculating the Log of a Number by Hand

I’ve become interested in logarithms—for a reason. Sometimes, like others, I use log scales to show graphics. The reason is that they make it easier to highlight some features of the data. In the process of writing a still unpublished post on that subject, I got to looking deeper at the origins of logarithms. My own penchant is to understand things from the bottom up. Thus I became aware of the fact that one finds very few resources on the Internet that go deeply into ancient things—whereas the easy and superficial is almost over-documented. My initial wonder arose over fractional exponents. Let me get into that first.

We know that the log of numbers of the common (base 10) logarithm are “powers of ten.” The log of 10 is 1; it is not multiplied by anything. It is the base. But 100, which is 10 x 10, is written as 102 and the log of 100 is 2. Log 1,000 is 3, 10,000 is 4, and so on. On multiples of 10, count the zeroes and you know the logarithm of the number. But what about other numbers? If I ask my spreadsheet or calculator for the log of 2, the answer will be 0.30103. Put another way, it means that 2, expressed as a power of 10, is that fraction, and that 10.30103 equals 2. But while the logs of 10 and its multiples make sense, and in every case tell me how often to multiply 10 by itself, how does one handle a fractional log? How do I get from 10.30103 to obtain the answer, 2, without using a logarithmic table? I can’t picture how a number might be multiplied by itself a fractional number of times.

My quest to understand the logs thus began by looking at its originator, John Napier (1550-1617), to see how he came up with those fractions. But it turns out that Napier’s initial logarithm was base 10,000,000—and while tracking his calculations is possible (here is his own account of it)—I was looking at an example of our own now dominant log to the base of 10. In what follows, therefore, I am echoing Leonard Euler (1707-1783), and more specifically a fine article by Ed Sandifer available here the content of which I am here rendering for the amateur. In that process, as I will show, one doesn’t really calculate these logs; one finds them, painstakingly, by pulling roots. First I’ll show a spreadsheet that calculates the log of 2. Next I will explain it.

Euler begins with two numbers the log of which is known from the outset, 1 and 10. The number 2 is between these two. Their logs are 0 and 1. Euler proceeds by multiplying 1 and 10 and pulling the square root. One times 10 is 10, and the square root of that is 3.16228. He performs the identical operation on the logs. Adding logs is to multiply them, therefore 0 + 1 = 1. This he divides by two, equivalent to pulling the square root. The result is 0.5. One can check this result by using a calculator. Sure enough, log(3.16228) is 0.5. The operations are placed under labels: A, B, and this last one, under C. Now, let us understand. He is looking for 2. His first result, 3.16…, is greater than 2. He next multiplies the two values closest to 2 on either side, thus the 1 in A and 3.16.. in C. He multiplies them and pulls the square root again, placing this result (1.77828) into row labeled D. Next he performs the same operation in the log column: 0 + .5 = .5 divided by 2 = .25. And, sure enough, checking that we find that log(1.77828) is .25. So now we’re on our way. Using this method, we proceed to find the two values above to either side of 2 and as close to it as possible. Those two are in rows C and D. Using those we proceed to the next step. I think I’ve gone far enough to make the procedure clear.

When continued, and the illustration documents the steps, we finally get, in row T, the answer we are looking for. We get the number 2 and, in the log column, the value of .301029. The actual number Excel gives me, if I take it out to 20 decimal points (the command typed in the cell is =log(2)) is .30102999566398100000; Excel shortens that to .30103.

Let me here indicate the Excel commands used. In the column labeled Actual, the formula in cell B8 and subsequent cells, references changing as indicated by the comment, is:

=SQRT(B7*B6)

In the column labeled Log, the formula in cell C8 and subsequent cells, references changing, is:

=(C6+C7)/2

The reader might fault me for not pulling my square roots manually. Sorry. I cut myself some slack there. That too is a lengthy process with large numbers, but I do know how to do that.

Finding the first few logs is difficult and time consuming. But later the very nature of the exponents makes the job go faster. Adding logs is multiplication, deducting logs is division. Having the logs of 1, 10, and 2, we can rapidly proceed thus:

• The log of 5 is obtained by dividing 10 by 2, thus 1 - .30103 = .69897.
• The log of 4 is easy too, 2 x 2, thus .3013 + .3013 = .60206.
• The log of 8 is 4 x 2, therefore .30103 + .60206 = .90309.
• The log of 20? No problem. 2 x 10 = .30103 + 1 = 1.30103.
• The log of 40? It is 1.60206.
• And 400? It is 2.60206. Simple, 100 x 4, 2 + .60206.

And so on. Prime numbers divisible only by 1 and themselves require the long process. 3 and 7 require slow calculation. But after that it is easy to calculate the log of 6, 9, 12, 14, 60, 70, 90, and so on. Not that we have to. A thirty dollar calculator or an Excel spreadsheet has them all. But it is valuable to understand things from the ground up.

One learns in this process that the integer portion of a log number always refers to multiples of ten (thus of the base), and the fractional parts to “fractions” of ten. The fractions are obtained by division, obtaining roots, the integers by multiplication.

In this process I also came to understand that logs are a geometrical series; the terms change by the same ratio. In a log base 10, the geometrical progression is represented by 10: 10, 100, 1000, etc. In a log base 2, the progression is by 2: 2, 4, 8, 16. In the first, integer logs will be exact multiples of 10—all other numbers will be or have a fractional component. In a log of base 2, integer logs will be multiples of two. The unchanging ratio is multiplication by the base or division to detect the root of the base.

In arithmetical series, the terms always change by the same amount. In the decimal system that amount is 1 or a fraction of 1. When a geometrical series is used to index an arithmetic series, the advantage is that multiplication and division of the indexed arithmetical series may be replaced by adding or deducting logs. This very much increases the efficiency of manual calculation—which was Napier’s motivation for developing logarithms in a time when mechanical calculators, and never mind lightning speed electronic devices, were still far in the future.

I’ll indulge my fascination with this subject in future posts as well—and perhaps they will help others too.