Interpolate2D





http://www.QuantTools.com
CapeTools Utils function list

Welcome | Documentation format | QuantTools Groups | QuantTools Categories | Licence

Key TAGs | Excel Index | API Index



Given X and Y point values, performs a two dimensional interpolation for the Z value given a Z matrix of data and a XArray and YArray of data headers.



Note: Within Excel, the function is named - CT.INTERP.Interpolate2D




High level graphic of Interpolate2D() function with parameters. Blue square node is the actual function with the parameters ordered.



Parameter Description


  1. XValue parameter

    X value to interpolate.
  2. YValue parameter

    Y value to interpolate.
  3. XArray parameter

    X header values.
  4. YArray parameter

    Y header values.
  5. ZMatrix parameter

    Z matrix of data.
  6. InterpMethod parameter

    Interpolation methodology to utilise. Possible values are : Linear or Cubic.
  7. Extrapolate parameter

    Whether you wish to extrapolate for the Z value, if the X or Y value is not within the XArray or YArray range.


Extended information

Function Syntax

VB Syntax


Double CTUtils.Interpolate2D( _
Double XValue, _
Double YValue, _
Variant XArray, _
Variant YArray, _
Variant ZMatrix, _
InterpEnum InterpMethod, _
Boolean Extrapolate)


Excel Spreadsheet Syntax


=CT.INTERP.Interpolate2D(
Excel Numeric Cell XValue,
Excel Numeric Cell YValue,
XLRange XArray,
XLRange YArray,
XLRange ZMatrix,
Excel String Cell InterpMethod,
Excel Boolean Value Cell Extrapolate)


C++ Syntax


static double Interpolate2D(
double XValue,
double YValue,
CTRangeDataCPP XArray,
CTRangeDataCPP YArray,
CTRangeDataCPP ZMatrix,
InterpEnum InterpMethod,
bool Extrapolate);


DotNET Syntax


System.Double CTUtilsSA.Interpolate2D(
System.Double XValue,
System.Double YValue,
CTRangeData XArray,
CTRangeData YArray,
CTRangeData ZMatrix,
CTIEnums.InterpEnum InterpMethod,
System.Boolean Extrapolate);

Parameter data types

ArgNameArgTypeIsKey
XValueDoubleFALSE
YValueDoubleFALSE
XArrayRangeFALSE
YArrayRangeFALSE
ZMatrixRangeFALSE
InterpMethodInterpEnumFALSE
ExtrapolateBooleanFALSE


Example Inputs

The first column represents the name of the parameters. The second column specifies whether the parameters are optional or not. Finally the last column provides some sample input data.
Function call input string-keys are always in the format : "NAME.EXTTAG.TICKER" The "EXTTAG.TICKER" part is determined from the output of other, capetools, object creation functions.


ArgNameIsOptional (Excel only)Example
XValueFALSE2.5
YValueFALSE3.5
XArrayFALSEInterpolate2D_XArray_Range (creates a range object)
YArrayFALSEInterpolate2D_YArray_Range (creates a range object)
ZMatrixFALSEInterpolate2D_ZMatrix_Range (creates a range object)
InterpMethodFALSELinear
ExtrapolateFALSEtrue


Example range for parameter : XArray

Within Excel, a range such as this can be passed directly into the XArray parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : XArray



CTQL.CTRangeData Interpolate2D_XArray;


double[] arrBInterpolate2D_XArray = {
1.0,
2.0,
3.0,
4.0,
5.0,
6.0,
7.0,
8.0,
9.0  //  Array Data

};

CTQL.DoubleVector arrInterpolate2D_XArray =
new  CTQL.DoubleVector(arrBInterpolate2D_XArray);

// Second parameter determines whether the array is a column array (false) or a row array (true)
Interpolate2D_XArray = new  CTQL.CTRangeData(arrInterpolate2D_XArray, false);


Example range for parameter : YArray

Within Excel, a range such as this can be passed directly into the YArray parameter.


Data is stored within the second column (Vector of data)..

Example C# API usage for setting the range data for parameter : YArray



CTQL.CTRangeData Interpolate2D_YArray;


double[] arrBInterpolate2D_YArray = {
1.0,
2.0,
3.0,
4.0,
5.0,
6.0,
7.0,
8.0,
9.0  //  Array Data

};

CTQL.DoubleVector arrInterpolate2D_YArray =
new  CTQL.DoubleVector(arrBInterpolate2D_YArray);

// Second parameter determines whether the array is a column array (false) or a row array (true)
Interpolate2D_YArray = new  CTQL.CTRangeData(arrInterpolate2D_YArray, false);


