Results 1 to 2 of 2

adjusting code to accept data in row format

Threaded View

  1. #1
    Registered User
    Join Date
    12-19-2007
    Posts
    4

    adjusting code to accept data in row format

    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
    Attached Files Attached Files
    Last edited by Cutter; 08-16-2012 at 09:42 PM. Reason: Added code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1