Routine for linear interpolation on a grid
Question
Write a function that, given increasing nodes with values , returns a linearly interpolated value at a query point .
Short answer
Find the bracketing interval, then blend linearly. Binary-search for in and return . Validate sorted, distinct nodes and decide a policy outside the grid (flat extrapolation, linear extrapolation or an error).
Adapted from Joshi, Denson & Downes, Quant Job Interview Questions and Answers, Q5.16, p.158; question and answer rewritten by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solution