6 views (last 30 days)

Check function Invertible or not

Walter Roberson
on 26 Oct 2020

If all you are given is a function handle, and you are not permitted to examine the source code, then it is not always possible to determine whether a function is invertible.

Consider for example

testfun = @(x) x + (x == 37.9123325183) .* 12.0876674817

which returns its input except for 37.9123325183 for which it returns 50 instead.

Without some tool for disassembling the implementing expression, you would have to have tested with exactly that magic value in order to have observed a result different than you expected.

Or here is another one: write a function that returns its input **unless* the number is odd and the sum of the factors of the number including 1 but excluding the number itself, add up to the number, in which case return -1.

Is this function invertible? No-one knows. A lot of research has gone into it over the centuries, but no-one has been able to prove that Odd Perfect Numbers do not exist (the above function is invertible except at odd perfect numbers.) Therefore even having access to the source code is not enough to be able to tell whether the function is invertible.

Walter Roberson
on 27 Oct 2020

If, though f = @(x)x.^2 - 2*x + 3 then for any non-zero x you try, f(x) ~= f(-x) , so just trying one value will not help.

If you have the symbolic toolbox, then there is a class of problems for which you can ask

solve(f(x) == f(-x), x)

and see if there is any solution that excludes 0 (because 0 = -0 and so -x is not distinct from x for x = 0).

In the case of polynomials, then The Fundamental Theorem of Algebra says that a degree N polynomial has N roots -- N (possibly non-distinct) places where f(x) = 0. If any of those roots are non-zero, then the polynomial is not invertable because it has at least two places where f(x1) = f(x2) = 0. The polynomial whose roots are all-zero is the form f(x) = a*x^n for some positive integer n. And in the case of a*x^n for positive integer n, if n is even then f(-x)=f(x) for all x and so it would not be invertible. For the case of a*x^n for odd positive integer n > 1, the function is still not invertible: y = a*x^n has solutions involving y/a and the N roots of unity.

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 0 Comments

Sign in to comment.