# Piecewise linear Interpolation between data points [closed]

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?

-

## closed as off-topic by J. M.♦Jun 28 '15 at 16:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – J. M.
If this question can be reworded to fit the rules in the help center, please edit the question.

Did searching for "interpolate" or "interpolation" in the documentation not give any results? – R. M. Mar 5 '13 at 2:19
@rm-rf Yes, but I want Interpolate[{Lena, Toady}] and it doesn't work – Dr. 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! – Dr. belisarius Mar 5 '13 at 13:01

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 '14 at 17:46

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

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

-

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]


-

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.

-