-2

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)?

Artur_Indio
  • 736
  • 18
  • 35
  • Something like GDI+? Which Delphi version are you using? That's an important tag for questions about something "in Delphi" because 2009+ has GDI+ built-in. If under 2009, you can still find other third-party libraries, or wrap the API yourself. – Jerry Dodge Mar 04 '15 at 01:22
  • Is GDI+ a graphic library to C++/C#? I want to do something more simple, a numeric linear interpolation, I will edit the question. – Artur_Indio Mar 04 '15 at 01:26
  • GDI+ is a Windows API. So it can be used from any language that compiles to Windows. http://www.bilsen.com/gdiplus/index.shtml – Jerry Dodge Mar 04 '15 at 01:27
  • @Jerry GDI+ is a graphics library. Linear interpolation is a mathematical algorithm. – David Heffernan Mar 04 '15 at 05:41
  • @David I apparently misinterpreted it, thinking it was related to linear drawing. I need to pay better attention. – Jerry Dodge Mar 04 '15 at 06:10
  • Thinking better my question is off-topic, sorry for that. Off-topic's questions must be deleted? – Artur_Indio Mar 04 '15 at 12:22
  • @Artur It's fine. The question might get deleted by mods. Probably not. You've got a nice answer though. No harm here. Thanks for thinking about this issue. – David Heffernan Mar 04 '15 at 12:46

1 Answers1

3

Linear interpolation of 1D-data is very simple:

  • Find such index in X-array, that 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])
    
MBo
  • 77,366
  • 5
  • 53
  • 86