Monday, January 12, 2009

How To Buy Alltunes Credit

Linear interpolation


the other day Internet!
searched and searched and not yet found, and then self-made:

have for creating linear interpolation as a bulk operation in the Excel spreadsheet I made the following function. This can be used freely. I am not liable for any errors, if ye be improved, I would be thrilled commented on the source code and look better.



======================== Beginning =======================

  • interpolated 'a point from a table of x, y points by the method of linear interpolation
  • Function Interpol_Lin (Xin As Range, Yin As Range Xtarget As Double)
  • Dim n%,% ny 'Xin and Yin Counter
  • Dim i%, X_index' loop counter

  • ny = Yin.Cells.Count
  • n = Xin.Cells.Count

  • 'Check whether the same number x and y points is given
  • If n ny <> Then
  • Interpol_Lin = CVErr (xlErrRef) 'Uneven counts of Xin and Yin "
  • GoTo err_ret
  • End If

  • ReDim x (1 To n) As Double
  • ReDim Y (1 To n) As Double

  • 'abundance x [] and y [] to
  • For i = 1 To n
  • x (i) = Xin (i)
  • Y (i) = yin (i)
  • Next i
  • i = 1

  • find 'the correct interval
  • Do While (Xtarget> x (i))
  • X_index = i
  • i = i + 1
  • Loop

  • Interpol_Lin = (Y (X_index + 1) - Y (X_index)) / (x (X_index + 1) - x (X_index)) * (Xtarget - x (X_index)) + Y (X_index)

  • err_ret:

  • End Function
======================== =================== END ====

greeting Chiochip

0 comments:

Post a Comment