Continuous-Time Models
We assume every continuous-time model to consist of a dynamics model $f$ and a measurement model $g$.
\[\dot{x}(t) = f(x(t), u(t), p, t)\\ y(t) = g(x(t), u(t), p, t)\]
The dynamics model is given by a first-order ordinary differential equation. The measurement model is given by a simple algebraic function.
Dynamics Model
The SimpleSim.jl equivalent of the first-order ordinary differential equation
\[\dot{x}(t) = f(x(t), u(t), p, t)\]
is to define a function that returns the current derivative of $x$ as an AbstractVector.
function fc_my_model(x, u, p, t)
my_x_derivative = # ...
return my_x_derivative
endImplicit differential equations $0 = F(\dot{x}, x, u, p, t)$ are not supported (yet...).
Measurement Model
The measurement model
\[y(t) = g(x(t), u(t), p, t)\]
is also implemented as a simple Julia function that returns the current output $y(t)$ given the current state $x(t)$, input $u(t)$ and time $t$, as well as the parameters $p$. The output $y$ should also be returned as an AbstractVector.
function gc_my_model(x, u, p, t)
my_output = # ...
return my_output
endModel Creation
Every SimpleSim.jl model has to be a data structure with named fields. So, you can use a custom struct to define your models or simply use a NamedTuple. Structs may have some advantages when it comes to debugging your code, however, for simple examples, NamedTuples are more than sufficient.
my_ct_model = (
p = nothing,
fc = fc_my_model,
gc = gc_my_model,
xc0 = my_initial_state,
uc0 = my_initial_input,
)Mandatory fields for continuous-time models:
p, set this tonothingif no parameters are neededfc, pass your dynamics function, returning the right-hand side of the ODEgc, pass your measurement function
Optional fields for continuous-time models:
xc0, the initial state of the system,nothingby default. Can be overriden by an initial state directly passed to thesimulatefunction.uc0, the initial input of the system,nothingby default.zc, function that returns a scalar and will be watched bySimpleSim.jlto detect zero-crossings.zc_exec, function that returns a post-zero-crossing state