Inverse function -- need help

342 Views Asked by At

I'm a senior software developer but my math lessons are a bit rusty. I know the name of what I want, but not anymore how to compute it ;)

I've found (by myself with Grapher.app) a simple easing function (for transitions), that's a bijection from $[0,1]$ to $[0,1]$:

$$ f(x) = \frac{27}{4} \cdot \left( \left( \frac{2x}3 \right) ^2 - \left( \frac{2x}3 \right) ^3 \right) $$

Edit: in fact, after simplifying, it's as simple as:

$$ f(x) = 3 x^2 - 2 x^3 $$

The derivatives at $0$ and $1$ are both zero, so it's a perfect ease-in-out function that's easy to compute.

In order to start my transitions from anywhere between $0$ and $1$, I need $f^{-1}$, the inverse of this function, but I'm completely lost as to where to start... Would someone shed some light on my oh-gosh-it-was-so-long-ago math course?

3

There are 3 best solutions below

4
On BEST ANSWER

Take your equation $3 x^2 - 2 x^3 = y$, substitute $x = X + 1/2$, multiply by $2$ and expand to get $-4X^3 + 3 X = 2 y - 1$. Now note that $\sin(3t) = - 4 \sin(t)^3 + 3 \sin(t)$. Thus a solution is $X = \sin(t)$ where $\sin(3t) = 2y-1$, i.e. $$ x = \sin\left(\frac{\arcsin(2y-1)}{3}\right) + 1/2 $$

Note that $0 \le x \le 1$ when $0 \le y \le 1$.

0
On

The inverse function $g(y)$ satisfies $f[g(y)] = y$. In this case:

$$\frac{27}{4} \cdot \left( \left( \frac{2g(y)}3 \right) ^2 - \left( \frac{2g(y)}3 \right) ^3 \right) = y$$

Solve for $g(y)$ algebraically. Might be tough because it's a cubic, but it is possible.

2
On

You can ask to wolfram alpha:

1/2 (1+1/(1-2 x+2 sqrt(-x+x^2))^(1/3)+(1-2 x+2 sqrt(-x+x^2))^(1/3))

Or either you could implement the bisection method to solve $f(x) = y$. One should check, but it is possible that in this case the bisection method is faster than using the explicit formula for inverse.