# Piecewise linear Interpolation between data points

Is there some sort of functionality built into Mathematica that will let me linearly interpolate between (x, y) pairs of data in an array?

Example: I have the two points (1, 10) and (2, 20), how can I find out what the interpolant at 1.5 would be?

-
Did searching for "interpolate" or "interpolation" in the documentation not give any results? –  rm -rf Mar 5 '13 at 2:19
@rm-rf Yes, but I want Interpolate[{Lena, Toady}] and it doesn't work –  belisarius Mar 5 '13 at 9:19
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! –  belisarius Mar 5 '13 at 13:01

Apparently, it has been missed that InterpolatingPolynomial[] can be used for "lerping". Here's halirutan's example as a one-liner:

InterpolatingPolynomial[{{1, 10}, {2, 20}}, 1.5]
15.

-

Not as elegant as above approaches, but Fit can also be used. To try different shape functions:

data = {{1, 10}, {2, 20}};
trial = {{1, x}, {1, x, x^2}, {1, x, x^2, x^3}, {1, Sin[x]}, {1, Cos[x]},
{1, Sin[x], Cos[x]}, {1, x, Exp[x]}, {1, x, x^2, Exp[x]}};
fits = Fit[data, #, x] & /@ trial;
x0 = 1.5;
Grid[Partition[
Plot[#, {x, 0, 3}, Frame -> True, ImageSize -> 230,
FrameLabel -> {{None, None}, {None,
Grid[{{"f(x)=", #, SpanFromLeft}, {"f(", x0,")=", # /. x -> x0}},
Spacings -> 0]}},
Epilog -> {Red, PointSize[.1], Point[{x0, # /. x -> x0}]},
ImagePadding -> {{30, 30}, {5, 50}}] & /@ fits, 3], Frame -> All]


-

Although not as elegant as halirutan's post, this helps alternatively,

f:=Rescale[#,{1,2},{10,20}]&;
f[1.5]

-

What about using Interpolation?

f = Interpolation[{{1, 10}, {2, 20}}, InterpolationOrder -> 1]
f[1.5]

-
this method is significantly slower than matlab interp1 method –  n3rd Aug 28 at 17:46