# Solve for x given an interpolation function, y

Given a list of data,

lst={{x1,y2},{x2,y2},...,{xn,yn}}


and the interpolation function fun,

y=Interpolation[lst]


which can be plotted as,

Plot[y[x],{x,x1,xn}]


as usual. I've tried to apply Solve in order to obtain x given y=y0 as

Solve[y[x]==y0,x]


and get

Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information. >>

• Try InverseFunction[y]. May 21, 2015 at 2:59
• @Guesswhoitis. You mean InverseFunction[y][y0]  , it does not work. I know it is a bit trivial, but maybe has to do with the fact it is an interpolation. May 21, 2015 at 3:05
• That means your interpolating function is not one-to-one; that is only valid for one-to-one functions. May 21, 2015 at 3:29

Method 1

You can reverse the value of {x,y} to {y,x}, and then interpolate them.

Note:In this case, the value of $y$ cannot be duplicate

lst=
{{3.61648, 5.64818}, {7.53428, 4.52803}, {4.21088, 2.35117},
{4.48224,1.08325}, {4.63735, 5.5877}, {2.24299, 3.10376}}

x = Interpolation[Reverse /@ data];
x[3.]

 2.44086


Method 2

If the the values of $y$ are be duplicate, you should interpolate in two directions.

For instance, using the following method Options[interpolateCurve] =
Join[Options[ParametricPlot3D], Options[Interpolation]];

interpolateCurve[pts : {{_, _} ..}, opts : OptionsPattern[]] :=
Module[{order, x, y, s, func1, func2},
order = OptionValue[InterpolationOrder];
x = pts[[All, 1]];
y = pts[[All, 2]];
(*calculate the accumulative chord length*)
s =
FoldList[
Plus, 0, EuclideanDistance @@@ Partition[pts, 2, 1]];
(*interpolation points with spline-method in two directions*)
{func1, func2} =
Interpolation[
Thread@{s, #}, InterpolationOrder -> order, Method -> "Spline"] & /@ {x, y};
(*visualize the curve*)
ParametricPlot[{func1[t], func2[t]}, {t, 0, Last[s]},
Evaluate@
(Sequence @@ FilterRules[{opts}, Options[ParametricPlot]]),
Epilog -> {Red, PointSize[Medium], Point[pts]}]
]

• Method 1 worked. Thanks May 21, 2015 at 3:27
• @Resanrom, My pleasure, and I will complete the method 2 when I have time. Now I am busy:-)
– xyz
May 21, 2015 at 3:28
• @Resanrom, I have completed the method 2
– xyz
Jul 13, 2015 at 8:36
• .Thank you very much, your answers are really useful. I learn a lot. Jul 15, 2015 at 21:04
• @xyz This is probably late, but for method 2, even though you can plot the inverse function, you can't actually extract the data points, that is, for a given y, you can obtain all the solutions x1,x2,x3,... such that y==foo[x]. Is there a work around? Apr 15, 2020 at 4:43

you can try FindRoot

f = Interpolation[{1, 2, 3, 5, 8, 5}];
sol = FindRoot[f[x] == 2.5, {x, 3}]
(*{x -> 2.5641}*)
Plot[{f[x], 2.5}, {x, 1, 6}, GridLines -> {{x /. sol}, None}] 