Hi there,
The last line wil not work below why is this?
I have tried it on an excel worksheet and it works there?
Also how can I return an array from a function. Is is possibel to retuern more than one array from a function?
Code:Function bSpline(y As Range, xIn As Range, steps As Integer, Optional aIn As Variant) As Double Dim V() As Double Dim n As Integer, i As Integer, j As Integer, l As Integer Dim a As Variant Dim x() As Double Dim B1() As Double Dim B2() As Double Dim B3() As Double Dim B4() As Double ReDim B1(steps) ReDim B2(steps) ReDim B3(steps) ReDim B4(steps) Dim f As Variant f = y.Value Dim k As Variant k = xIn.Value n = UBound(k) - LBound(k) - 4 ReDim V(n, n) If IsMissing(aIn) Then V(0, 0) = 1 V(0, 1) = -2 V(0, 2) = 1 For i = 1 To n - 1 V(i, i - 1) = 1 / 6 V(i, i) = 2 / 3 V(i, i + 1) = 1 / 6 Next i V(n, n - 2) = 1 V(n, n - 1) = 2 V(n, n) = 1 a = Application.WorksheetFunction.MMult(Application.WorksheetFunction.MInverse(V), f) Else a = aIn.Value End If For j = 1 To 4 ReDim x(steps) x(0) = k(j + 3, 1) For l = 1 To (steps - 1) x(l) = ((k(j + 4, 1) - k(j + 3, 1)) / steps) * l + k(j + 3, 1) Next l x(steps) = k(j + 4, 1) For i = 1 To steps B1(i) = Basis(x(i), j, 4, xIn) B2(i) = Basis(x(i), j + 1, 4, xIn) B3(i) = Basis(x(i), j + 2, 4, xIn) B4(i) = Basis(x(i), j + 3, 4, xIn) Next i bSpline = Application.WorksheetFunction.MMult(B1, a(j, 1)) Next j End Function




Reply With Quote