1
$\begingroup$

Consider the following sample code

pts = Table[{i, i^2}, {i, -10, 10}];
foo = Interpolation[pts];
Plot[InverseFunction[foo][y], {y, 0, 10}]

From the plot, we see that InverseFunction[foo][y] only finds the positive x corresponding to the interpolation function foo, but ideally, I would like the inverse function to be something like ifoo[y]={x1,x2,...}, where x1,x2,... are the possible solutions for $y=x^2$.

In the end, I would like to generalize this to a multi-dimensional function. More specifically, let's say I have a set of data {{{x1,y1},{f1,g1}},...} and apply interpolation so that we get the function foo[x,y]={f[x,y],g[x,y]}. Now I would like to invert this function so that ifoo[z,w]={{x1,y1},{x2,y2},...} where {x1,y1},{x2,y2},... are the possible solutions towards foo[x,y]={z,w}.

How would one be able to do this?

$\endgroup$

2 Answers 2

1
$\begingroup$

Define the inverse with FindRoot

Clear["Global`*"]

pts = Table[{i, i^2}, {i, -10, 10}];
foo = Interpolation[pts];

inv[y_?NumericQ, branch_ : Automatic] :=
 Module[{x, init = If[branch === Automatic, -10, 10]},
  x /. FindRoot[foo[x] == y, {x, init}]]

Augmenting InverseFunction

Plot[{InverseFunction[foo][y], inv[y]},
 {y, 0, 100}, PlotLegends -> Placed["Expressions", {.85, .25}]]

enter image description here

Replacing InverseFunction

Plot[{inv[y, "+"], inv[y]}, {y, 0, 100}, 
 PlotLegends -> Placed["Expressions", {.85, .25}]]

enter image description here

$\endgroup$
3
  • $\begingroup$ So in your code, it seems that you need to know that there are two solutions, one positive one negative, but for a general function that may not be true, such as a bifurcation diagram or something else. $\endgroup$ Commented Apr 15, 2020 at 5:24
  • $\begingroup$ You would need to plot foo to determine how many branches there are and the initial starting value to use for each branch. $\endgroup$
    – Bob Hanlon
    Commented Apr 15, 2020 at 5:31
  • $\begingroup$ @Andrew an inverse function is supposed to be one-to-one, so if you know multiple solutions are possible, you need to do things differently. $\endgroup$ Commented May 19, 2020 at 7:35
1
$\begingroup$

You can find the two inverses by generating a differential equation of foo and solve with NDSolve applied to two initial conditions. Even derivatives of inverse function can be produced.

pts = Table[{i, i^2}, {i, -10, 10}];
foo = Interpolation[pts];

dinv = D[foo[x[y]] == y, y]

xsol[y_] = 
   x[y] /. NDSolve[{dinv, #}, x, {y, 100, 0}] & /@ {x[100] == -10, 
x[100] == 10} // Quiet

{Plot[xsol[y], {y, 0, 100}, ImageSize -> 300, AspectRatio -> 1], 
 Plot[xsol'[y], {y, 0, 100}, ImageSize -> 300, AspectRatio -> 1]
}

enter image description here

$\endgroup$

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.