Difference between revisions of "Dynamic dependencies"
m (hyperlinks to functions) |
|||
Line 30: | Line 30: | ||
When the definition of a variable in a dynamic loop is evaluated, the definition is repeatedly evaluated in the context of <code>Time = t</code> (as <code>t</code> increments through the values of <code>Time</code>). The value for any identifier that appears in an expression is implicitly sliced at <code>Time = t</code> (unless it is explicitly offset in <code>Time</code>). As an example, suppose <code>A</code> is indexed by <code>Time</code>, and <code>X</code> is defined as: | When the definition of a variable in a dynamic loop is evaluated, the definition is repeatedly evaluated in the context of <code>Time = t</code> (as <code>t</code> increments through the values of <code>Time</code>). The value for any identifier that appears in an expression is implicitly sliced at <code>Time = t</code> (unless it is explicitly offset in <code>Time</code>). As an example, suppose <code>A</code> is indexed by <code>Time</code>, and <code>X</code> is defined as: | ||
− | :<code>Dynamic(0, | + | :<code>[[Dynamic]](0, [[Self]][[[Time]] - 1] + [[Max]](A, [[Time]]))</code> |
During evaluation, <code>A</code> would be an atom at any given time point since it is implicitly [[slice]]d across [[Time]]. When <code>A</code> is not indexed by <code>Time</code>, <code>Max(A, Time)</code> simply returns <code>A</code>, so that the above expression is equivalent to: | During evaluation, <code>A</code> would be an atom at any given time point since it is implicitly [[slice]]d across [[Time]]. When <code>A</code> is not indexed by <code>Time</code>, <code>Max(A, Time)</code> simply returns <code>A</code>, so that the above expression is equivalent to: | ||
− | :<code>Dynamic(0, | + | :<code>[[Dynamic]](0, [[Self]][[[Time]] - 1] + A)</code> |
− | To add the greatest value of <code>A</code> along <code>Time</code> in this expression, you must introduce an extra variable to hold the maximum value, defined simply as <code>Max(A, Time)</code>, and ensure that the two variables do not occur in the same dynamic loop. | + | To add the greatest value of <code>A</code> along <code>Time</code> in this expression, you must introduce an extra variable to hold the maximum value, defined simply as <code>[[Max]](A, [[Time]])</code>, and ensure that the two variables do not occur in the same dynamic loop. |
If you attempt to operate over the [[Time]] dimension from within a dynamic loop, Analytica issues the warning: ''“Encountered application of an array function over the Time index from within a dynamic loop. The semantics of this operation might be different than you expect.”'' | If you attempt to operate over the [[Time]] dimension from within a dynamic loop, Analytica issues the warning: ''“Encountered application of an array function over the Time index from within a dynamic loop. The semantics of this operation might be different than you expect.”'' |
Revision as of 23:12, 7 August 2017
All variables with dynamic inputs are evaluated dynamically — that is, their results are arrays indexed by Time.
Example: A series of dynamic definitions produce equations for distance, velocity, and acceleration:
Acceleration: -9.8
Dt: 0.5
Time: Sequence(0, 6, Dt)
Velocity: Dynamic(0, Self[Time - 1] + Acceleration*Dt)
Distance: Dynamic(100, Self[Time - 1] + Velocity*Dt) →
Dynamic dependency arrows
If a variable is dynamically dependent on another variable, a gray arrow is drawn between the variables.
To show or hide dynamic dependency arrows:
- Select Set Diagram Style from the Diagram menu to open the Diagram Style dialog.
- Click in the Dynamic checkbox to show dynamic arrows (or uncheck it to hide the arrows).
- Click OK to accept the change.
Expressions inside dynamic loops
A dynamic loop is a sequence of variables beginning and ending at the same variable, with each consecutive variable dependent on the previous one. At least one variable in a dynamic loop is defined using the Dynamic function.
When the definition of a variable in a dynamic loop is evaluated, the definition is repeatedly evaluated in the context of Time = t
(as t
increments through the values of Time
). The value for any identifier that appears in an expression is implicitly sliced at Time = t
(unless it is explicitly offset in Time
). As an example, suppose A
is indexed by Time
, and X
is defined as:
During evaluation, A
would be an atom at any given time point since it is implicitly sliced across Time. When A
is not indexed by Time
, Max(A, Time)
simply returns A
, so that the above expression is equivalent to:
To add the greatest value of A
along Time
in this expression, you must introduce an extra variable to hold the maximum value, defined simply as Max(A, Time)
, and ensure that the two variables do not occur in the same dynamic loop.
If you attempt to operate over the Time dimension from within a dynamic loop, Analytica issues the warning: “Encountered application of an array function over the Time index from within a dynamic loop. The semantics of this operation might be different than you expect.”
See Also
Enable comment auto-refresher