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))
Était-ce utile?

La 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

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top