0
votes

I have an unknown non-linear system and I want to model it using another system with some adaptable parameters (for instance, a neural network). So, I want to fix an online learning structure of the unknown system without knowing its dynamics, I can only interact with it through inputs-outputs. My problem is that I can not make it work in MATLAB using ode solvers. Lets say that we have this real system (my actual system is more complicated, but I will give a simple example in order to be understood):

function dx = realsystem(t, x)
u = 2;
dx = -3*x+6*u;
end

and we solve the equations like this:

[t,x_real] = ode15s(@(t,x)realsystem(t,x), [0 1], 0)

We suppose that is an unknown system and we do not know the coefficients 3 and 6 so we take an adaptive system with the 2 adaptive laws:

dx(t) = -p1(t)*x(t) + p2(t)*u(t)

dp1(t) = -e(t)*x(t)

dp2(t) = e(t)*u(t)

with e(t) the error e(t) = x(t) - x_real(t).

The thing is that I cannot find a way to feed the real values for each t to the ode solver in order to have online learning.

I tried with something like this but it didn't work:

function dx = adaptivesystem(t, x, x_real)
dx = zeros(3,1);
e = x_real - x;
u = 2;
dx(1) = -x(2)*x(1)+x(3)*u;
dx(2) = -e*x(1); %dx(2) = dp1(t)
dx(3) = e*u; %dx(3) = dp2(t)
end
1
Why do you think an ODE solver is the right tool for this job? A hammer doesn't work on screws no matter how hard you try. - Ben Voigt
I thought that was the right tool to simulate a system knowing its differential equations. Is there any other way to estimate the parameters of the model knowing these equations? - sharp
For linear approximations, you have ARMA(X) and state-space models. For nonlinear parametric fitting, lsqcurvefit. Also, an Extended Kalman Filter may work well if you need to improve your fit with incoming data over time (not all data is available for the initial estimate). - Ben Voigt

1 Answers

0
votes

You should be aware that your problem is ill-posed as it is. Given any trajectory x(t) obtained via sampling and smoothing/interpolating, you can choose p1(t) at will and set

p2(t) = ( x'(t) - p1(t)*x(t) ) / u.

So you have to formulate restrictions. One obvious is that the functions p1 and p2 should be valid for all trajectories of the black-box system. Do you have different trajectories available?

Another variant is to demand that p1 and p2 are constants. Actually, in this case and if you have equally spaced samples available, it would be easier to first find a good difference equation for the data. With the samples x[n] for time t[n]=t0+n*dt form a matrix X with rows

[ -u, x[n], x[n+1], ... ,x[n+k] ] for n=0, ... , N-k

and apply QR decomposition or SVD to X to determine the right hand kernel vectors. QR may fail to show a usable rank deficiency, so use the SVD on the top square part of R = USV^T, S diagonal, ordered as usual, U,V square and orthogonal, and use the last row of V, with coefficients

[b, a[0], ..., a[k] ],

corresponding to the smallest eigenvalue, to form the difference equation

a[0]*x[n]+a[1]*x[n-1]+...+a[k]*x[n-k]=b*u.

If the effective rank of R resp. S is not (k-1), then reduce k to be the effective rank plus one and start again.

If in the end k=1 is found, then you can make a differential equation out of it. Reformulate the difference equation as

a[0]*(x[n]-x[n-1])/dt = -(a[0]+a[1])/dt * x[n-1] + b/dt * u

and read off the differential equation

x'(t) = -(a[0]+a[1])/(a[0]*dt) * x(t) + b/(a[0]*dt) * u

One may reject this equation if the coefficients become uncomfortably large.