Difference between revisions of "Dynamic function"
(Created page with "Category:Analytica User Guide <breadcrumbs>Analytica User Guide > Dynamic Simulation > {{PAGENAME}}</breadcrumbs> __TOC__ ==See Also== <footer>Time index / {{PAGENAME}}...") |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
__TOC__ | __TOC__ | ||
+ | ==Dynamic(initial1, ''initial2..., initialn'', expr)== | ||
+ | Performs dynamic simulation, calculating the value of its defined variable at each element of [[Time]]. The result of [[Dynamic]]() is an array, indexed by [[Time]]. | ||
+ | |||
+ | «Initial1», ...«initialn» are the values of the variable for the first ''n'' time periods. «expr» is an expression giving the value of the variable for each subsequent time period. «expr» can refer to the variable in earlier time periods, that is, contain its own identifier in its definition. If variable <code>Var</code> is defined using [[Dynamic]], «expr» can be a function of <code>Var[Time - k]</code> or <code>Self[Time - k]</code>, where ''k'' is an expression that evaluates to an integer between ''1'' and ''t'', and ''t'' is the time step at which «expr» is being evaluated. | ||
+ | |||
+ | <tip title="Tip"> | ||
+ | Square brackets ([ ]) are necessary around <code>Time - t</code>. | ||
+ | </Tip> | ||
+ | |||
+ | The [[Dynamic]] function must appear at the topmost level of a definition. It cannot be used inside another expression. | ||
+ | |||
+ | When a dynamic variable refers to itself, it appears in its own list of inputs and outputs, with a symbol for cyclic dependency: [[File:Chapter17_1.5.png]]. | ||
+ | |||
+ | '''Library:''' Special | ||
+ | |||
+ | '''When to use:''' Use [[Dynamic]]() for defining variables that are cyclically dependent. There are only two functions in Analytica that allow a cycle to be formed, in which a variable can refer to its own value or to other variables that depend on it. Those two functions are [[Dynamic]]() and [[Iterate]](). Only dynamic variables can compute their value based on the values at at earlier time periods. | ||
+ | |||
+ | '''Example:''' [[Dynamic]]() can be used to calculate the effect of inflation on the price of gasoline in the years 1990 to 1994. | ||
+ | |||
+ | If the initial value is $1.20 per gallon and the rate of inflation is 5% per year, then <code>Gasprice</code> can be defined as: <code>Dynamic(1.2, Gasprice[Time - 1]*1.05)</code> or <code>Dynamic(1.2, Self[Time - 1]*1.05)</code>. | ||
+ | |||
+ | :[[File:Chapter17_2.png]] | ||
+ | |||
+ | Clicking the '''Result''' button and viewing the mid value as a table displays the following results. | ||
+ | |||
+ | :[[File:Chapter17_3.png]] | ||
+ | |||
+ | For 1990, Analytica uses the initial value of <code>Gasprice (1.2)</code>. For each subsequent year, Analytica multiplies the value of <code>Gasprice</code> at <code>[Time - 1]</code> by 1.05 (the 5 percent inflation rate). | ||
+ | |||
+ | ==x[Time - k]== | ||
+ | Given a variable <code>x</code> and brackets enclosing [[Time]] minus an integer «k», returns the value for «x», «k» time periods back from the current time period. This function is only valid for variables defined using the [[Dynamic]] function. | ||
+ | |||
+ | '''Library:''' Special | ||
==See Also== | ==See Also== | ||
+ | * [[Tutorial: Dynamic system model]] | ||
+ | * [[Dynamic]] | ||
+ | * [[Time]] | ||
+ | * [[Time index]] | ||
+ | * [[Iterate]] | ||
+ | |||
+ | |||
<footer>Time index / {{PAGENAME}} / Time index details</footer> | <footer>Time index / {{PAGENAME}} / Time index details</footer> |
Latest revision as of 23:25, 22 August 2016
Dynamic(initial1, initial2..., initialn, expr)
Performs dynamic simulation, calculating the value of its defined variable at each element of Time. The result of Dynamic() is an array, indexed by Time.
«Initial1», ...«initialn» are the values of the variable for the first n time periods. «expr» is an expression giving the value of the variable for each subsequent time period. «expr» can refer to the variable in earlier time periods, that is, contain its own identifier in its definition. If variable Var
is defined using Dynamic, «expr» can be a function of Var[Time - k]
or Self[Time - k]
, where k is an expression that evaluates to an integer between 1 and t, and t is the time step at which «expr» is being evaluated.
Square brackets ([ ]) are necessary around Time - t
.
The Dynamic function must appear at the topmost level of a definition. It cannot be used inside another expression.
When a dynamic variable refers to itself, it appears in its own list of inputs and outputs, with a symbol for cyclic dependency: .
Library: Special
When to use: Use Dynamic() for defining variables that are cyclically dependent. There are only two functions in Analytica that allow a cycle to be formed, in which a variable can refer to its own value or to other variables that depend on it. Those two functions are Dynamic() and Iterate(). Only dynamic variables can compute their value based on the values at at earlier time periods.
Example: Dynamic() can be used to calculate the effect of inflation on the price of gasoline in the years 1990 to 1994.
If the initial value is $1.20 per gallon and the rate of inflation is 5% per year, then Gasprice
can be defined as: Dynamic(1.2, Gasprice[Time - 1]*1.05)
or Dynamic(1.2, Self[Time - 1]*1.05)
.
Clicking the Result button and viewing the mid value as a table displays the following results.
For 1990, Analytica uses the initial value of Gasprice (1.2)
. For each subsequent year, Analytica multiplies the value of Gasprice
at [Time - 1]
by 1.05 (the 5 percent inflation rate).
x[Time - k]
Given a variable x
and brackets enclosing Time minus an integer «k», returns the value for «x», «k» time periods back from the current time period. This function is only valid for variables defined using the Dynamic function.
Library: Special
See Also
Enable comment auto-refresher