Example range for parameter : ZMatrix

Within Excel, a range such as this can be passed directly into the ZMatrix parameter.

1013.8917.7220.0423.5625.8129.8634.4138.33
42.8145.6450.1753.8957.4562.3966.3270.4474.75
78.3381.3985.7588.2292.4796.79100.23103.67108.09
112.43115.05117.95121.71126.65129.31133.34136.72140.5
145.27147.88150.51154.28157.65160.48163.17165.44169.02
172.78177.74179.75183.19187.91192.1196.82200.72203.03
206.3208.91213.46216.66221.58225.08228.18232.82236.82
239.57244.22247.07251.68255.64260.25265.21267.22271.56
274.06276.95281.1286.04290.45295.28298.37301.89304.09

Example C# API usage for setting the range data for parameter : ZMatrix



CTQL.CTRangeData Interpolate2D_ZMatrix = new CTQL.CTRangeData();

System.Text.StringBuilder Interpolate2D_ZMatrix_builder =
new System.Text.StringBuilder(100);

Interpolate2D_ZMatrix_builder.Append("{");
Interpolate2D_ZMatrix_builder.Append("10	 | 13.89	 | 17.72	 | 20.04	 | 23.56	 | 25.81	 | 29.86	 | 34.41	 | 38.33 ;");
Interpolate2D_ZMatrix_builder.Append("42.81	 | 45.64	 | 50.17	 | 53.89	 | 57.45	 | 62.39	 | 66.32	 | 70.44	 | 74.75 ;");
Interpolate2D_ZMatrix_builder.Append("78.33	 | 81.39	 | 85.75	 | 88.22	 | 92.47	 | 96.79	 | 100.23	 | 103.67	 | 108.09 ;");
Interpolate2D_ZMatrix_builder.Append("112.43	 | 115.05	 | 117.95	 | 121.71	 | 126.65	 | 129.31	 | 133.34	 | 136.72	 | 140.5 ;");
Interpolate2D_ZMatrix_builder.Append("145.27	 | 147.88	 | 150.51	 | 154.28	 | 157.65	 | 160.48	 | 163.17	 | 165.44	 | 169.02 ;");
Interpolate2D_ZMatrix_builder.Append("172.78	 | 177.74	 | 179.75	 | 183.19	 | 187.91	 | 192.1	 | 196.82	 | 200.72	 | 203.03 ;");
Interpolate2D_ZMatrix_builder.Append("206.3	 | 208.91	 | 213.46	 | 216.66	 | 221.58	 | 225.08	 | 228.18	 | 232.82	 | 236.82 ;");
Interpolate2D_ZMatrix_builder.Append("239.57	 | 244.22	 | 247.07	 | 251.68	 | 255.64	 | 260.25	 | 265.21	 | 267.22	 | 271.56 ;");
Interpolate2D_ZMatrix_builder.Append("274.06	 | 276.95	 | 281.1	 | 286.04	 | 290.45	 | 295.28	 | 298.37	 | 301.89	 | 304.09");
Interpolate2D_ZMatrix_builder.Append("}");

// Parse the string into the Range object.
Interpolate2D_ZMatrix.RangeFromStr( Interpolate2D_ZMatrix_builder.ToString() );



Example function usage


The C# example below contains all the sub-function calls leading up to this function call. As a result, the example can contain a lot of code.

The VB.NET, J#, C++.NET, Java, Excel VBA, Visual Basic 6 (via COM) and C++ examples below contain function code stubs for the calls leading up to this function call. However, the function call for this function is displayed.
You can easily reproduce the stub functions code from the C# example.


If you are accessing this functrion via the MiniXL libraries, this function is present within the CT.QL.Utils20 MiniXL Excel Addin.

Within our Excel Example Addin Generator, we have used the following QuantTools sub-functions in order to prepare the arguments needed to call the Interpolate2D() function. If you are executing this function via the MiniXL libraries, the module addin name, (in brackets, to the right of the sub-functions listed below), indicates the MiniXL library in which the sub-function is held. You will need to load this library into your Excel session (along with any other libraries that the sub-function call within the addin requires (ie - CT.QT.Utils20 addin in almost all cases) in order for the example to compute successfully.


The following four examples demostrate calling this function within a Microsoft .NET environment

The following four examples demostrate calling this function within a non .NET environment

The following is a sample output from executing the Interpolate2D() function call


93.71

Copyright (c) 2003-2007 CapeTools - All Rights Reserved.