Modeling system with piecewise constant control input

Hello,
I would like to simulate a model with use of DifferentialEquations.jl. I know I can provide an input to the system via anonymous function, but I am not able to approximate such function.

Is there any possible way to provide sampled data with fixed sampling time as an input (N x 1 vector) instead of providing an anonymous function?

EDIT: The original problem was not well defined, I asked about how to provide measured signal (represented as a sampled data) as a input to the system , which led to interpolation of that sampled data.

The correct formulation is that I would like to provide these sampled data as a discrete time signal (the signal is constant between samples - therefore it is piecewise constant control signal)

If you have sampled data of the right-hand side then it should be possible to use any kind of interpolation. For example, if you want to solve \dot x = f(x) and you have sampled data of f, e.g. F_i \approx f( i/N), then it should be doable.

However, if you have only samples of the trajectory, e.g. X_i = x(t_i) for t_i = 0, h, 2h, ... then
what you describe is actually a non-trivial and very active area of research.
The question how to find the ODE model for given data is very closely related to parameter optimisation or regression; and somehow similar to machine learning techniques.

There is for example this package: GitHub - SciML/DataDrivenDiffEq.jl: Data driven modeling and automated discovery of dynamical systems for the SciML Scientific Machine Learning organization
and if you have some idea how the ODE model could look like, you could use:
DiffEqFlux.jl – A Julia Library for Neural Differential Equations

But essentially, you either need a lot of samples or a good idea how the ODE model could roughly look like, otherwise it is just impossible. (The situation is like in statistics or machine learning, either you need a lot of data or a good model, ideally both to get good results.)


I don’t know what your application is, but it could be that time series analysis is more suitable…

1 Like

Thank you for suggestions. I will definitely check them out.
I have sampled data of the right-hand side, therefore I could use any kind of interpolation as you said.

To give an example, my model looks like this:

function model(dx, x, p, t)
    dx[1] = x[2]
    dx[2] = -0.48 * x[2] - 5.1195 * sin(x[3]) + 0.0677 * x[4] + 586.3695 * p.input(t)
    dx[3] = x[4]
    dx[4] = -0.0034 * x[2] - 73.6336 * sin(x[3]) - 0.3351 * x[4] + 210.12 * p.input(t)
end

where I would like to change p.input(t) for sampled data instead of anonymous function.

Ah, so the sampled data is for the time-dependent parameters, there is a package kind of made for this task: GitHub - PumasAI/DataInterpolations.jl: A library of data interpolation and smoothing functions

Probably you only need to add these lines (assuming you use a named tuple for your parameters) and it should work with the model as you showed it.

using DataInterpolations
p_data = #...
t_data = # ...
p = (input = LinearInterpolation(p_data,t_data), )
1 Like

What kind of variable is your input? What is its role in your problem? I dare to guess (based on some other private discussion we had) that it is actually a control variable.

If I am right, then most often than not this control variable (some might call it manipulated variable) will be periodically produced by a discrete-time (computer) controller. The variable will then be piecewise constant and the simulation should capture this. There was already some discussion of this here:

But I am sorry in case this is off topic.

2 Likes

It is the control input produced by a discrete-time controller based on our discussion.
I tried to find solution on Julia discourse but I missed these topics to be honest.

Thank you, I will check them out and then provide a feedback.

Then I suggest adding an EDIT: ... to your original post, stating that actually piecewise constant control input is considered. Otherwise people willing to help might start adding their advice on how to do interpolation, which is actually not what you need.

I would even feel tempted to reflect this in the title of the post perhaps replacing measured input with piecewise constant control input or digital input or discrete-time input or time-series input something like that. And make a comment on this modification in the EDIT so that the existing responses do not look off the original topic. This way, I believe, the whole topic might serve better not only to you right now but also to other readers searching for this topic in future using keywords. But it is up to you, you can perhaps even leave everything as it is.

1 Like

As far as I read through, it seems that these topics solve the problem.
Thank you.