3
$\begingroup$

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. >>

$\endgroup$
3
  • $\begingroup$ Try InverseFunction[y]. $\endgroup$ Commented May 21, 2015 at 2:59
  • $\begingroup$ @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. $\endgroup$ Commented May 21, 2015 at 3:05
  • $\begingroup$ That means your interpolating function is not one-to-one; that is only valid for one-to-one functions. $\endgroup$ Commented May 21, 2015 at 3:29

2 Answers 2

4
$\begingroup$

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

enter image description here

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]}]
]
$\endgroup$
5
  • $\begingroup$ Method 1 worked. Thanks $\endgroup$ Commented May 21, 2015 at 3:27
  • $\begingroup$ @Resanrom, My pleasure, and I will complete the method 2 when I have time. Now I am busy:-) $\endgroup$
    – xyz
    Commented May 21, 2015 at 3:28
  • 1
    $\begingroup$ @Resanrom, I have completed the method 2 $\endgroup$
    – xyz
    Commented Jul 13, 2015 at 8:36
  • $\begingroup$ .Thank you very much, your answers are really useful. I learn a lot. $\endgroup$ Commented Jul 15, 2015 at 21:04
  • $\begingroup$ @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? $\endgroup$ Commented Apr 15, 2020 at 4:43
4
$\begingroup$

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}]

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.