# [✓] Obtain inverse of a function?

Posted 1 year ago
1272 Views
|
3 Replies
|
3 Total Likes
|
 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
3 Replies
Sort By:
Posted 1 year 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: g2[0.9] g2[0.920] g2[9/10] (* 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]] g[0.9] g[0.920] g[9/10] (* 5.83679 5.8367930034159570568 Root[{1 - (10 #1^2)/(-2 + 2 Cosh[#1]) &, 5.83679300341595705682344345476}] *) Plot[g[y], {y, 0, 1}] 
 Another way, without using InverseFunction: g[y_ /; Element[y, Reals]] := First[x /. NSolve[F[x] == y && x > 0, x, Reals]] 
 Another way,using differential equation: F[x_] := 1 - x^2/(2 Cosh[x] - 2) HoldForm@D[InverseFunction[F][x], x] == D[InverseFunction[F][x], x] Substituting and simplifying: eq = y'[x] == 1/(-((2 y[x])/(-2 + 2 Cosh[y[x]])) + (2 Sinh[y[x]] y[x]^2)/(-2 + 2 Cosh[y[x]])^2)// Simplify sol = NDSolve[{eq, y[0] == 1}, y, {x, 0, 1}, WorkingPrecision -> 20]; Plot[y[x] /. sol, {x, 0, 0.92}] Or by Inverse Series: F[x_] := 1 - x^2/(2 Cosh[x] - 2); n = 10;(*more better*); inv = Normal@InverseSeries[Series[F[x], {x, 0, n}]]; Plot[Evaluate@inv, {x, 0, 1}]