A wide variety of primitives allow you to enter equations that determine their values or magnitudes. These equations can be arbitrary mathematical expressions. For instance, take the example of the following complex equation:
Sin(Time*2) + [Alpha]^0.05
This example displays a number of features that the Simgua equation engine supports:
· ‘Time’ refers to the current time as measured in your model’s base time units.
· ‘[Alpha]’ indicates that the equation is for a flow, and refers to the value of the stock that is the start of the flow.
· ‘Sin’ applies the trigonometric sine function.
· ‘+’, ‘*’, and ‘^’ are all standard mathematical operators representing addition, multiplication and exponentiation respectively.
The following table lists some of the important functions support by Simgua’s equation engine and describes them briefly.
Table of Equation engine Functions and variables.
|
Function |
Description |
|
Operators |
|
|
x+y |
Sums x and y. |
|
x-y |
Subtracts y from x. |
|
x*y |
Multiplies x and y. |
|
x/y |
Divides x by y. |
|
x^y |
Takes x to the yth power. |
|
-x |
Returns the negative of x. |
|
Mathematical Functions |
|
|
Abs(x) |
Returns the absolute value of x. |
|
Cos(x) |
Returns the cosine of x in radians. |
|
Acos(x) |
Returns the arc-cosine of x in radians. |
|
Sin(x) |
Returns the sine of x in radians. |
|
Asin(x) |
Returns the arc-sine of x in radians. |
|
Tan(x) |
Returns the tangent of x in radians. |
|
Atan(x) |
Returns the arc-tangent of x in radians. |
|
Round(x) |
Rounds x to the nearest integer. |
|
Floor(x) |
Rounds x down to the nearest integer. |
|
Ceil(x) |
Rounds x up to the nearest integer. |
|
Log(x) |
Returns the natural logarithm of x. |
|
Exp(x) |
Returns e to the power of x. |
|
Max(x, y) |
Returns either x or y, whichever is bigger. |
|
Min(x, y) |
Returns either x or y, whichever is smaller. |
|
Sqrt(x) |
Returns the square root of x. |
|
Random Number Generation Functions |
|
|
Rand(Maximum, Minimum) |
Returns a random number uniformly distributed between Maximum and Minimum. These parameters are optional and default to 0 and 1 respectively. |
|
RandNormal(mu, sigma) |
Returns a normally distributed random number with a mean of mu and standard deviation of sigma. If these parameters are omitted they default to 0 and 1 respectively. |
|
RandLognormal(mu, sigma) |
Returns a lognormally distributed random number with a mean of mu and standard deviation of sigma. Lognormally distributed random numbers are always positive and are often used to model naturally occurring quantities. |
|
RandExp(lambda) |
Returns an exponentially distributed random number using lambda as the rate parameter for the distribution. Lambda is optional and defaults to 1. |
|
RandPoisson(lambda) |
Returns a Poisson distributed random number where lambda is the expected number of occurrences in a time period. |
|
RandBinomial(count, probability) |
Returns a binomially distributed random. Binomial random numbers can be thought of as flipping count coins each with probability of showing heads (a decimal number from 0 to 1). The number of heads that occurred in these count coin flips is found and returned. |
|
RandNegative-Binomial(successes, probability) |
Returns a negative binomially distributed random. The number of random events required to obtain the specified number of successes each with a probability chance of occurring. |
|
RandGamma(alpha, beta) |
Returns a gamma distributed random number with a shape factor of alpha and a scale factor of beta. |
|
SetRandSeed(seed) |
Sets the seed used for the random number generator so that the same sequence of numbers will be generated each time the simulation is run. A convenient place to put this command is in your Settings primitive’s On Start property. Seed is an integer value. |
|
Other Functions |
|
|
IfThenElse(Condition, IfTrue, IfFalse) |
Carries out a logical test of Condition (examples: “[My Stock] = 2”, “Time <= 3”, “Time > 3 AND Time <> 7”). If Condition is true, then return the value of IfTrue. If Condition is false, return the value of IfFalse. |
|
Time Functions |
|
|
Seconds(x) |
Converts the value of x—given in your model’s basic time units—to its equivalent in seconds. If x is omitted, Time is used in its place. |
|
Minutes(x) |
Converts the value of x—given in your model’s basic time units—to its equivalent in minutes. If x is omitted, Time is used in its place. |
|
Hours(x) |
Converts the value of x—given in your model’s basic time units—to its equivalent in hours. If x is omitted, Time is used in its place. |
|
Weeks(x) |
Converts the value of x—given in your model’s basic time units—to its equivalent in weeks. If x is omitted, Time is used in its place. |
|
Days(x) |
Converts the value of x—given in your model’s basic time units—to its equivalent in days. If x is omitted, Time is used in its place. |
|
Months(x) |
Converts the value of x—given in your model’s basic time units—to its equivalent in months. If x is omitted, Time is used in its place. Simgua assumes a constant 12 months in a year. This means there is not an even number of days or weeks in a Simgua month. |
|
Years(x) |
Converts the value of x—given in your model’s basic time units—to its equivalent in years. If x is omitted, Time is used in its place. Simgua assumes a constant 365 days per year. |
|
BaseTime(x,”units”) |
Converts the time specified by the variable x which is in the units specified by the string units (“seconds”, “minutes”, “hours”, “days”, “weeks”, “months”, or “years”) into your model’s basic time units. |
|
Controlled Input Functions |
|
|
Pulse(time, height, width, repeat) |
Creates a pulse input at the specified time with the specified height and width. Height defaults to 1 and width defaults to 0. Repeat is also optional and, if set, it repeats the pulse every repeat time length. |
|
Staircase(start, height) |
Creates a staircase or step input that is initially set to 0 and after the time of start is set to height. Height defaults to 1. |
|
Ramp(start, finish, height) |
Creates a ramp input which moves linearly from 0 to height between the start and finish times. Before start, the value is 0, after finish the value is height. Height defaults to 1. |
|
Historical Functions |
|
|
Delay(<x>, time, default) |
The Delay function returns past values of the primitive x (whose name is enclosed in triangle brackets). The time specifies how long ago to obtain the value. Default is optional and will be returned if the time selected results in a time prior to the start of the simulation. |
|
Delay1(<x>, time, initial value) |
The Delay1 function returns past values of the primitive x (whose name is enclosed in triangle brackets) using a first order exponential delay. The time specifies how long ago to obtain the value. Initial Value is optional. |
|
Delay3(<x>, time, initial value) |
The Delay3 function returns past values of the primitive x (whose name is enclosed in triangle brackets) using a third order exponential delay. The time specifies how long ago to obtain the value. Initial Value is optional. |
|
Smooth(<x>, time, initial value) |
The Smooth function operates like Delay1. |
|
Max(<x>) |
Returns the maximum value the primitive x has taken on over the course of the simulation. |
|
Min(<x>) |
Returns the minimum value the primitive x has taken on over the course of the simulation. |
|
Median(<x>) |
Returns the median of the values the primitive x has taken on over the course of the simulation. |
|
Mean(<x>) |
Returns the mean of the values the primitive x has taken on over the course of the simulation. |
|
StdDev(<x>) |
Returns the standard deviation of the values the primitive x has taken on over the course of the simulation. |
|
Constants |
|
|
Pi |
π = 3.14159265 |
|
Phi |
φ = 1.61803399 |
|
E |
e = 2.71828183 |
|
Simulation Variables |
|
|
Time |
The current time period in your model’s base time units. |
|
TimeStep |
The time step in your model’s base time units. |
|
TimeLength |
The length of the simulation in your model’s base time units. |
|
TimeUnits |
Your model’s base time units. Either “Seconds”, “Minutes”, “Hours”, “Days”, “Weeks”, “Months”, or “Years”. |
Simgua also includes support for representing numbers in hexadecimal, binary and octal notation. ‘17’, ‘&h11’ (hex), ‘&o21’ (octal), and ‘&b10001’ (binary) are identical in Simgua. Scientific notation such as ‘2e4’ equaling ‘20000’ is also supported.