Manipulating Vectors and Matrices
Lesson 5, page 6 of 15
In many systems, you will want to create and manipulate elements The basic building blocks with which a GoldSim model is constructed. Each element represents a feature, pararamer, process or event in the model. that represent collections of data, rather than individual items. For example, you may want to create an element that represents your company's revenue for each of five separate divisions, or an element that represents the salmon population in each of a number streams.
One way to do this, of course, would be to create separate elements for each object you wanted to model (e.g., five elements representing revenue, 13 elements representing salmon populations in different streams). Such an approach, however, is not desirable for two reasons:
- It could require you to create a very large number of elements (e.g., if you wanted revenues for 100 subgroups or wanted to evaluate salmon populations in 200 streams). This could result in very large, cluttered models.
- Usually, you will want to carry out the same types of calculations and operations on all related objects in such a collection (e.g., multiply all revenues by 2, compute the number of salmon eggs this year for all streams based on the current salmon population). Having to do this individually for every object in a large collection would be very cumbersome and time-consuming.
To address these kinds of problems, GoldSim allows you to create and manipulate vectors and matrices (collectively referred to as arrays). For example, you could create a vector A one-dimensional array. Data element An Input element that allows you to specify a constant scalar value or array of values. that represented the salmon populations in each of 13 streams, as shown below:
You could also create a matrix A two-dimensional array. Data element that represented the salmon population in each of 13 streams for a period of 3 years, as shown below:
In addition to adding data in the form of vectors and matrices, you can manipulate these arrays in equations. For example, you could create an Expression element A Function element that produces a single output by calculating user-specified mathematical expressions., and define it as:
2 * Salmon_Population
The output of the Expression would be an array, identical to the Salmon_Population array, except each item of the array would be two times greater. Note that if you did not use arrays to carry out this calculation, rather than creating 2 elements, you would need to create 26 elements (13 Data elements and 13 Expression elements) to accomplish the same thing!
If required, you can access a particular item of the array in an equation. For example,
Salmon_Matrix[BearCreek, 1999]
references a single (scalar) value representing the salmon population in Bear Creek in 1999.
GoldSim provides a wide variety of special operators which allow you to manipulate arrays. For example, if the name of the vector was Salmon_Population, the expression
Sumv(Salmon_Population)
would result in a single (scalar) value representing the sum of all items in the vector.