1

Lets say that I have a linear scale [100-1000] and I want to map it to a [10-200] scale on a logarithmic basis.

100 becomes 10
1000 becomes 200
450 however becomes lower than 95 since the new scale is logarithmic.

I need a formula that if given the min/max of both scales, it takes any number within the linear scale and returns the logarithmic scale equivalent.

I tried to use the formula suggested in this question but when using the numbers provided by the author as a test, I get 0.97 as a result instead of 1.02 which is apparently the correct one.

Meteor
  • 55
  • 1
  • 6

2 Answers2

0

Logarithmic scale is represented by equation

Y = a + b * log(X)

for some convenient logarithm base (decimal or natural)

Make equation for two border points (I use log10):

a + b * log10(100) = a + b * 2 = 10
a + b * log10(1000) = a + b * 3 = 200
b = 190
a = 10 - 380 = -370

so formula is

Y = -370 + 190 * log10(X)
for X=450 Y=134
MBo
  • 77,366
  • 5
  • 53
  • 86
  • I think you solved the reverse problem given that according to the author _"450 however becomes **lower** than 95 since the new scale is logarithmic."_. Your 134 is clearly more than 95. – SergGr Jan 10 '19 at 15:47
  • @SergGr I believe that **logarithmic scale** maps 10-100-1000-10000 to equal-spaced values like 1,2,3,4, and here geometric mean value 316.2 maps to middle 105. Perhaps you are right, and author really wants **exponential scale** – MBo Jan 10 '19 at 16:02
0

Meteor I believe that the formula in the referenced answer is correct but it's application to case x=5 is wrong. 1.02 clearly can't be a valid mapping of 5 because 5 is slightly before the middle in the [0.1; 10] range (the middle is 5.05) and 1.02 is slightly above the middle of the logarithmic range [0.1; 10] (the middle is 1.0). This is probably due to the rounding errors by @DietrichEpp

Also I think that the formula he uses is a bit more prone to rounding errors. Particularly I think that starting from

y = a' * exp(b*(x-x1))

will produce a better formula. In such case a' is clearly y1.

b is still calculated the same way as

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

The main difference is that in this formula a' = a*exp(b*x1) (where a is the a in @DietrichEpp's answer). If x1 is anything big, this reduces a lot of rounding errors.

For your particular case using e (2.71828...) as the base for logarithm and exponent I get b = 0,00332859141506 and a' = 10

SergGr
  • 23,570
  • 2
  • 30
  • 51