1
$\begingroup$

I have the following system: $$\dot{x} = A(t)x+B(t)u$$ $$y = x$$

$A(t)$ and $B(t)$ are actually scalar, but time-dependent. If they would be constant, I could simulate the system in Matlab using:

sys = ss(A,B,C,0); lsim(sys,u,t,x0);

However, it would be nice to simulate the system with dynamic state and input matrix. The matrices are based on measurement data, this means I would have for each discrete time step $t_i$ another matrix $A(t_i)$. Any suggestions how to do that?

$\endgroup$
11
  • $\begingroup$ I'm voting to close this question as off-topic because it belongs on Stack Overflow (yes, despite the fact that I answered it). $\endgroup$
    – Chuck
    Jun 12, 2015 at 15:09
  • $\begingroup$ What is wrong with using an ode solver such as ode45 and interpolating A and B? $\endgroup$
    – fibonatic
    Jun 12, 2015 at 15:52
  • $\begingroup$ @Chuck I do not think this question would really be suited for stackoverflow, the computation science stackexchange would be a better choice. $\endgroup$
    – fibonatic
    Jun 12, 2015 at 15:55
  • $\begingroup$ @fibonatic, you might be correct, but I've always gotten Matlab answers from Stack Overflow. To this point, consider there are 321 questions tagged with "matlab" on the computation science board, but 48,752 on the Stack Overflow board. $\endgroup$
    – Chuck
    Jun 12, 2015 at 17:44
  • $\begingroup$ @Chuck But stackoverflow is also an older/bigger stackexchange. $\endgroup$
    – fibonatic
    Jun 12, 2015 at 19:20

1 Answer 1

1
$\begingroup$

When you say the matrices are based on measurement data, do you mean that $A(t)$ varies with your state space output $y$, which should be configured to provide your outputs (measurements), or that you want to actually provide a hard-coded series of parameters (field measurements) to the $A$ matrix?

If you are trying to do the former, have essentially $A=f(y)$, where $y=f(t)$ (because actually $y=f(x)$, but $x=f(t)$ by definition), then you can use ode45. In the function you want to use you can define y = x, then use that to update the parameters in $A$.

If you want the latter, or the former really, you can always brute force it. Setting up some standards real quick, let's say you have:

nSamples, which would be the number of time points in your simulation.

Your time step is dT.

You have nStates, so $size(A) = [nStates,nStates]$. Now assume that your A matrix evolves over time based of field samples (testing, etc.), you should have a bunch of $A$ matrices, such that you actually have $size(A) = [nStates,nStates,nSamples]$.

Now, try this:

x = Initial Conditions;

for i = 1:nSamples

currentA = A[: , : , i];

xDot = currentA * x + B * u;

x = x + xDot * dT;

y = x;

end

As before, if you just want to swap out parameters in $A$ based on $y$ then that's easy to implement too.

x = Initial Conditions;

y = f(x);

for i = 1:nSamples

A = f(y);

xDot = Ax + Bu;

x = x + xDot*dT;

y = f(x);

end

Again, this is just a brute-force method to implement what lsim does for you. It's just numeric integration.

Hope this helps!

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.