0
$\begingroup$

MMA 12.1 For quite some time I have been chasing a bug that I could trace down to the following code. As it is not impossible to fool oneself, I would be glad if somebody could verify this before I report it to Wolfram:

I have a well behaved InterpolatingFunction fun1:

fun1[z_] = 
   InterpolatingFunction[{{-5., 0.}}, {5, 3, 0, {46}, {4}, 0, 0, 0, 0,
       Automatic, {}, {}, 
      False}, {{-5., -4.79167, -4.58333, -4.375, -4.16667, -3.95833, \
-3.75, -3.54167, -3.33333, -3.125, -2.91667, -2.70833, -2.5, \
-2.39583, -2.29167, -2.1875, -2.08333, -1.97917, -1.875, -1.77083, \
-1.66667, -1.5625, -1.45833, -1.35417, -1.25, -1.14583, -1.04167, \
-0.9375, -0.885417, -0.833333, -0.78125, -0.729167, -0.677083, \
-0.625, -0.572917, -0.520833, -0.46875, -0.416667, -0.364583, \
-0.3125, -0.260417, -0.208333, -0.15625, -0.104167, -0.0520833, 
       0.}}, {{2.85192}, {2.67974}, {2.50886}, {2.3394}, {2.17145}, \
{2.00516}, {1.84064}, {1.67807}, {1.51763}, {1.35951}, {1.20397}, \
{1.05127}, {0.901755}, {0.828303}, {0.755796}, {0.684292}, \
{0.613859}, {0.544567}, {0.476499}, {0.409743}, {0.344399}, \
{0.280578}, {0.218405}, {0.158022}, {0.0995881}, {0.043287}, \
{-0.0106712}, {-0.0620432}, {-0.0866725}, {-0.110545}, {-0.133618}, \
{-0.155844}, {-0.177172}, {-0.197544}, {-0.216899}, {-0.235169}, \
{-0.252278}, {-0.268143}, {-0.282669}, {-0.295752}, {-0.307275}, \
{-0.317105}, {-0.325091}, {-0.331059}, {-0.334812}, {-0.336118}}, \
{Automatic}][z]


Plot[fun1[z], {z, -5, 0}]

enter image description here

If I take the inverse function, you would expect a plot of the following form (obtained numerically):

d1 = Table[{x, fun1[x]}, {x, -5, 0, .1}];
ListLinePlot[Reverse /@ d1]

enter image description here

However, what I get is:

Plot[InverseFunction[fun1][z], {z, -.336, 3}]

enter image description here

$\endgroup$
4
  • 2
    $\begingroup$ It might be because the inverse is done over the extrapolated part of the interpolation {-.336,3} which is mostly outside {-5, 0} - have a look at Plot[{fun1[z], InverseFunction[fun1][z], z}, {z, -.336, 3}, AspectRatio -> 1, PlotRange -> {{0, 3}, {0, 3}}] - it's symmetrical, so the inverse is correct over this domain, but not where you want it. $\endgroup$
    – flinty
    May 15, 2021 at 20:10
  • $\begingroup$ Apparently, you too have been working on 246073. $\endgroup$
    – bbgodfrey
    May 16, 2021 at 20:47
  • $\begingroup$ @ bbgodfrey - :) so I did! $\endgroup$ May 17, 2021 at 7:01
  • $\begingroup$ I brought this issue to the attention of Wolfram and here is their answer: "Thank you for the clarification. InverseFunction does not currently fully support InterpolationFunction objects. I have added your contact information to a suggestion report on this feature, so that robust InverseFunctions for interpolating functions can be added in future versions of the Wolfram Language, and a separate report so that this can be highlighted in the documentation." $\endgroup$ May 18, 2021 at 20:39

1 Answer 1

2
$\begingroup$

It might be useful to introduce the wrapper for the given function:

fun2[z_] := If[0 > z > -5, fun1[z], 0]

Now we can plot both inverses

Plot[{InverseFunction[fun2][z], InverseFunction[fun1][z]}, {z, -.336, 
  3}, PlotRange -> All]

This essentially confirms what @flinty said in the comment: InverseFunction simply has chosen the wrong branch.

enter image description here

$\endgroup$
4
  • $\begingroup$ Thanks' a lot for your answer. But I think the explanation is not correct. I plotted on purpose the inverse function over the range of the original function. The definition region of the inverse function is the range of the original function not its definition region. Imagine the case where these to region have no point in common. I think, the real reason is that fun1 is not monotonous. This makes the inverse mutlivalued. Look e.g. at: ParametricPlot[{fun1[z], z}, {z, -5, 3}] $\endgroup$ May 16, 2021 at 7:39
  • $\begingroup$ @DanielHuber I fail to see why my explanation is not correct. What exactly is wrong? By the way, you do not need to accept answers, if you think they are wrong. Just write your own. $\endgroup$
    – yarchik
    May 16, 2021 at 10:14
  • $\begingroup$ @DanielHuber The function fun1 is monotonous on the interpolation domain, and is not monotonous on a broader domain. As you said, it makes the inverse multivalued, and MA has chosen the wrong branch out of 2. That is what I have written. If you look closer into the problem, the real reason is that one needs to restrict the domain where the function is defined. This assures the monotonicity. $\endgroup$
    – yarchik
    May 16, 2021 at 10:21
  • $\begingroup$ Hi, please do not get me wrong, I appreciate your answer. I only pointed out that the problem is the monotonicity and not that the inverse function is not defined over the definition region of the original function. $\endgroup$ May 16, 2021 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.