How to use the LOG function
What is the LOG function?
The LOG function calculates the logarithm of a number to a specific base. The log function uses base 10 if a base is not specified.
Table of Contents
1. Introduction
What is a logarithm?
A logarithm is a mathematical operation that tells you how many times you need to multiply a certain number, called the base, by itself to get another number.
For example, if you want to know how many times you need to multiply 2 by itself to get 16: 2x = 16
you can use a logarithm with base 2 and write it as log2(16) which equals 4.
Now we know the exponent: 24 = 16 or 2 * 2 * 2 * 2 = 16
What is a base?
In logarithms, the base is the number that is raised to a power to produce the desired output. It is the foundation of the logarithmic function.
For example, the logarithm log10(100):
- 10 is the base
- 100 is the input number
- 2 is the exponent that makes 10 return 100 because 102 = 100
The most common bases are
- 10
- e (natural log), and
- 2 (for computers).
But any positive number besides 1 can be a base.
What is an exponent?
An exponent is a number that indicates the power or times that a base number is multiplied by itself.
Exponents are written as a small raised number, like x2, y3, or 104. The base number is being multiplied by itself as many times as the exponent value. Exponents are also referred to as "raising to a power".
What is the definition of a logarithm with an arbitrary base?
A logarithm with an arbitrary base b can also be defined using a limit definition, similar to how the natural logarithm is defined:
For a base b > 0, b ≠ 1:
logb(x) = lim (n->infinity) (x^(1/n) - 1) * n / logb(e)
Where:
- b is the base
- x is the input number
- e is the mathematical constant
Here is an example:
b = 3
x = 100
e = 2.718281828
n = large number, here I use 99999999
(100^(1/99999999) - 1) * 99999999/ log3(e) = 4.191806641
=LOG(100,3) returns 4.191806549
What are the other logarithmic functions in Excel?
Excel function | Description |
---|---|
LOG | Returns the logarithm with a given base. |
LN | Returns the natural logarithm (base e) of a number |
LOG10 | Returns the base-10 logarithm of a number |
LOG2 | Returns the base-2 logarithm of a number |
The corresponding inverse functions for the logarithm functions in Excel:
Logarithm | Power to |
---|---|
LOG | Arbitrary base, basex or POWER(number, power) |
LN | EXP(number) |
LOG10 | 10x or POWER(10,x) |
LOG2 | 2x or POWER(2,x) |
2. Syntax
LOG(number, [base])
number | Required. The positive numerical value for which you want the logarithm. |
[base] | Optional. The base of the logarithm. Default value is 10. |
3. Example 1
This example shows how to calculate the logarithms based on a specified value and a given base. The arguments are populated in cell range B3:C6:
- number: B3:B6
- [base]: C3:C6
The first value is 1000 (number) and the base is 10, the function in cell E3 returns 3 which represents the logarithm. This means that 10^3 = 1000.
Formula in cell E3:
The number argument is in cell B3 and the [base] argument is in cell C3.
The second value is 10 which is the number argument and the base is 2, the function in cell E4 returns approx. 3.32 which represents the logarithm. This means that 2^3.32 = 10.
Formula in cell E4:
The number argument is in cell B4 and the [base] argument is in cell C4.
The third value is 9 and the base is 3. The number argument is in cell B5 and the [base] argument is in cell C5.
Formula in cell E5:
The function in cell E5 returns 2 which represents the logarithm. This means that 3^2 = 9.
The fourth value is 100 and the base is 4. The number argument is in cell B6 and the [base] argument is in cell C6.
Formula in cell E6:
The function in cell E6 returns approx. 3.32 which represents the logarithm. This means that 4^3.32 = 100.
4. Example 2
How many hours will it take for a bacteria population to grow from 1,000 cells to 4,000 cells if it triples every hour?
Here are the key parameters:
- Start population: 1,000 cells (This is the initial amount of bacteria cells)
- End population: 4,000 cells (This is the final number of cells)
- Growth: 3x per hour (This constant tells us how fast the bacteria population grows per hour)
Here are the LOG function arguments:
- number: The ratio between the final population and the start population is 4,000/1,000 equals 4 or if we use cell references: C20/C19
- [base]: The growth rate per hour is our base.
Formula in cell E23:
The formula in cell E23 returns 1.26 which represents the number of hours it takes for the bacteria population to grow to 4,000 cells.
The image above shows a chart that displays the population growth across hours, the blue line represents the bacteria population from 0 to 2 hours. The red vertical line shows 1.26 on the x-axis, find the intersection with the blue line. Go with the horizontal line to the y axis on the left side and you will find the value 4,000.
5. Example 3
How many years will it take for an initial investment of 10,000 to reach 37,500 if the interest rate is 5% per year?
Here are the key parameters:
- Present value: 10,000 cells (This is the initial investment)
- End population: 37,500 cells (This is the final number of cells)
- Rate : 5% (The investment accumulates each year by 1 + 0.05 = 1.05)
Here are the LOG function arguments:
- number: The ratio between the investment goal and the initial investment 37,500/10,000 equals 3.75 or if we use cell references: C20/C19
- [base]: The growth rate per year is our base which in this case is 1.05
Formula in cell E23:
The formula in cell E23 returns 27.09 which represents the number of years it takes for the present value to reach 37,500.
The picture shows a graph that illustrates the investment growth across years, the blue line represents the investment amount from 0 to 40 years. The red vertical line shows 27.09 on the x-axis, find the intersection with the blue line. Go with the horizontal red line to the y axis on the left side and you will find the value 37,500.
6. Function not working
The LOG function returns a #VALUE! error if an argument is non-numeric. The function also propagates errors if they are present in the source input values.
6.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
6.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3 converted to hard-coded value using the F9 key. The LOG function requires numerical values which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
6.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Useful links
Logarithm - wikipedia
Euler's Number - UTSA
Functions in 'Math and trigonometry' category
The LOG function function is one of 62 functions in the 'Math and trigonometry' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form