Difference between revisions of "Dynamic on non-Time Indexes"
m (hyperlinks to functions) |
|||
(4 intermediate revisions by one other user not shown) | |||
Line 2: | Line 2: | ||
<breadcrumbs>Analytica User Guide > Dynamic Simulation > {{PAGENAME}}</breadcrumbs> | <breadcrumbs>Analytica User Guide > Dynamic Simulation > {{PAGENAME}}</breadcrumbs> | ||
− | |||
− | The Dynamic function can be used to express a recurrence along any index, where the value at one value depends on previous values, the same way it is used to express a recurrence along the Time index. For non-Time indexes, you must specify the index explicitly in square brackets following the function name. | + | The [[Dynamic]] function can be used to express a recurrence along any index, where the value at one value depends on previous values, the same way it is used to express a recurrence along the [[Time]] index. For non-Time indexes, you must specify the index explicitly in square brackets following the function name. |
− | In the following example, we are to acquire as much of item 1 as we can afford, but can only purchase an integer number of units. With whatever funds remain, we purchase as many integer units of item 2 as possible, as so on. | + | In the following example, we are to acquire as much of ''item 1'' as we can afford, but can only purchase an integer number of units. With whatever funds remain, we purchase as many integer units of ''item 2'' as possible, as so on. |
− | + | :<code>Index Item := [1, 2, 3, 4]</code> | |
− | + | :<code>Unit_price := [[Table]](Item)(5100, 1600, 800, 250)</code> | |
− | + | :<code>Budget := 20K</code> | |
− | + | :<code>Num_acquired := [[Floor]](Funds_remaining/Unit_price)</code> | |
− | + | :<code>Spent := Num_acquired*Unit_price</code> | |
− | + | :<code>Funds_remaining := [[Dynamic]][Item](budget, [[Self]][Item - 1]-Spent[Item - 1])</code> | |
− | The three variables, Num_acquired, Spent, and Funds_remaining, form a recurrence over | + | The three variables, <code>Num_acquired, Spent</code>, and <code>Funds_remaining</code>, form a recurrence over the <code>Item</code> index. Evaluation proceeds starting with the dynamic context <code>Item = 1</code>. When <code>Num_acquired</code> is evaluated in this context, the <code>Unit_price</code> appearing in its definition evaluates to <code>Unit_price[Item = 1]</code>, since the use of a variable in a definition refers to its value sliced by the current dynamic context. Evaluation proceeds by evaluating each variable in the loop as <code>Item</code> is incremented and retaining the results for each value of <code>Item</code>: |
− | the Item index. Evaluation proceeds starting with the dynamic context Item=1. When | ||
− | Num_acquired is evaluated in this context, the Unit_price appearing in its definition evaluates to Unit_price[Item=1], since the use of a variable in a definition refers to its value sliced by the current dynamic context. Evaluation proceeds by evaluating each variable in the loop as Item is incremented and retaining the results for each value of Item: | ||
− | [[File:Chapter17_15.png]] | + | :[[File:Chapter17_15.png]] |
==See Also== | ==See Also== | ||
+ | * [[Dynamic]] | ||
+ | * [[Time]] | ||
+ | |||
+ | |||
<footer>Dynamic and uncertainty / {{PAGENAME}} / Reverse Dynamic</footer> | <footer>Dynamic and uncertainty / {{PAGENAME}} / Reverse Dynamic</footer> |
Latest revision as of 23:23, 7 August 2017
The Dynamic function can be used to express a recurrence along any index, where the value at one value depends on previous values, the same way it is used to express a recurrence along the Time index. For non-Time indexes, you must specify the index explicitly in square brackets following the function name.
In the following example, we are to acquire as much of item 1 as we can afford, but can only purchase an integer number of units. With whatever funds remain, we purchase as many integer units of item 2 as possible, as so on.
Index Item := [1, 2, 3, 4]
Unit_price := Table(Item)(5100, 1600, 800, 250)
Budget := 20K
Num_acquired := Floor(Funds_remaining/Unit_price)
Spent := Num_acquired*Unit_price
Funds_remaining := Dynamic[Item](budget, Self[Item - 1]-Spent[Item - 1])
The three variables, Num_acquired, Spent
, and Funds_remaining
, form a recurrence over the Item
index. Evaluation proceeds starting with the dynamic context Item = 1
. When Num_acquired
is evaluated in this context, the Unit_price
appearing in its definition evaluates to Unit_price[Item = 1]
, since the use of a variable in a definition refers to its value sliced by the current dynamic context. Evaluation proceeds by evaluating each variable in the loop as Item
is incremented and retaining the results for each value of Item
:
See Also
Enable comment auto-refresher