Using a Vector as a Lookup Table

Two array functions are available in GoldSim whose primary application is to allow you to create dynamic lookup tables (in which the values for the independent and/or dependent variables are changing with time). 

Although GoldSim provides a specialized Lookup Table element, this element does not support dynamic tables (all the values must be constant values).

Using the array functions vIndex and vInterp provides a mechanism for creating a dynamic lookup table using a vector.

vIndex(vector, value) requires the first argument to be a vector, and the second argument to be a value (with the same dimensions as the vector).  It searches for the specified value within the provided vector, and returns the dimensionless index at which the value is found. It treats the vector as a continuous function, linearly interpolating where necessary between the defined points in the vector, and as a result, the returned index value is not necessarily an integer.  For example, if the vector’s values were [3m, 4m, 5m, 6m], then vIndex(vector, 5.1m) would return an index value of 3.1.  Similarly, vIndex(vector, 10ft) would return an index value of 1.048. If the array labels are indexed, the appropriate index value is returned; if the array labels are named, the first entry in the array has an index value of 1.

If the value is outside of the range of values in the vector, a fatal error is displayed. If the value exists multiple times in the vector (e.g., a sine function), the first matching value is used.

vInterp(vector, index) requires the first argument to be a vector, and the second argument to be a dimensionless index.  It interpolates into the vector using the specified index value. It treats the vector as a continuous function, linearly interpolating where necessary between the defined values in the vector, and returns a value (with the same dimensions as the vector). For example, if the vector’s values were [3m, 4m, 5m, 6m] then vInterp(vector, 3.1) would return a value of 5.1m.

If the index is outside of the range of indices for the vector, a fatal error is displayed.

These two functions can be used in conjunction to create a dynamic lookup table.  To do so, you would create two vectors using the same array label set, which would typically be indexed (e.g., 1 through 10).  One of the vectors (named VectorInd here) would contain the independent variables, and the other vector (named VectorDep here) would contain the corresponding dependent variables.  The values of these could change dynamically.  At any time, if you wanted to obtain the dependent variable for a particular value of the independent variable (say, X), you could do so using the following expression:

vInterp(VectorDep, vIndex(VectorInd, X))

This would look up the index of X in the vector representing the independent variable and return the corresponding value from the vector representing the dependent variable.

A reverse lookup into the same table could be carried out using this expression:

vInterp(VectorInd, vIndex(VectorDep, Y))

This would look up the location of Y in the vector representing the dependent variable and return the corresponding value from the vector representing the independent variable.

An example model which illustrates how these functions can be used to create dynamic lookup tables DynamicLookup.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…

Learn more about: