@@ -22,10 +22,10 @@ Consider the following example:
2222
2323``` @example Usage
2424using ModelingToolkit, OrdinaryDiffEq, SymbolicIndexingInterface, Plots
25+ using ModelingToolkit: t_nounits as t, D_nounits as D
2526
2627@parameters σ ρ β
27- @variables t x(t) y(t) z(t) w(t)
28- D = Differential(t)
28+ @variables x(t) y(t) z(t) w(t)
2929
3030eqs = [D(D(x)) ~ σ * (y - x),
3131 D(y) ~ x * (ρ - z) - y,
@@ -121,6 +121,30 @@ output, the following shorthand is used:
121121sol[allvariables] # equivalent to sol[all_variable_symbols(sol)]
122122```
123123
124+ ### Evaluating expressions
125+
126+ ` getu ` also generates functions for expressions if the object passed to it supports
127+ [ ` observed ` ] ( @ref ) . For example:
128+
129+ ``` @example Usage
130+ getu(prob, x + y + z)(prob)
131+ ```
132+
133+ To evaluate this function using values other than the ones contained in ` prob ` , we need
134+ an object that supports [ ` state_values ` ] ( @ref ) , [ ` parameter_values ` ] ( @ref ) ,
135+ [ ` current_time ` ] ( @ref ) . SymbolicIndexingInterface provides the [ ` ProblemState ` ] ( @ref ) type,
136+ which has trivial implementations of the above functions. We can thus do:
137+
138+ ``` @example Usage
139+ temp_state = ProblemState(; u = [0.1, 0.2, 0.3, 0.4], p = parameter_values(prob))
140+ getu(prob, x + y + z)(temp_state)
141+ ```
142+
143+ Note that providing all of the state vector, parameter object and time may not be
144+ necessary if the function generated by ` observed ` does not access them. ModelingToolkit.jl
145+ generates functions that access the parameters regardless of whether they are used in the
146+ expression, and thus it needs to be provided to the ` ProblemState ` .
147+
124148## Parameter Indexing: Getting and Setting Parameter Values
125149
126150Parameters cannot be obtained using this syntax, and instead require using [ ` getp ` ] ( @ref ) and [ ` setp ` ] ( @ref ) .
0 commit comments