If you have the symbolic toolbox in MATLAB, you can do the following
syms x
x=solve('x^2*exp(-x)=y')
x=
(-2)*lambertw(k, -((-1)^l*y^(1/2))/2)
Here lambertw
is the solution to y=x*exp(x)
, which is available as a function in MATLAB. So you can now define a function as,
t=@(y,k,l)(-2)*lambertw(k, -((-1)^l*y^(1/2))/2)
lambertw
is a multivalued function with several branches. The variable k
lets you choose a branch of the solution. You need the principal branch, hence k=0
. l
(lower case L) is just to pick the appropriate square root of y
. We need the positive square root, hence l=0
. Therefore, you can get the value of t
or the time for any value of y
by using the function.
So using your example, t(0.3,0,0)
gives 0.8291
.
EDIT
I forgot that there are two branches of the solution that give you real outputs (gnovice's answer reminded me of that). So, for both solutions, use
t(0.3,[0,-1],0)
which gives 0.8921
and 3.9528
.