I need to make a simple numeric linear interpolation in Delphi, was thinking of implementing a function, but then thought better and I think that should already be some library. I found nothing on google.
My problem is simple, I have a dataset with X and Y data, and other new dataset X data (Xb) that will be the basis for finding new Y data (Yin) interpolated.
In R, for example, have a function approx
that accomplishes this easily. This function also allows Xb length is of any size.
Yin <- approx (X, Y, Xb, method = "linear")$y
There is some statistical library to do this in Delphi? Or continue to write my function (based on approx
)?
Linear interpolation of 1D-data is very simple:
X[i] <= Xb < X[i+1]
(binary search for case of random access, linear search for case of step-by step Xb changing)
Calculate
Yb = Y[i] + (Y[i+1] - Y[i]) * (Xb - X[i]) / (X[i+1] - X[i])