# InverseFunction fails at some parameter

Currently, I am faced with the difficulty of evaluating the inverse of the function below for certain negative decimal values of the parameter q. Specifically for large values of the argument of rho, the inversion blows up. My code reads:

q = -5/2;
b0 = 1;
rho[r_] := (2 b0)/(1 - q) Sqrt[1 - (b0/r)^(1 - q)]
Hypergeometric2F1[1/2, (q - 2)/(q - 1), 3/2, 1 - (b0/r)^(1 - q)];
ry = N@InverseFunction[rho[#] &];

ry[300] // N
During evaluation of In[13]:= Power::infy: Infinite expression 1/0. encountered.
During evaluation of In[13]:= Power::infy: Infinite expression 1/0.^1. encountered.
Out[13]= ComplexInfinity


This is weird since this does not happen for negative integer values of q. The estimated value of ry[300] should be around (or near) 300 also. So I guess MMA is having a hard time processing decimal values of the parameter q, like possibly it tends to treat small values as effectively zero. Is there something that I am missing here? Any help is much appreciated.

Edited: The original function rho can be evaluated at any point r including the points that I have difficulty with for the inverse function.

• I can't reproduce the error in MMA 13 (cloud). I obtain 0.0173961 +0.0218141 I as the result. Feb 25, 2022 at 1:53
• Hi @MathX, I am only aware of the branch point at $z=1$ but haven't checked on the discontinuities. Feb 25, 2022 at 1:56
• Hi @MarcoB, hmm that's weird but I am expecting a rough estimate of around 300 for the value. Thanks for the info Feb 25, 2022 at 1:58
• Hi @MathX, I have already checked it and I encounter no problem in evaluating the original function at any point. But thanks for the comment. I will add your point in the original question and clarify that the original function can be evaluated at any point including the points that I have difficulty for the inverse function. Feb 25, 2022 at 2:14
• No that's fine. Feb 25, 2022 at 2:18

Edit

Just see, @CarlWoll has found it hours before!

This is a typical example, which confirms, what i always say: Use "SetDelayed" only where neccessary, standard should be "Set". With that strategy, you would have seen the error at once!

Your definitons of rho[r_] is split to two lines. Omit lhs to see it.

(2 b0)/(1 - q) Sqrt[1 - (b0/r)^(1 - q)]
Hypergeometric2F1[1/2, (q - 2)/(q - 1), 3/2, 1 - (b0/r)^(1 - q)]


Just delete The "Return" and it is ok.

q = -5/2;
b0 = 1;

rho[r_] := (2 b0)/(1 - q) Sqrt[1 - (b0/r)^(1 - q)]    Hypergeometric2F1[
1/2, (q - 2)/(q - 1), 3/2, 1 - (b0/r)^(1 - q)];
ry = N@InverseFunction[rho[#] &];

ry[300] // N

(*   300.53   *)

• Hi. I think the problem is with the version/copy of MMA that I have. I still get ComplexInfinity even when I use your answer. Feb 25, 2022 at 11:14