There is no problem in computing the above. I get the answer to this almost instantly. But I couldn’t evaluate the same function when my input is 201. i.e., When I do the following, Mathematica couldn’t find an answer.
Please help me out what I’m missing and why the computations are taking time when I try evaluating the same using Solve and also why Mathematica couldn’t evaluate the function value at certain points such as 201?
You are using floating point numbers. In most cases InverseFunction is used with symbolic numbers instead because it is a symbolic function. There are major differences between floating point and symbolic numbers.
Use Rationalize to convert most of your formula to symbolic numbers.
Remember though that you have to be careful with the precision you have. If we use Rationalize[#,0]& as work with a completely symbolic formula, it’s possible to get a situation where there is no precision left in your result.
It is easy to make your calculations meaningless by losing all precision. I’m not sure how many digits of accuracy your coefficients have to begin with, but it’s possible that InverseFunction might not be a very stable operation in this case.
I may have miscopied the code. The suggestion however is to try computing the values symbolically in some way. Or you may want to investigate why this isn’t numerically stable.
This gives back a Root expression, which is just a complicated way of describing a number. You can run N on it to try returning a decimal approximation. You may need to use arbitrary precision computing however.
But when I did the same using the method you suggested me (first using rationalize and then solving it using N ), provided me altogether different solution and the solution doesn’t change even when I change the input after the input is 24.
The difference in value is probably floating point error. If you’re comfortable knowing the result is close to 0, then the result might be fine. How much precision are you look for in your result? You may be able to get it using arbitrary precision arithmetic.
If InverseFunction isn’t working out at all, then some serious numerical work will have to be done to get a good answer. Typically, computing the inverse of a function is viewed as a root finding problem. You may want to experiment with different Methods for FindRoot. The three statements below are essentially equivalent.
NSolve[f[x] == b,x]
x = InverseFunction[f][b]
FindRoot[f[x]-b, {x,0}]
I tried to find the inverse function using 2 methods for the same expression. Directly solving using InverseFunction gave me a result which is 0.0101108 ; while solving it first by using Rationalize and then solving it using N gave me a result which is 4.26674*10^9.
Please note that there are many orders of magnitude difference between the both but not a floating point error.
Having many orders of magnitude between the two results is fairly normal for a floating point error. Very often you have to come up with a technique specific to the problem. In this case rephrasing as a root finding problem seems sufficient to get a reasonable answer: