'**************************************************************************************** 'NAME: Public Function LinearInterpolation(ScaleX() As Single, ScaleY() As Single, ByVal x As Single) As Single 'FUNCTION: 根据样点求x值的分段线性插值 'Parameter: ScaleX:样点x维数组,ScaleY:样点y维数组,x:待求插值的参数值 'RETURN: 返回x值的分段线性插值 '**************************************************************************************** Public Function LinearInterpolation(ScaleX() As Single, ScaleY() As Single, ByVal x As Single) As Single Dim i, j As Integer For j = 0 To UBound(ScaleX) - 1 If x >= ScaleX(j) And x <= ScaleX(j + 1) Then i = j GoTo a End If Next If x > ScaleX(UBound(ScaleX)) Then i = UBound(ScaleX) - 1 Else i = 0 End If If UBound(ScaleX) = 0 Or UBound(ScaleY) = 0 Then If x = ScaleX(0) Then LinearInterpolation = ScaleX(0) Else LinearInterpolation = 0 End If Exit Function End If a: LinearInterpolation = ScaleY(i) * (x - ScaleX(i + 1)) / (ScaleX(i) - ScaleX(i + 1)) + ScaleY(i + 1) * (x - ScaleX(i)) / (ScaleX(i + 1) - ScaleX(i))
用户377235 2012-10-13 08:23
谢谢