Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Paul,
You can pass the 3D array just the same, and just look at the first dimension, as you did with tyhe first column. I haven't tested this, but I hope I haven't missed anything. Function VLinearInterpolation(T As Double, TRange , _ LRange ) As Double Dim nRow As Integer Dim TLow As Double Dim THigh As Double Dim LLow As Double Dim LHigh As Double 'If at top or bottom, use two points at the end to extrapolate If T < TRange(1, 1) Then nRow = 1 Else For nRow = 1 To UBound(TRange,1) If T = TRange(i, 1) Then Exit For Next nRow If nRow = UBound(TRange,1) Then nRow = nRow - 1 End If End If TLow = TRange(nRow, 1) THigh = TRange(nRow + 1, 1) LLow = LRange(nRow, 1) LHigh = LRange(nRow + 1, 1) VLinearInterpolation = (T - TLow) * (LHigh - LLow) / (THigh - TLow) + LLow End Function -- HTH RP (remove nothere from the email address if mailing direct) "Paul" wrote in message om... Hi Bob, that's probably the solution ... the problem is that I don't know how the assign one dimension of a multidimension array to the function ... if i succeed in naming the specific dimension (of the multidimension array) I can use that name in the interpolation. regards, paul "Bob Phillips" wrote in message ... Paul, You could drop the arrays into a worksheet range, but why don't you pass arrays to the function and process these? Function VLinearInterpolation(T As Double, TRange , _ LRange ) As Double Dim nRow As Integer Dim TLow As Double Dim THigh As Double Dim LLow As Double Dim LHigh As Double 'If at top or bottom, use two points at the end to extrapolate If T < TRange(1) Then nRow = 1 Else For nRow = 1 To UBound(TRange,1) If T = TRange(i) Then Exit For Next nRow If nRow = UBound(TRange,1) Then nRow = nRow - 1 End If End If TLow = TRange(nRow,) THigh = TRange(nRow + 1) LLow = LRange(nRow) LHigh = LRange(nRow + 1) VLinearInterpolation = (T - TLow) * (LHigh - LLow) / (THigh - TLow) + LLow End Function -- HTH RP (remove nothere from the email address if mailing direct) "Paul" wrote in message om... Hi all, Below I have provided the code (Sub bereken_asian_call) for a macro which finally calculates two arrays: O(index,state,a) and F(index,state,a). The range for the a values in this case is 1 to alpha (which is 4 now). Additionally, a new value is calculated called NewAv1. I should now interpolate NewAv1 given the array O(index,state,1 to alpha) and F(index,state,1 to alpha). For that I want to use a function written in VBA called VlinearInterpolation (see below). Therefore, I must therefore to that function within the sub bereken_asian_call. The function is defined as: VlinearInterpolation(value to be interpolated, range 1, range 2) ... In my case range 1 is: O(index,state,1 to alpha) and range 2 is F(index,state,1 to alpha) ... Question is: how should i refer to the VLinearInterpolation function and how do I assign the O(index,state,1 to alpha) and F(index,state,1 to alpha) ranges to range 1, respectively range 2 in the VLinearInterpolation function. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
INDIRECT function to reference a named range | Excel Worksheet Functions | |||
VBA code for find function (reference cell value) | Excel Worksheet Functions | |||
ComboBox AddItem code to reference cells in a Range | Excel Discussion (Misc queries) | |||
A function to get a variable row reference for range in XNPV funct | Excel Worksheet Functions | |||
dynamic range reference and use of common code | Excel Programming |