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$
  • $\begingroup$ Try InverseFunction[y]. $\endgroup$ – J. M. is away May 21 '15 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$ – Patrick El Pollo May 21 '15 at 3:05
  • $\begingroup$ That means your interpolating function is not one-to-one; that is only valid for one-to-one functions. $\endgroup$ – J. M. is away May 21 '15 at 3:29
3
$\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$
  • $\begingroup$ Method 1 worked. Thanks $\endgroup$ – Patrick El Pollo May 21 '15 at 3:27
  • $\begingroup$ @Resanrom, My pleasure, and I will complete the method 2 when I have time. Now I am busy:-) $\endgroup$ – xyz May 21 '15 at 3:28
  • 1
    $\begingroup$ @Resanrom, I have completed the method 2 $\endgroup$ – xyz Jul 13 '15 at 8:36
  • $\begingroup$ .Thank you very much, your answers are really useful. I learn a lot. $\endgroup$ – Patrick El Pollo Jul 15 '15 at 21:04
1
$\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, privacy policy and cookie policy

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