Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
    
normal form: y=function of x, inverse: x=function of y –  Bob Jan 31 '13 at 19:52
1  
It's simpler and easier to understand if you write $f(x)=3x^2-2x^3$. –  user1551 Jan 31 '13 at 19:54
    
Oh. My. Didn't even think of simplifying it. When I told you I'm rusty... –  Cyrille Jan 31 '13 at 20:48

3 Answers 3

up vote 5 down vote accepted

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$.

share|improve this answer
    
Wait wait wait... sinuses? –  Cyrille Jan 31 '13 at 20:51
    
Okay, after re-reading it like ten times, it makes sense. –  Cyrille Jan 31 '13 at 21:02
1  
What I've always wondered (and that's where the beauty of maths comes from) is: where did you take the "substitute x = X + 1/2" from? I mean, did you just have to say "shazam" to find this? –  Cyrille Jan 31 '13 at 21:11
    
Take $x = X + a$ and see what $a$ has to be to eliminate the $X^2$ term. –  Robert Israel Jan 31 '13 at 23:35

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.

share|improve this answer

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.

share|improve this answer
    
Didn't even knew you could ask this to Wolfram. Thanks! –  Cyrille Jan 31 '13 at 21:05
    
But notice that when $x \in (0,1)$, you're taking the square root of a negative number. This is no accident: see en.wikipedia.org/wiki/Casus_irreducibilis –  Robert Israel Jan 31 '13 at 23:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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