# Finding the $y$ value of an interpolated function given an $x$ value

I am trying to interpolate my dataset, which is a list of points. Thus I have two interpolated functions of my x data and y data:

datax={19.668, 18.5235, 17.581, 16.7985, 16.1445, 15.595, 15.1315, 14.7395,
14.4075, 14.1265, 13.8885, 13.6875, 13.518, 13.3765, 13.2585, 13.162,
13.083, 13.0205, 12.9715, 12.935, 12.909, 12.892, 12.8835, 12.8815,
12.885, 12.8935, 12.906, 12.9215, 12.9395, 12.9595, 12.98, 13.001,
13.022, 13.0425, 13.0615, 13.0785, 13.094, 13.1065, 13.1165, 13.1235,
13.1265, 13.126, 13.122, 13.1135, 13.1005, 13.0835, 13.062, 13.0355,
13.005, 12.97, 12.9305, 12.8865, 12.838, 12.786, 12.7295, 12.6695,
12.606, 12.539, 12.469, 12.396, 12.32, 12.242, 12.1615, 12.079,
11.995, 11.9095, 11.823, 11.7355, 11.647, 11.558, 11.469, 11.38,
11.291, 11.2025, 11.1145, 11.0275, 10.9415, 10.8565, 10.7725, 10.69,
10.609, 10.53, 10.453, 10.3775, 10.304, 10.233, 10.164}

datay={0.161158, 0.17188, 0.183499, 0.196057, 0.209601, 0.224179, 0.239842,
0.256644, 0.274639, 0.293882, 0.314433, 0.336349, 0.359688, 0.384507,
0.410862, 0.43881, 0.468401, 0.499684, 0.532704, 0.567499, 0.604103,
0.642541, 0.682831, 0.724979, 0.768983, 0.814829, 0.862489, 0.911922,
0.963073, 1.01587, 1.07023, 1.12604, 1.1832, 1.24156, 1.30096,
1.36126, 1.42226, 1.48377, 1.54559, 1.6075, 1.66927, 1.73069,
1.79152, 1.85153, 1.91048, 1.96817, 2.02436, 2.07887, 2.13148,
2.18203, 2.23035, 2.27629, 2.31974, 2.36058, 2.39873, 2.43413,
2.46673, 2.49651, 2.52347, 2.54761, 2.56897, 2.58759, 2.60354,
2.61689, 2.62772, 2.63613, 2.64222, 2.64609, 2.64786, 2.64765,
2.64558, 2.64177, 2.63633, 2.6294, 2.62109, 2.61152, 2.6008, 2.58906,
2.57639, 2.5629, 2.5487, 2.53389, 2.51855, 2.50278, 2.48667, 2.47028,
2.45371}

fx=Interpolation[datax]
fy=Interpolation[datay]


I can then plot these together using ParametricPlot:

ParametricPlot[{fx[x], fy[x]}, Evaluate@{x,Sequence @@ First@Interpolation[datax]["Domain"]}]


And it gives me a nice interpolated version of my original data.

My issue is, now I need to find a specific y-value corresponding to x_o=1.4 on this parametric plot, which I've found to be impossible (?).

So what I'm doing is the following:

First, plot each interpolated function separately:

 Plot[{fx[x], fy[x]}, Evaluate@{x,
Sequence @@ First@Interpolation[datax]["Domain"]}]


Which gives me my two interpolated functions:

Next, I Find the X-value of my fy interpolated function:

xroot = x /. FindRoot[fy[x] == 1.4, {x, 35}][[1]]
(*36.6362*)


And now I need to find the corresponding Y-value of my fx interpolated function.

My issue is, I have no idea how to find a y-value given an x-value! I have tried:

FindRoot[InverseFunction[fx[x]] == sol, {x, 3}]


But I get the error:

"The function value {-36.6362+InverseFunction[17.581]} is not a list of numbers with dimensions {1} at {x} = {3.}"


Does anyone know how to find a y-value given x_o for an interpolated data set? or is there an easier way of doing this??

Thanks so much for your time!

• parts of your code don't evaluate, ParametricPlot[{datax,datay},{x,0,16.5}], other parts are undefined fm, fr Commented Jun 6, 2018 at 18:48
• Sorry! My bad. I just fixed it so it runs :)
– zack
Commented Jun 6, 2018 at 18:55
• @zack your code still does not run. You should try to copy your code from this question and execute it in a clean MMA kernel to make sure that you provided us enough information to run it. Commented Jun 6, 2018 at 19:03
• This is pretty unclear. Are your data points specified by $(x_i,y_i)$ pairs, which you separated into the two sets datax and datay? If so, then $x_0 = 0.14$ is outside of your domain and I don't think you can calculate the corresponding $y_0$ with the information you have. If, on the other hand, you want to calculate the $x_0$ for which $y=0.14$, then try InverseFunction[Interpolation@Transpose@{datax, datay}][1.4], which returns 13.1814. Commented Jun 6, 2018 at 19:09
• Looks like you have fx and fy switched. Commented Jun 6, 2018 at 19:17

The following is how you could use InverseFunction to find the $x$ value for a given $y$:

ify = InverseFunction[fy];
fx[ify[1.4]]


13.0886

Of course, you have no control over which $y$ value is used.

Or finding the $y$ value for a given $x$:

ifx = InverseFunction[fx];
fy[ifx[15]]
`

0.245044

• Thank you so much Carl! I've been trying to get this to work all day and your simple solution worked wonders! Your first line gave me the exact answer I need.
– zack
Commented Jun 6, 2018 at 19:48