Computing the Integral or Derivative of a 1-D Lookup Table

In some cases, you may want to compute the integral or derivative of the function defined by a Lookup Table.

To implement these, you can add a second argument to the table function:

Tablename(Row Variable, TBL_Derivative): This returns the derivative of the function at the specified row value.

Tablename(Row Variable, TBL_Integral): This returns the integral of the table function up to the specified row value.

Tablename(Result Variable, TBL_Inv_Integral): This returns the row value corresponding to a specified integral for the table result (the result variable).

For example, if you had a Lookup Table (named Volume) in which the independent variable was a length and the dependent variable was a volume, then the following expression would return the derivative of the corresponding function (an area) when the independent variable was 5 m:

   Note: These arguments can only be used with 1-D tables.  They cannot be used by 2-D and 3-D tables.

The best way to illustrate how these functions are calculated is to consider a simple example.  Consider the following 1-D Table (named “Volume), in which the independent variable has dimensions of length and the dependent variable has dimensions of volume:

Computing the Derivative

The plot below shows how GoldSim would compute Volume(X, TBL_Derivative) for different values of X:

Several points should be noted:

   For TBL_Derivative, the dimensions of the input argument must be that of the Independent Variable.  The dimensions of the output of the function are Dependent Variable dimensions / Independent Variable dimensions.  In this example, since the Independent Variable was a length and the Dependent Variable was a volume, the result of the function has dimensions of an area.

   If the input is outside of the range of the table, the function returns the value at the edge of the table (regardless of the Handling of Data Outside Bounds field setting). 

   The derivative function always returns a value of zero if the table’s Interpolation is set to “Next lower”.

   The derivative function returns an error if the Interpolation is set to “Exact only”.

Computing the Integral

The plot below shows how GoldSim would compute Volume(X, TBL_Integral) for different values of X:

Several points should be noted:

   For TBL_Integral, the dimensions of the input argument must be that of the Independent Variable. The dimensions of the output of the function are Independent Variable dimensions * Dependent Variable dimensions.  In this example, since the Independent Variable was a length and the Dependent Variable was a volume, the result of the function has dimensions of length4.

   The integral function integrates from the start of the table up to the lesser of the given argument and the end of the table.  If the argument is less than the first row value for the table, the function returns zero.

   If the input is outside of the range of the table, the function returns the value at the edge of the table (regardless of the Handling of Data Outside Bounds field setting). 

   The integral function returns an error if the Interpolation option is set to “Exact only”.

Computing the Inverse Integral

The plot below shows how GoldSim would compute Volume(X, TBL_Inv_Integral) for different values of X:

Several points should be noted:

   For TBL_Inv_Integral, the dimensions of the input argument must be Dependent Variable dimensions * Independent Variable dimensions.  In this example, since the Independent Variable was a length and the Dependent Variable was a volume, the dimensions of the input argument must be length4. The dimensions of the output of the function are those of the Independent Variable.

   If the input (the integral) is outside of the range produced by the table’s inputs, the function returns the value at the edge of the table (regardless of the Handling of Data Outside Bounds field setting).  For example, in the example provided above, a value of 15m (the last data point in the table) corresponds to an integral value of 395m4.  As a result, if the first argument to Table(X, Inv_Integral) was greater than 395m4, the function would return 15m.  

   If the integral of the table is non-monotonic, the inverse integral returns the lowest value whose integral matches the argument.

   The inverse integral function returns an error if the Interpolation option is set to “Exact only”.

One practical application of the use of these functions is when creating tables that describe how the surface area, volume and water elevation in a pond or reservoir are related. In these kinds of problems, you often would compute the volume, and then use a table to output the surface area and elevation corresponding to that volume. One way to do this in a consistent way using the table functions would be to define a table (named, say, Area_from_Elevation) that outputs the surface area as a function of the water elevation (i.e., the independent variable would be elevation and the dependent variable would be surface area).  Given a volume (V), you could then use this table to compute the elevation and surface area as follows:

Elevation = Area_from_Elevation(V, TBL_Inv_Integral)

Surface_Area = Area_from_Elevation(Elevation)

An example model which illustrates these functions (TableFunctions.gsm) can be found in the General Examples/LookupTable folder in your GoldSim directory (accessed by selecting File | Open Example... from the main menu).

Related Topics…