# Lesson 3 - What are Arrays and Why Do We Need Them?

In many models, you will want to create and manipulate elements that represent collections, rather than individual items. For example, you may want to create an element that represents a company's revenue for each of five different divisions, or an element that represents the salmon population in each of 20 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, 20 elements representing salmon populations).

Such an approach, however, has two disadvantages:

• It could require you to create a very large number of elements (e.g., if you wanted revenues for 25 divisions 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 20 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, and increases the likelihood of errors.

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 element that represented the salmon populations in each of a number of streams:

You could also create a matrix element that represented the historic salmon population in each of the streams over a period of three historic years:

Most importantly, 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, 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.

If you did not use arrays to carry out this calculation, rather than creating 2 elements, you would need to create 40 elements (20 Data elements and 20 Expression elements) to accomplish the same thing!

Vectors and matrices are applicable to many kinds of systems, and you will likely want to take advantage of this feature in many of your models. When using the Contaminant Transport Module, however, the use of vectors is essential (i.e., required).  In particular, as we shall see, the Contaminant Transport Module adds a number of specialized elements to GoldSim, and for most of these elements, a number of the inputs and outputs are vectors. This is because when using the Contaminant Transport Module, you will typically be interested in modeling multiple contaminants or solutes (referred to as species). Instead of modeling each species separately (which would quickly become very cumbersome, particularly if you were modeling tens of species, which is not uncommon), they are handled by GoldSim together as a vector of species.  For example, the initial mass of contaminants at various locations in an environmental system is entered as vectors of species, and the predicted concentrations throughout the system is computed as vectors of species.

We will return to this and discuss it in great detail in subsequent Units.  For the remainder of this Unit, however, we will focus on the basics of creating and manipulating vectors.

Because the Contaminant Transport Module requires use of vectors but not matrices, we will not discuss matrices further in this Course.  If you are interested, you can learn more about matrices in GoldSim Help.