### Subscripting

#### Vensim’s subscripting language enables construction of very advanced arrayed models

Often a piece of model structure will need to be repeated over and over again.  For example, a retail store might be replicated for many different regions, or a factory production process might be repeated several times.  One method for repeating structure is to create and debug one structure, then copy and replicate that structure as many times as needed.  However, this can lead to complex diagrams and hard-wiring of constant values and number of structures.  A better way to repeat structure is to use subscripts.  A subscript is created and added to the one original structure, creating as many structures as there are subscript elements.  Now numbers of structures and numerical values for all structures can easily be changed.  Diagrams are also neater.

#### Example

A retail outlet such as a shoe retailer might have stores in three locations. A model can be built for one store with structure for staff, inventory, sales, etc. Once that model simulates properly, a subscript is created called Location, with the subscript elements Boston, New York, and San Francisco. The subscript Location is added to the one store structure, constants are modified to reflect the value for each location, and now the one model contains three structures.

Each subscripted structure can be individually customized, with different constants, multiple equations, even multiple subscripts.  Vensim supports up to eight different subscripts, allowing for extremely complex structures.

#### Subscript Equations

In a company containing a workforce, the subscript [worktype] might represent the types of workers in the company, and the subscript [location] might represent the physical location of the office or plant. So the equation

``hires[worktype, location] = desired hires[worktype, location] / time to hire worker[worktype]``

allows one equation to represent the hiring of workers for all types of work and for all location (using only two subscripts). Note that the time to hire a worker in the above equation is considered to be different depending on worktype, but not location (therefore the subscript is only for worktype).

#### Further Examples

Subscripts can allow construction of a single stock that represents many different segments of the same physical process. For example, a population aging chain is constructed of several stocks in which people age and move into the next stock, as below:

This same structure can be built using subscripts to represent each age category (cohort), as below:

The advantage of using subscripts is that you can easily change the number or characteristics of age categories by changing subscript names and values, rather than changing the physical structure by removing or adding stocks (as you would have to in the multiple stock structure above).  Also, you can represent a very large number of age categories (say 100) without having to create 100 stocks.

#### Subscript Functions

Subscripts have several special functions designed to manipulate equations. The SUM function sums all values of a subscript marked with an exclamation mark (!). Other functions include products, maximums, and minimums.

``total workers[worktype] = SUM ( Workers[worktype, location!])``

This equation describes the summing of workers of each particular worktype (e.g., office staff, plant operators) over all locations. In other words, total office staff summed over all locations, total plant operators summed over all locations. The SUM function works on the subscript location because location is marked with the exclamation mark.