Array Functions

Most of the built-in functions in GoldSim can also operate on arrays. In most cases, these functions carry out the operation term-by-term and produce an array of the same order as the input argument. For example, if A was a vector based on the set “Days”, C=sin(A) would also produce a vector based on the set “Days”. The first item of C would be the sine of the first item of A, the second item of C would be the sine of the second item of A, and so on.

Several functions (max, min, mod, tdist, tprob, bess, beta) accept multiple array arguments.  For these functions, the arguments must all be scalars, or must be arrays of the same order that  are defined using the same set of array labels. GoldSim carries out the operation term-by-term and produces an array of the same order. For example, if A was a vector based on the set “Days”, and B was a vector based on the set “Days”,  C=min(A, B) would also produce a vector based on the set “Days”. The first item of C would be the minimum of the first item of A and the first item of B; the second item of C would be the minimum of the second item of A and the second item of B, and so on.

Two specialized functions (occurs and changed) cannot accept arrays as arguments.

If X and Y are arrays (of the same order and using the same set of array labels), the If(C, X, Y) function can manipulate the arrays in two different ways:

   If C is a scalar condition, the output of the If function is either the array X (if C is true) or the array Y (if C is false).

   If C is an array (of the same order and using the same set of array labels as X and Y), GoldSim will carry out a term-by-term if,then computation to produce the output array.  That is, if the first item of C is true, the first item of the output would be equal to the first item of X, otherwise it would be equal to the first item of Y, and so on.

In addition to the standard functions mentioned above, GoldSim also provides a wide variety of special array functions which allow you to manipulate arrays (accessible from the context menu for an input field).

These special array functions are listed below:

 

Function

Description

Result

GetItem(VC,n)

Returns the nth item in the vector.

scalar

 

GetItem(MC,n, m)

Returns the item in the nth row and mth column of the matrix.

scalar

GetRow(VC,n)

Returns the nth item in the vector. (If first argument is a vector, this function is identical to GetItem).

scalar

GetRow(MC,n)

Returns the nth row of the matrix.

vector

GetColumn(MC,m)

Returns the mth column of the matrix.

vector

GetRowCount(VC)

Returns the number of items in the vector.

scalar

GetRowCount(MC)

Returns the number of rows in the matrix.

scalar

GetColumnCount(MC)

Returns the number of columns in the matrix.

scalar

sumv(VC, X)

Sums the items of the vector.  If the arguments are conditions, ORs the conditions. X is optional. If positive, the calculation is applied to the first X terms; if negative, the calculation applies to the last X terms. X is ignored if 0 or greater than array size.

scalar

prodv(VC, X)

Computes the product of the items of the vector. If the arguments are conditions, ANDs the conditions. X is optional. If positive, the calculation is applied to the first X terms; if negative, the calculation applies to the last X terms. X is ignored if 0 or greater than array size.

scalar

minv(V)

Computes the smallest item in the vector.

scalar

maxv(V)

Computes the largest item in the vector.

scalar

meanv(V)

Computes the mean of the items in the vector.

scalar

sdv(V)

Computes the standard deviation of the items in the vector.

scalar

rowmin(V)

Computes the index of the smallest item in the vector (i.e., 1, 2, 3, etc.).

scalar

rowmax(V)

Computes the index of the largest item in the vector (i.e., 1, 2, 3, etc.).

scalar

sort123(V)

Sorts the items in the vector from smallest to largest.

vector

sort321(V)

Sorts the items in the vector from largest to smallest.

vector

dot(V1,V2)

Dot (inner) product of V1 and V2. The first vector is assumed to be a row vector and the second vector is assumed to be a column vector. The two vectors must be based on the same set of array labels.

scalar

vvmatrix(V1,V2)

Vector multiplication (to produce a matrix).The first vector is assumed to be a column vector and the second vector is assumed to be a row vector.  This is equivalent to vector multiplication of V1 by the transpose of V2.

matrix[A,B], where A is the set of array labels for V1 and B is the set of array labels for V2

vIndex(V1,X)

Vector lookup. The second argument must be a value (with the same dimensions as the vector).  It searches for the specified value within the provided vector, and returns a 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.

scalar

vInterp(V1,n)

Vector interpolation. The second argument must 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).

scalar

sumr(MC, X)

Sums the items across each row of the matrix. If the arguments are conditions, ORs the conditions. X is optional. If positive, the calculation is applied to the first X terms; if negative, the calculation applies to the last X terms. X is ignored if 0 or greater than array size.

