Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing the inverse of function in MATLAB

Tags:

matlab

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?

like image 655
hherklj kljkljklj Avatar asked Feb 16 '23 03:02

hherklj kljkljklj


1 Answers

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.

like image 106
Andreas H. Avatar answered Feb 23 '23 13:02

Andreas H.