Question

I am using a function to give me logarithmic scale that I am using in a slider widget. The function came from this blog. I need help reversing this function:

var v = (Math.exp(2.77258872 * x) - 1) / 15;
v *= MAX_WIDTH;

A commenter from that blog has posted this g(f(x)) function, but it does not seem to produce the right result:

var unscaledValue = 2.77258872 * (Math.log(v * 15 /MAX_WIDTH + 1))
Was it helpful?

Solution

v = (Math.exp(2.77258872 * x) - 1) / 15 * MAX_WIDTH
v * 15 / MAX_WIDTH = Math.exp(2.77258872 * x) - 1
v * 15 / MAX_WIDTH + 1 = Math.exp(2.77258872 * x)
Math.log(v * 15 / MAX_WIDTH + 1) = 2.77258872 * x
x = Math.log(v * 15 / MAX_WIDTH + 1) / 2.77258872

OTHER TIPS

Just go back and do the algebra:

v = MAX_WIDTH* ((Math.exp(2.77258872 * x) - 1 ) /15)
v/MAX_WIDTH = (Math.exp(2.77258872 * x) - 1 ) /15)
15*(v/MAX_WIDTH) = Math.exp(2.77258872 * x) - 1
15*(v/MAX_WIDTH) +1 = Math.exp(2.77258872 *x)

log(15*(v/MAX_WIDTH)+1) = 2.77258872*x
(log(15*v/MAX_WIDTH)+1)/2.77258872) = x

Looks like you multiplied when you should have divided.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top