0

I'm trying to find the inverse of the function: $$y=\frac{x^f + 1 - (1-x)^\frac{1}{f}}{2}$$ where $f=10c^3+1$ and $x,y$ and $z$ lie in the interval $[0,1]$

I'm using this for mapping of MIDI note velocities and need to be able to convert back to the original value - but my math is failing me.

The function is basically a curved line from (0,0) -> (1,1) where c controls how much it bends away from the straight line.

See here for background

See here for Desmos Calculator showing how the curve behaves.


Sorry for incorrect previous posting, pretty sure the function is now correct.


Someone asked about the rationale... to be honest I can't remember where I got this function. It's been in my software for 10+ years and works well but now I need the inverse.


Note: this function looks symmetrical about the line $y=1-x$ for the specified x range... but it's definitely not.

Anand
  • 3,588

1 Answers1

0

You are not going to find a simple expression which, when given a value $y=g(x)$, produces $x$ precisely.

That said, it seems that your function $g(x)$ is fairly smooth and well-behaved.

Accordingly, you should be able to solve $g(x)=y$ quite easily by Newton's method. (It is easy enough to differentiate).

If you think that this will be too slow in practice, you can calculate solutions in advance for the 100 values $y=0.00, 0.01,… 1.00$ and make a table of the corresponding $x$ values in your program. You can then look up those values when you need them, or interpolate between them, or even use the looked-up value as a starting point and do one step of Newton's method to refine the result. You do not, after all, need your result accurate to ten decimal places.

My guess, however, is that given what you have said about your function and its intended use, starting with an estimate $x=y$ and doing a fixed number (say, 6) of "Newton steps" from there will give you all the accuracy you could reasonably need.

  • Hi Martin, Thanks for that. Unfortunately my math isn't good enough to really understand this. I've just been through the Wikipedia article for Newtons method and I think I basically understand the concept and I've worked out the derivative of my original function but the code I wrote seems to be improving the approximation towards zero, not the value it should be. Not sure how to get the target value I want into Newtons method. If you've got time, could you provide an example of one step of the method - or a basic reference on how to do this? Thanks again. – Brad Robinson Jul 15 '19 at 12:30
  • Actually, ignore that ... I figured it out. Thanks so much for your help. – Brad Robinson Jul 15 '19 at 12:53