InverseFunction

enter image description here

in the range x<0. Is this a plotting problem or a bug in InverseFunction? Thanks!

Ulrich Neumann asked Feb 1, 2018 at 14:59 Ulrich Neumann Ulrich Neumann 55.5k 2 2 gold badges 23 23 silver badges 59 59 bronze badges

$\begingroup$ f[x_]:=Tan[Sqrt[x]/Sqrt[x] is not well defined, as it has a syntax error :) $\endgroup$

Commented Feb 1, 2018 at 15:22 $\begingroup$ Now it's well defined. Thanks. $\endgroup$ Commented Feb 1, 2018 at 15:24 $\begingroup$ Interestingly Wolframalpha does plot the inverse correctly ! $\endgroup$ Commented Feb 1, 2018 at 16:41

3 Answers 3

$\begingroup$

The problem is simply that your inverse is not single valued

FindRoot[Tan[Sqrt[x]]/Sqrt[x] == -4 , ] FindRoot[Tan[Sqrt[x]]/Sqrt[x] == -4 , ] FindRoot[Tan[Sqrt[x]]/Sqrt[x] == -4 , ] 

InverseFunction doesn't always find the lowest..

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

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[, , AspectRatio -> 1/GoldenRatio, Exclusions -> , PlotRange -> , Automatic>] 
answered Feb 1, 2018 at 17:05 george2079 george2079 39k 1 1 gold badge 44 44 silver badges 110 110 bronze badges $\begingroup$ Thank You, I didn't see it. $\endgroup$ Commented Feb 2, 2018 at 9:19 $\begingroup$

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], ] 

enter image description here

Addendum

ContourPlot[ Tan[Sqrt[y]]/Sqrt[y] == x, , , ContourShading->False ] 

enter image description here

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[2] /. First @ NSolve[eq[2] && 15, y, ]; 

And a visualization:

Plot[sol[t], ] 

enter image description here

answered Feb 1, 2018 at 15:45 131k 6 6 gold badges 244 244 silver badges 357 357 bronze badges $\begingroup$ Thanks: But I'm missing the branch x<0. $\endgroup$ Commented Feb 2, 2018 at 8:31 $\begingroup$
f[x_] := Tan[Sqrt[x]]/Sqrt[x] f[0] = 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][[1]] (* π^2/4 *) if[y_?NumericQ] := x /. NSolve[, x][[1]] Plot[if[y], , AxesLabel -> (Style[#, 14, Bold] & /@ ), Epilog -> , >]>] 

enter image description here

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: [[1]]> is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. x /. <>[[1]] *) 
f2[x_] = Sinc[Sqrt[x]]/Cos[Sqrt[x]]; 

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

f[x] == f2[x] // FunctionExpand (* True *) f2[0] (* 1 *) if2[y_?NumericQ] := x /. NSolve[, x][[1]] Plot[if2[y], , AxesLabel -> (Style[#, 14, Bold] & /@ ), Epilog -> , >]>] 

enter image description here

if2[1.00001] (* 0.0000299996 *)