I have an array with data:
X Y
3 50
5 60
9 120
11 130
18 90
20 150
The data is entirely non-linear. X is guaranteed to be sorted.
Now for any given value, I'd like to have linear interpolation between the numbers (so for example, 3 => 50, 4 => 55, 5 => 60). A bilinear interpolation would be even nicer, but I'm keeping my expectations low.
Best Answer
This script will do the same (plus a little bit more).
Code
Explained
In the beginning of the script, there's a small error handling. After that it will find the first lowest entry compared to the input value. Once found, it will does some math and present the result.
Note
If the selected value equals 20, the script returns 150 as where the formula yields
#DIV/0
.Screenshot
Formula
Use the following formula to take in account all values
Example
Add the script under Tools>Script editor and press the save button (no authentication needed).
I've created an example file for you: How to interpolate data in a range in Google Sheets