Plot inverse functions?

Hello all,

I am currently working on some polar coordinate plots and have been constantly running into the same problem. For an inverse function like ArcCos[x], the domain is [-1,1]. When plotting this function we get

Plot[ArcCos[\[Theta]], {\[Theta], -2 \[Pi], 
  2 \[Pi]}, PlotRange -> {-4, 4}]

But we know that the Cos[x] function is periodic

So there has to be multiple solutions to the ArcCos[x] function. eg. ArcCos1 = 0, 2pi, 3pi, etc…

How come Mathematica does not recognize this? Also, how can I plot a continuous Inverse function?

Is this more like what you wanted?

ParametricPlot[{Cos[t], t}, {t, -2 Pi, 2 Pi}]

To put it in simple terms, if ArcCos did not evaluate to a number it would be fairly useless. Same for Log and all the rest.

As for multiple solutions to trig equations, there is Solve and Reduce. Example:

In[203]:= Solve[Cos[x] == 1, x]

(* Out[203]= {{x ->  ConditionalExpression[2 \[Pi] C[1], C[1] \[Element] Integers]}} *)

In simple terms, x = Cos[theta] is a multivalued function. Many values of theta (in fact, an infinite number, theta + 2 n pi) give the same value of x. In mathematical jargon, ArcCos[x] is an injective but not a bijective function.

Good responses all around, and I agree. It’s useful to think about the conditions where you expect an inverse function to exist, and how are the inverse functions defined or calculated from first principles?

You should conclude that the notion of an inverse function is essentially a local concept, limited to domains where the direct function is either strictly increasing or strictly decreasing.

Then, if necessary, you can program functionality to “patch” your direct and inverse functions. For example:

Show[
 Plot[Cos[x], {x, -Pi, 0}],
 Plot[Cos[x], {x, 0, Pi}, PlotStyle -> Red], PlotRange -> All,
 ImageSize -> 500
 ]

Extrapolate this patching scheme to the entire domain, taking advantage of translation ivariance. Then permute x and y axis, and you will calculate the following patched inverse function

Show[

Plot[
-ArcCos[x] + 2 Pi # & /@ Range[-5, 5], {x, -1, 1}, 
PlotRange -> {-10, 10}, PlotStyle -> Blue],
Plot[
ArcCos[x] + 2 Pi # & /@ Range[-5, 5], {x, -1, 1}, 
PlotRange -> {-10, 10}, PlotStyle -> Red],
ListPlot[{Cos[#], #} & /@ (Range[-150, 100]/10), 
PlotMarkers -> {Automatic, 10}]]

Thanks, Brad.

Thank you guys for replying. My main issue with inverse functions is not so much how to interpret them mathematically but how Mathematica treats them when plotting. For example: say I’m working with the potential field below:

V[r_, \[Phi]_] := 
  Exp[-(r - 1)^2]*(Exp[-(\[Phi])^2] + Exp[-(\[Phi] - 2 \[Pi]/3)^2] + 
     Exp[-(\[Phi] + 2 \[Pi]/3)^2]);

If I did a simple ContourPlot with phi as my independent axis, it would look something like this…

but if I try to convert it into a radial plot in Cartesian coordinates, phi → ArcTan(x/y), There seems to be a discontinuity in the Plot:

TransformedField["Polar" -> "Cartesian", 
 V[r, \[Phi]], {r, \[Phi]} -> {x, y}]

ContourPlot[%, {x, -2, 2}, {y, -2, 2}, PlotRange -> All]

There should be a saddle pt at (x=-1, y=0), but due to restriction’s in ArcTan’s argument, there is a cutoff. This problem also affects the dynamics of this field as well because Mathematica just doesn’t recognize that there is overlap between the two Gaussian hills.

Any suggestions on how to resolve this?

Perhaps ArcTan[x,y] instead of ArcTan[x/y]

V[r_, ?_] := Exp[-(r - 1)^2]*(Exp[-?^2] + Exp[-(? - 2 ?/3)^2] + Exp[-(? + 2 ?/3)^2]) /. ?->ArcTan[x, y];
TransformedField["Polar"->"Cartesian", V[r, ?], {r, ?}->{x, y}];
ContourPlot[%, {x, -2, 2}, {y, -2, 2}, PlotRange -> All]

Read the help page carefully to make certain the order of x,y and x/y are correct in your ArcTan.

Hi Bill, can I ask what version of Mathematica you are using? I’ve copied and pasted the exact same code onto my notebook and am still having the same problem.

In V10.1 it displays without the discontinuity.

In V11.1 it displays with the discontinuity.

Perhaps you can think very carefully, write your own version of TransformedField and see if you can avoid the discontinuity.

Perhaps someone can look at the internal details of TransformedField and see if the implementation has shown “unexpected behavior”.

Use the option Exclusions → None to ContourPlot

V[r_, \[CurlyPhi]_] := 
  Exp[-(r - 1)^2]*(Exp[-\[CurlyPhi]^2] + 
      Exp[-(\[CurlyPhi] - 2 \[Pi]/3)^2] + 
      Exp[-(\[CurlyPhi] + 2 \[Pi]/3)^2]) /. \[CurlyPhi] -> 
    ArcTan[x, y];
TransformedField["Polar" -> "Cartesian", 
  V[r, \[CurlyPhi]], {r, \[CurlyPhi]} -> {x, y}];
ContourPlot[%, {x, -2, 2}, {y, -2, 2}, PlotRange -> All, 
 Exclusions -> None]

I think you should be careful with this plot, and it looks like you are headed in a wrong direction. The function you give isn’t 2\pi periodic, as can easily be seen by explicit computation of function values

V[r_, \[CurlyPhi]_] :=   Exp[-(r - 1)^2]*(Exp[-\[CurlyPhi]^2] +  Exp[-(\[CurlyPhi] - 2 \[Pi]/3)^2] + Exp[-(\[CurlyPhi] + 2 \[Pi]/3)^2])
N@V[1, 0]
N@V[1, 2 Pi]

1.02489
2.3982*10^-8

So the function domain isn’t planar. Then why would you use polar coordinates?

Maybe I’m reading too much into your symbolism, but it looks like you’re trying to define a potential function with a central saddle point, and a few equally spaced minima. The best way to do this is to insert power series expansions into the elements of a 2\times2 matrix, apply a symmetry constraint to matrix elements and polynomial variables to reduce degrees of freedom, and finally diagonalize the matrix. If you do all this right, the lower energy eigenvalue surface should be a nice potential function with all your desired extremal properties and a conical intersection at the origin. These sort of potential surfaces are used in the setting of the vibronic Jahn-Teller effect. A good-enough article is: Effects of higher order Jahn-Teller coupling on the nuclear dynamics .

You know what Hans? That was it.

Thank you.