Lesson 7 – Exercise: Creating and Manipulating Vectors
We are now ready to do our first Exercise. We are going to start by creating a new model.
In this very simple Exercise, we are going to carry out some calculations on a collection of farm fields. In particular, we will assume that we have four fields (named North, South, East and West). The dimensions of the fields are as follows:
|Field||Length (m)||Width (m)|
Given this, we would like to create elements that display/calculate the following:
- The length of the East field;
- The area of each field;
- The total area of the fields (there are two alternative ways to do this; one obvious and one that is not so obvious);
- The mean area of the four fields;
- The area of the field with the maximum area; and
- The item number (1, 2, 3 or 4) of the field with the maximum area (i.e., which item in the Array Label set that you will create to represent the four fields).
There is nothing dynamic in this model, so there is no reason to run it. You just need to create the various elements and will be able to view results by holding the cursor over elements to view tool-tips.
To create this very simple model, you will need to start by creating an Array Label set (with four items, one for each field), and two vectors (one for the Length, and one for the Width). The calculations can all be carried out using Expression elements.
Stop now and try to build the model.
Once you are done with your model, save it to the “MyModels” subfolder of the “Contaminant Transport Course” folder on your desktop (call it ExerciseCT1.gsm), as we will build upon this in a later Lesson. If, and only if, you get stuck, open and look at the worked out Exercise (ExerciseCT1_Vectors.gsm in the “Exercises” subfolder) to help you finish the model.
Let’s quickly walk through the model now.
As pointed out above, your first step should have been to create an appropriate Array Label set. It should look something like this:
You then should have created two vectors (for Length and Width). Here is the Length:
Note: You could have also created these using the vector constructor function.
All of the calculations can then be carried out using Expression elements:
Length of the East field
This scalar value can simply be referenced as follows:
Area of each field
We can calculate the area of each field as follows (this result, of course, is itself a vector):
Note, of course, that the Display Units are for an area.
There are two ways to compute the total area (a scalar), and both use an array function. The first is to simply use a function to sum the items of the Area vector:
The second is a bit trickier. It turns out that given a Length and a Width vector, the total area can be calculated by taking the dot product (also referred to as the scalar product) of the two vectors. GoldSim provides a function for calculation the dot product:
The final three calculations can all be carried out using array functions. All three are scalars.
The mean area of the four fields is:
The area of the field with the maximum area is:
The item number (1, 2, 3 or 4) of the field with the maximum area is:
In this case, it returns the item in the Array Label set that corresponds to the largest area. In this example, the fourth item (West) has the largest area, so the function returns the unitless scalar value 4.
You should now be fairly comfortable creating and manipulating vectors. In the next Lesson, we will talk a bit more about how vectors can be used, and will describe how we can view them in results (such as Time Histories and Distributions).