InverseFunction

Considering a well defined function

f[x_]:=Tan[Sqrt[x]]/Sqrt[x] (*x>= 0*)

I tried to evaluate the inverse function and get an unexpected result

Plot[ InverseFunction[Function[{x}, Tan[Sqrt[x]]/Sqrt[x]]][z] , {z, -5, 5}, PlotRange -> {0, Automatic}]

in the range x<0. Is this a plotting problem or a bug in InverseFunction? Thanks! • f[x_]:=Tan[Sqrt[x]/Sqrt[x] is not well defined, as it has a syntax error :) – user6014 Feb 1 '18 at 15:22
• Now it's well defined. Thanks. – Ulrich Neumann Feb 1 '18 at 15:24
• Interestingly Wolframalpha does plot the inverse correctly ! – José Antonio Díaz Navas Feb 1 '18 at 16:41

The problem is simply that your inverse is not single valued

FindRoot[Tan[Sqrt[x]]/Sqrt[x] == -4 , {x, 2700}]
FindRoot[Tan[Sqrt[x]]/Sqrt[x] == -4 , {x, 23}]
FindRoot[Tan[Sqrt[x]]/Sqrt[x] == -4 , {x, 3}]

2371.67

22.7034

2.94296

InverseFunction doesn't always find the lowest..

InverseFunction[Function[{x}, Tan[Sqrt[x]]/Sqrt[x]]][-4] // N

22.7034 + 0. I

There are actually an infinity of inverses each where Sqrt[x] is approximately n Pi / 2, n odd.

Note if you just want to make the plot you can use

ParametricPlot[{Tan[Sqrt[x]]/Sqrt[x], x}, {x, -5, 7},
AspectRatio -> 1/GoldenRatio, Exclusions -> {x == Pi^2/4},
PlotRange -> {{-10, 10}, Automatic}]
• Thank You, I didn't see it... – Ulrich Neumann Feb 2 '18 at 9:19

There seems to be an issue with InverseFunction, might be worth reporting. A workaround is to use a black box function instead:

f[x_Real]:=Tan[Sqrt[x]]/Sqrt[x]
if = InverseFunction[f[#]&];

Plot[if[x], {x, -5, 5}] The OP asked about the "missing" inverse when $x<0$. The issue here is that the inverse has multiple branches. The "missing" inverse actually belongs to a different branch. This can be seen by looking at ContourPlot:

ContourPlot[
Tan[Sqrt[y]]/Sqrt[y] == x, {x, -5, 5}, {y, -5, 30},
] Rather than trying to come up with an inverse that switches branches, I think it makes more sense to have a different inverse function for each branch. A simple way to do this is to use NDSolveValue:

(* equation *)
eq[x_] = Tan[Sqrt[y[x]]]/Sqrt[y[x]] == x

(* initial point *)
y2 = y /. First @ NSolve[eq && 15<y<25]

(* NDSolve *)
sol = NDSolveValue[{eq'[x], y == y2}, y, {x, -5, 5}];

And a visualization:

Plot[sol[t], {t, -5, 5}] • Thanks: But I'm missing the branch x<0... – Ulrich Neumann Feb 2 '18 at 8:31
f[x_] := Tan[Sqrt[x]]/Sqrt[x]

f = f[0.] = Limit[f[x], x -> 0]

(* 1 *)

FunctionDomain[f[x], x]

(* NotElement[1/2 + Sqrt[x]/π, Integers] && x > 0 *)

s = x /. Solve[1/2 + Sqrt[x]/π == 1, x][]

(* π^2/4 *)

if[y_?NumericQ] := x /. NSolve[{f[x] == y, 0 <= x < 10}, x][]

Plot[if[y], {y, -5, 5},
AxesLabel -> (Style[#, 14, Bold] & /@ {y, x}),
Epilog -> {Gray, Dashed, Line[{{-5, s}, {5, s}}]}] EDIT:

\$Version

(* "11.2.0 for Mac OS X x86 (64-bit) (September 11, 2017)" *)

if (which is to say NSolve) fails for some values

if[1.00001]

(* Part::partw: Part 1 of {} does not exist.

ReplaceAll::reps: {{}[]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

x /. {}[] *)

Redefine f as

f2[x_] = Sinc[Sqrt[x]]/Cos[Sqrt[x]];

f and f2 are equivalent except that f2 is defined without adding a separate definition.

f[x] == f2[x] // FunctionExpand

(* True *)

f2

(* 1 *)

if2[y_?NumericQ] :=
x /. NSolve[{f2[x] == y, 0 <= x < 10}, x][]

Plot[if2[y], {y, -5, 5},
AxesLabel -> (Style[#, 14, Bold] & /@ {y, x}),
Epilog -> {Gray, Dashed, Line[{{-5, s}, {5, s}}]}] if2[1.00001]

(* 0.0000299996 *)
• Looks fine, thanks. But near y=1 I get unexplainable results: if[1.0001]==0.000299967 (*ok*), but if[1.00001]==20.1907 (* ??? *) – Ulrich Neumann Feb 2 '18 at 9:05
• @UlrichNeumann - Yes. On my Mac with version 11.2.0, NSolve fails for if[1.00001] and result is x /. {}[] along with associated error messages. – Bob Hanlon Feb 2 '18 at 15:25