Hi
I have a very nice bit of code that interpolates between point on graphs with a smoothed line. The code is called cubic spline and it is extremely useful for all types of applications, finance through to engineering.
However, the code has been set up to only take data in rows rather than columns and i need to use it to take data in row format. The code calls other functions in its workings but this is the high level code. Is there an obvious way to make it accept data in row format? XX, and YY are the variables for the ranges of data in column format. I attach a simple excel sheet demonstrating the problem with the full code.
Worthdownloading just for the code.
thanks
t
Function cubspline(Metode As Integer, xi As Double, xx As Object, yy As Object) As Double
Dim i As Integer
Dim yi As Double
Dim x() As Double
Dim y() As Double
Dim y2() As Double
Dim j As Integer
If Metode = 1 Then
'Numerical Recipes are 1 based
j = 0
Else
'Others are 0 based
j = -1
End If
For i = 1 To UBound(xx())
If yy(i) <> "" Then
j = j + 1
ReDim Preserve x(j)
ReDim Preserve y(j)
x(j) = CDbl(xx(i))
y(j) = CDbl(yy(i))
End If
Next i
If Metode = 1 Then
'NR cubic spline
'Get y2
ReDim y2(1 To UBound(x()))
Call spline(x(), y(), UBound(x()), 10 ^ 30, 10 ^ 30, y2())
'Get y
Call splint(x(), y(), y2(), UBound(x()), xi, yi)
ElseIf Metode = 3 Then
'Own cubic spline
yi = SplineX3(xi, x(), y())
End If
'Return
cubspline = yi
End Function
Bookmarks