Message Boards Message Boards

[✓] Obtain inverse of a function?


I'm quite new to Mathematica and have so far been unable to resolve the following (minor) technical issue. In principle, the task is very straightforward: I'd like to define the inverse of the function F(x) = 1 - x^2/(2cosh(x)-2) for x >= 0, but because F is not a 1-1 function on the reals, I often get answers with the wrong sign if I set:

g[x_] = InverseFunction[F][x]

I need to compose g with another function, so it's not enough to just reflect the plot of F in the line y=x.

The easy fix I've found is just to let

g[x_] = Abs[InverseFunction[F][x]]

but this feels like a bit of a cheat, and on my machine, it takes quite a long time to generate a plot (it is possible to speed up this process?)

Instead, I've been trying to define g as a function with a restricted domain using ConditionalExpression, as in the example at

I must be doing something wrong, because I don't get any plot whatsoever!

Any help would be much appreciated

POSTED BY: Oliver Feng
2 months ago

One possibility, which can be found in the documentation for InverseFunction, is

g2[x_] = InverseFunction[ConditionalExpression[F[#1], #1 > 0] &][x]

But it does not evaluate nicely:

  InverseFunction[ConditionalExpression[F[#1], #1 > 0] &][0.9]
  InverseFunction[ConditionalExpression[F[#1], #1 > 0] &][0.90000000000000000000]
  Root[{1 - (10 #1^2)/(-2 + 2 Cosh[#1]) &, 5.83679300341595705682344345476}]

Okay, the infinite-precision input works. So here's a workaround:

g[x_] := N[InverseFunction[F][SetPrecision[x, Infinity]], Precision[x]]

  Root[{1 - (10 #1^2)/(-2 + 2 Cosh[#1]) &, 5.83679300341595705682344345476}]

Plot[g[y], {y, 0, 1}]

enter image description here

POSTED BY: Michael Rogers
2 months ago

Another way, without using InverseFunction:

g[y_ /; Element[y, Reals]] := 
 First[x /. NSolve[F[x] == y && x > 0, x, Reals]]
POSTED BY: Gianluca Gorni
2 months ago

Group Abstract Group Abstract