Skip to content

Commit 3c17637

Browse files
docs: document the ability to save parameters in callbacks
1 parent a29966b commit 3c17637

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/src/basics/Events.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,28 @@ one must still use a vector
336336
```julia
337337
discrete_events = [[2.0] => [v ~ -v]]
338338
```
339+
340+
## Saving discrete values
341+
342+
Time-dependent parameters which are updated in callbacks are termed as discrete variables.
343+
ModelingToolkit enables automatically saving the timeseries of these discrete variables,
344+
and indexing the solution object to obtain the saved timeseries. Consider the following
345+
example:
346+
347+
```@example events
348+
@variables x(t)
349+
@parameters c(t)
350+
351+
@mtkbuild sys = ODESystem(
352+
D(x) ~ c * cos(x), t, [x], [c]; discrete_events = [[t ~ 1.0] => [c ~ c + 1]])
353+
354+
prob = ODEProblem(sys, [x => 0.0], (0.0, 2pi), [c => 1.0])
355+
sol = solve(prob, Tsit5())
356+
sol[c]
357+
```
358+
359+
The solution object can also be interpolated with the discrete variables
360+
361+
```@example events
362+
sol([1.0, 2.0], idxs = [c, c * cos(x)])
363+
```

0 commit comments

Comments
 (0)