|
Objectives:
Constants and Functions:
A constant in a model can take on only one single value throughout the duration of
the simulation, for example, a constant birth rate. But what if we were simulating a
time period that included a war such that the birth rate had one value during the period
of the war and a different value during peace-time? The "IF THEN ELSE" function
is used when there is a variable in the model that can take on exactly two different values.
Create this model and save it as Account1(similar to Saving1 from lab 1)
Using "IF THEN ELSE"
Save this model as Account1IF.
Using a Compound "IF THEN ELSE"
(Just read this part)******************
Now, let's use an IF-THEN-ELSE in a little more complicated situation. Say that we are modeling
the situation where the interest rate is .03 up until 2001, is .04 during 2001 and 2002,
and then reverts back to .03 after 2002. (Don't be concerned about why this might happen--it's
just an example.)
So, before January 1, 2001 and after December 31, 2002 the interest rate is .03. From January 1, 2001
to December 31, 2002 the interest rate is .04. We still have only two possible values for the interest rate so we can use an IF-THEN-ELSE. But, how do we formulate the condition?
Note that if the year is both greater than 2000 and is less than 2003 the interest rate is .04
and otherwise it is .03. The condition can be stated as:
year > 2000 AND year < 2003
In Vensim we use the Time shadow variable for the year, so...
The ":AND:" can be selected from the MORE tab...
Lab will tell you how to use below!!
**********************************************************************************************************
Using "IF THEN ELSE" to Increase Realism of a Model:
In a previous lab you worked with a model of drug absorption that was
less than realistic in that in the simulation the variables for "ingesting"
and "absorption" took on negative values. Let's use the IF THEN ELSE function
to improve the realism of the model.
Begin by loading the "Drug_Goal" model you save previously.
Modify the equation for "Dosage Gap" to make it equal to the goal minus the
level of drug in the bloodstream when the goal is greater than the amount of
drug in the bloodstream and zero otherwise.
Also modify the equation for "Absorbing" to calculate its value when the
concentration in the stomach is greater than the concentration in the
bloodstream and to assign a value of zero otherwise.
Now run a simulation and look at the graph for each variable.
Using a Lookup Table
We have learned to use the "IF THEN ELSE" function to model
a situation where an auxiliary variable takes on exactly two different
values during a simulation.
Now, what if we were modeling a situation in which a variable could take on not one, or
two values, but three or more different values over the course of the simulation. In
that case Vensim allows us to specify all the possible values in a table.
The simulation will then pick the approriate value from the table each time period
as the simulation progresses from one time period to the next. Of course, there must be some basis
for selecting a particular value from the table, so that means that each row of
the table will contain two columns.
One column contains the values of the variable of interest and the
other is used to locate the appropriate value for each time period.
Load the Account1IF model you saved previously in this lab.
Let's change the above model so that the interest rate is
3 percent on balances below $500, 5 percent between $500 and $1,000,
and 7 percent for $1,000 and above. Now that there are three values for the interest
rate the "IF THEN ELSE" function can not be used.
Stated as a table, we have:
Now let's create a table for our model and enter the values for Interest Rate.
First, we need to restate the table as two columns of numbers. So, think of the
table above in terms of three sentences.
The system will extend the last straight line to find
an interest rate for values higher than those in the table. So, .07 will be used for balances of $1,000, $3,000, $10,000, $12,000, etc. (all values of $1,000 or higher). Without the forth point the straight line from $500 to $1,000 would be extended for balances above $1,000 which would give interest rates over 7 percent.
To get discrete values we will have to specify a step function. Enter the
following values in the table.
Save this model as Savings_Lookup1. We will modify this program later in
this lab.
Shadow Variables
Shadow variables are used in two ways. First they are used to simplify a diagram
when one variable is to be connected to another variable for
which there is no direct path to draw an arrow. A shadow variable with the
same name as one of the two variables that are to be connected
is placed in a location near the second
variable and then the connection is made between the shadow variable and
the second variable.
The second way a shadow variable can be used is to add some special system
variables to a diagram. The variable "Time" is one of the system variables.
Time is often used with the "Lookup" function to select a value from the
table.
To add a shadow variable to a diagram:
Shadow Variables and Lookup Functions:
Let's modify a model to use a shadow variable as the
locator variable in a Lookup function. In this example the interest
rate will not vary depending on the account balance but, rather, the
interest rate will increase over time.
Load "Savings_Lookup1" that you saved previously.
Drawing Flow Arrows:
To draw a double-headed arrow, first draw a one-headed arrow. Then
Click on the Arrow or the Move/Size icon and right Click on the
small circle at the end of the flow arrow that you wish to add an
arrowhead to.
The following window will be displayed.
Click the "Arrowhead" box in the upper left corner and Click OK.
That's it, you now have a double-headed arrow.
Try drawing the Momentum-Force diagram now.
To draw a flow arrow in segments, hold down the shift key as you move the mouse to draw
the arrow. At each point where you want to change directions, Click once
and then draw the next segment. Note that Vensim will only draw straight
horizontal or vertical segments.
Try drawing the above diagram now.
Submit the model (Momentum.mdl) to Blackboard.
This is the end of the lab exercise.
|