Convert Linear scale to Logarithmic

MathLogarithm

Math Problem Overview


I have a linear scale that ranges form 0.1 to 10 with increments of change at 0.1:
  |----------[]----------|
0.1         5.0         10

However, the output really needs to be:
  |----------[]----------|
0.1         1.0         10 (logarithmic scale)

I'm trying to figure out the formula needed to convert the 5 (for example) to 1.0. Consequently, if the dial was shifted halfway between 1.0 and 10 (real value on linear scale being 7.5), what would the resulting logarithmic value be? Been thinking about this for hours, but I have not worked with this type of math in quite a few years, so I am really lost. I understand the basic concept of log10X = 10y, but that's pretty much it.

The psuedo-value of 5.0 would become 10 (or 101) while the psuedo-value of 10 would be 1010. So how to figure the pseudo-value and resulting logarithmic value of, let's say, the 7.5?

Let me know if addition information is needed.

Thanks for any help provided; this has beaten me.

Math Solutions


Solution 1 - Math

Notation

As is the convention both in mathematics and programming, the "log" function is taken to be base-e. The "exp" function is the exponential function. Remember that these functions are inverses we take the functions as:

> exp : ℝ → ℝ+, and > > log : ℝ+ → ℝ.

Solution

You're just solving a simple equation here:

> y = a exp bx

Solve for a and b passing through the points x=0.1, y=0.1 and x=10, y=10.

Observe that the ratio y1/y2 is given by:

> y1/y2 = (a exp bx1) / (a exp bx2) = exp b(x1-x2)

Which allows you to solve for b

> b = log (y1/y2) / (x1-x2)

The rest is easy.

> b = log (10 / 0.1) / (10 - 0.1) = 20/99 log 10 ≈ 0.46516870565536284 > > a = y1 / exp bx1 ≈ 0.09545484566618341

More About Notation

In your career you will find people who use the convention that the log function uses base e, base 10, and even base 2. This does not mean that anybody is right or wrong. It is simply a notational convention and everybody is free to use the notational convention that they prefer.

The convention in both mathematics and computer programming is to use base e logarithm, and using base e simplifies notation in this case, which is why I chose it. It is not the same as the convention used by calculators such as the one provided by Google and your TI-84, but then again, calculators are for engineers, and engineers use different notation than mathematicians and programmers.

The following programming languages include a base-e log function in the standard library.

In fact, I cannot think of a single programming language where log() is anything other than the base-e logarithm. I'm sure such a programming language exists.

Solution 2 - Math

I realize this answer is six years too late, but it might help someone else.

Given a linear scale whose values range from x0 to x1, and a logarithmic scale whose values range from y0 to y1, the mapping between x and y (in either direction) is given by the relationship shown in equation 1:

 x - x0    log(y) - log(y0)
------- = -----------------      (1)
x1 - x0   log(y1) - log(y0)

where,

x0 < x1
{ x | x0 <= x <= x1 }

y0 < y1
{ y | y0 <= y <= y1 }
y1/y0 != 1   ; i.e., log(y1) - log(y0) != 0
y0, y1, y != 0


EXAMPLE 1

The values on the linear x-axis range from 10 to 12, and the values on the logarithmic y-axis range from 300 to 3000. Given y=1000, what is x?

Rearranging equation 1 to solve for 'x' yields,

                 log(y) - log(y0)
x = (x1 - x0) * ----------------- + x0
                log(y1) - log(y0)

                log(1000) - log(300)
  = (12 - 10) * -------------------- + 10
                log(3000) - log(300)

  ≈ 11


EXAMPLE 2

Given the values in your question, the values on the linear x-axis range from 0.1 to 10, and the values on the logarithmic y-axis range from 0.1 to 10, and the log base is 10. Given x=7.5, what is y?

Rearranging equation 1 to solve for 'y' yields,

          x - x0
log(y) = ------- * (log(y1) - log(y0)) + log(y0)
         x1 - x0

        /  x - x0                                \
y = 10^|  ------- * (log(y1) - log(y0)) + log(y0) |
        \ x1 - x0                                /

        / 7.5 - 0.1                                  \
  = 10^|  --------- * (log(10) - log(0.1)) + log(0.1) |
        \  10 - 0.1                                  /

        / 7.5 - 0.1                    \
  = 10^|  --------- * (1 - (-1)) + (-1) |
        \  10 - 0.1                    /

  ≈ 3.13


:: EDIT (11 Oct 2020) ::

For what it's worth, the number base 'n' can be any real-valued positive number. The examples above use logarithm base 10, but the logarithm base could be 2, 13, e, pi, etc. Here's a spreadsheet I created that performs the calculations for any real-valued positive number base. The "solution" cells are colored yellow and have thick borders. In these figures, I picked at random the logarithm base n=13—i.e., z = log13(y).

Spreadsheet values
Figure 1. Spreadsheet values.

Spreadsheet formulas
Figure 2. Spreadsheet formulas.

Mapping of X and Y values
Figure 3. Mapping of X and Y values.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTurdPileView Question on Stackoverflow
Solution 1 - MathDietrich EppView Answer on Stackoverflow
Solution 2 - MathJim FischerView Answer on Stackoverflow