Using a Vector as a Lookup
Table
Two array A collection of variables that share common output attributes and can be manipulated in GoldSim elements or input expressions. 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 A type of input element that allows you to define your input in terms of a lookup table (i.e., a response surface)., 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 A one-dimensional array..
vIndex(vector, value) requires the first argument to be a vector, and the second argument to be a value (with the same dimensions An output attribute for an element that defines the dimensionality (in terms of Length, Time and other fundamental dimensions) of the output. 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 A collection of labels identifying the items of an array. 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).
Learn more
- Array Functions
- Copying Array Elements Between Models
- Defining Arrays in an Input Field Using Array Constructor Functions
- Defining Vectors and Matrices Using Data Elements
- Defining Vectors Using Stochastic Elements
- Displaying Final Value Results for Matrices
- Displaying Final Value Results for Vectors
- Elements That Can Manipulate Arrays
- Manipulating Vectors and Matrices with Other Elements
- Referencing an Item of an Array
- Understanding Array Labels
- Using a Vector as a Lookup Table
- Viewing an Array in a Browser or Interface
- Viewing Array Results
- Viewing Results for Arrays
- Viewing Time Histories for Array Outputs
- Viewing Time Histories of Multiple Realizations for an Array