vector[A], where A is the set of array labels for the rows in the original matrix

prodr(MC, X)

Computes the product of the items across each row of the matrix. If arguments are conditions, ANDs the conditions. X is optional. If positive, the calculation is applied to the first X terms; if negative, the calculation applies to the last X terms. X is ignored if 0 or greater than array size.

vector[A], where A is the set of array labels for the rows in the original matrix

minr(M)

Computes the smallest item in each row of the matrix.

vector[A], where A is the set of array labels for the rows in the original matrix

maxr(M)

Computes the largest item in each row of the matrix.

vector[A], where A is the set of array labels for the rows in the original matrix

meanr(M)

Computes the mean of the items in each row of the matrix.

vector[A], where A is the set of array labels for the rows in the original matrix

sdr(M)

Computes the standard deviation of the items in each row of the matrix.

vector[A], where A is the set of array labels for the rows in the original matrix

sumc(MC, X)

Sums the items down each column of the matrix. If the arguments are conditions, ORs the conditions. X is optional. If positive, the calculation is applied to the first X terms; if negative, the calculation applies to the last X terms. X is ignored if 0 or greater than array size.

vector[B], where B is the set of array labels for the columns in the original matrix

prodc(MC, X)

Computes the product of the items down each column of the matrix. If the arguments are conditions, ANDs the conditions. X is optional. If positive, the calculation is applied to the first X terms; if negative, the calculation applies to the last X terms. X is ignored if 0 or greater than array size.

vector[B], where B is the set of array labels for the columns in the original matrix

minc(M)

Computes the smallest item in each column of the matrix.

vector[B], where B is the set of array labels for the columns in the original matrix

maxc(M)

Computes the largest item in each column of the matrix.

vector[B], where B is the set of array labels for the columns in the original matrix

meanc(M)

Computes the mean of the items in each column of the matrix.

vector[B], where B is the set of array labels for the columns in the original matrix

sdc(M)

Computes the standard deviation of the items in each column of the matrix.

vector[B], where B is the set of array labels for the columns in the original matrix

trans(MC)

Transpose of matrix.

trans(MC1[A,B]) = MC2[B,A]

matrix[B,A], where A is the set of array labels for the rows in the original matrix and B is the set of array labels for the columns

inv(M)

Inverse of matrix.

inv(M1[A,B]) = M2[B,A]

matrix[B,A], where A is the set of array labels for the rows in the original matrix and B is the set of array labels for the columns

mult(M1,M2)

Matrix multiplication. The columns of the first matrix must be based on the same set of array labels as the rows of the second matrix.

Mult(M1[A,B] , M2[B,C]) = M3[A,C].

matrix[A,C], where A is the set of array labels for the rows in matrix M1 and C is the set of array labels for the columns in matrix M2

mult(M,V)

Matrix times vector. The vector is automatically treated as a column vector. The vector must be based on the same set of array labels as the columns of the matrix.

Mult(M[A,B] , V[B]) = V[A]

vector[A], where A is the set of array labels for the rows in matrix M

mult(V,M)

Vector times matrix. The vector is automatically treated as a row vector. The vector must be based on the same set of array labels  as the rows of the matrix.

Mult(V[A] , M[A,B]) = V[B]

vector[B], where B is the set of array labels for the columns in matrix M

V, V1, V2: Vector of values
VC: Vector. Can be value or condition.
M, M1, M2: Matrix of values
MC, MC1, MC2: Matrix. Can be value or condition.
X: Scalar value.
n,m: a dimensionless value; can be specified as a number, equation or a link. Real values are rounded to the nearest integer.

Note that the GetItem, GetRow, and GetColumn functions can, in most cases. more easily be implemented by referencing items of an array directly using variables.  That is, if A was based on a named set or an indexed set that started with 1, GetItem(A, X) is identical to A[X].

Note, however, that in his example, if A was an indexed set that did not start with 1, GetItem(A, X) would not be identical to A[X].  GetItem(A,X) would return the Xth row.  A[X] would return the item whose label was X.  These are only the same if the indexed set starts with 1.

Another difference is that the first argument of the GetItem, GetRow and GetColumn functions can itself be an expression.  To implement this using arrays with variable arguments would therefore require you to create a second element.  That is, to reproduce this expression:

GetItem(A * B, X),

you would first need to create a vector C = A*B, and then reference C[X].

Related Topics…

Learn more about: