0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ I wouldn't expect this function to have an inverse that can be expressed with elementary functions. This is just a hunch, though. $\endgroup$ – 5xum Jul 15 at 7:00
  • 1
    $\begingroup$ I think when $0<c<1$, the function does not have a unique inverse function, because it's not monotonous. $\endgroup$ – Matti P. Jul 15 at 7:04
  • $\begingroup$ desmos.com/calculator/cnhvp4u9jh $\endgroup$ – Matti P. Jul 15 at 7:05
  • $\begingroup$ There is no closed-form expression, as the equation can be put in the form of a polynomial for rational $c$. $\endgroup$ – Yves Daoust Jul 15 at 7:12
  • $\begingroup$ This function looks fairly empirical. What's the rationale ? $\endgroup$ – Yves Daoust Jul 15 at 7:15
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Brad Robinson Jul 15 at 12:30
  • $\begingroup$ Actually, ignore that ... I figured it out. Thanks so much for your help. $\endgroup$ – Brad Robinson Jul 15 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.