I have done this a few times, but never published the glue code. The pieces you need are
ModelingToolkit.generate_control_function to generate a function that computes \dot x = f(x, u, p, t) where x is the state and $u$$ is some external input (if present). In your case, I would remove the TimeVaryingFunction and instead treat those as external inputs (if I understand your use case correctly).
SeeToDee.jl to discretize the function f from above.
Call nonlinear_pem with the discretized dynamics function returned by SeeToDee.jl
Ah, if you have an LTI model, you can call named_ss from ContorlSystemsMTK or ModelingToolkit.linearize_symbolic to obtain the statespace matrices A,B,C,D, you can then make use of structured_pem to estimate the parameters. You’d need to write some glue code yourself in this case, this special-case pipeline of an LTI model from MTK hasn’t been explored yet.
You find some relevant utilities here, in particular the symbolic linearization and code generation that would give you the constructor function you need for structured_pem.
You can use the utilities to estimate a generic nonlinear model, it will not be as performant as if the linearity was exploited, but it will get the job done. Here’s a fully working example.
Not really, MTK is a tool for generic, nonlinear acausal modeling. As such, it can of course model simple LTI systems, but there is not much infrastructure in place to handle this special case any different from a fully generic nonlinear model.
If the model you have shown above is the full extent of your system, I would consider MTK a bit overkill and instead use something more minimal, e.g.
OrdinaryDiffEq.jl directly
SeeToDee.jl
ControlSystems.jl
The last two options would be much easier to interface with ControlSystemIdentification.
Your model as you have shown it does not make any use of things like model components, connections, algebraic equations, and for such simple system I think MTK complicates things rather than simplifies. If your end goal is a much bigger model, MTK may of course still make sense.
Thanks, I’m trying to see if I can get structured_pem working. Is there any example or docs on how to setup the state-space model for constructor? I wasn’t able to find anything in the docs