Spring 2009

Newsletter Home | Contact | GRC

 

 

 

Modeler's Corner

Vector and Matrix Constructor Improvements in Version 10

Andrew Burns
GoldSim Technology Group
aburns@goldsim.com

Often it's necessary to assemble scalar values into vectors and scalar values and vectors into matrices. In versions prior to GoldSim 10, this could only be done at time zero using static values. This meant that array manipulation often required using an external DLL or spreadsheet.

The new version permits you to use both static and dynamic values within vector constructors. In the accompanying model to this article (which you can download here) you'll see the following example in the Dynamic_Values container:

 

In this example, a static Data element output, a Stochastic element resampled daily, and an Expression element (equal to e^(1/(ETime|d|+1))) are combined together into a three element vector using the following equation:

Vector(ThreeLabels, Data, Stochastic, Expression)

If we plot the output of the CreateVector element we can see that the dynamic values are updated throughout the simulaton:

The new constructors also allow you to combine vectors into matrices. In the model, this is shown in the Vector_to_Matrix container. Here I've created three vectors with 4 elements (Vector 1 is equal to [1, 2, 3, 4], Vector 2 is equal to [10, 20, 30, 40] and Vector 3 is equal to [100, 200, 300, 400]. These are combined into a 3 row, 4 column matrix in the Three_by_Four element using the following Matrix constructor:

Matrix(ThreeLabels, FourLabels, Vector1, Vector2, Vector3)

The result is the following:

We can combine the same vectors into a 4 row, 3 column matrix in the Four_by_Three element using the following Matrix constructor:

Matrix(FourLabels, ThreeLabels, Vector1, Vector2, Vector3)

The result is the following:

Version 10 also adds two special operators, row and col which can be used within the vector constructor. Two examples of this are shown in the Row_Col container.

The first example, UpperTriangular, creates an upper triangular matrix of 1's. The following expression is used:

Matrix(ThreeLabels, ThreeLabels, if(col>=row, 1, 0))

The result looks like this:

The second example, EvenZeros, creates a 4x4 matrix with 1's in the odd rows only. The following expression is used:

Matrix(FourLabels, FourLabels, if(row mod 2 = 0, 0, 1)

In this case, the result is as follows:

Note that in both cases, the 1 could have been replaced with a link to an element's output (dynamic or static).

More documentation on vector and matrix constuctors can be found under the topic Defining Arrays in an Input Field Using Array Constructor Functions in the GoldSim User's Guide and in the online help.

Suggestions?

Do you have any suggestions for future Modeler's Corner articles? If so, we'd love to hear from you. Please contact us at support@goldsim.com.