Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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]
share|improve this answer
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,

share|improve this answer

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

Mathematica graphics

share|improve this answer

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]
share|improve this answer

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