How do you compute the inverse of a function in MATLAB? Say you want to compute the inverse of f(x)=e^x, what would be the code?
Numerical inverse of a monotone Function: let v be a monotone ascending array of numbers (that means v=sort(v)). Then you can derive the inverse (vinv) very simple:
vinv=cumsum(hist(v,length(v)));
After this you can beautify the result with a bit of scaling, but basically the cumsum of hist -thingi does the trick.
You can test the following:
x=randn(1,1000);
v=sort(x);
plot(v);
vinv=cumsum(hist(v,1000));
figure(2);
plot(vinv);
If the analytical approach fails (which is preferred whenever possible) use numerical approach:
Given y and guess x0 for the inverse
x = fzero( @(x)(f(x)-y), x0 );
or a low accuracy but faster method when the range of x known to be bounded in xmin...xmax
xx = linspace( xmin, xmax, N );
yy = f(xx);
x = interp1(yy, xx, y);
Of course, N has to be chosen according to the desired accuracy.
you can use finverse from the symbolic math toolbox http://www.mathworks.com/help/symbolic/finverse.html but for your example you can just do ln()?