I'd like to use NDSolve to solve a system of n coupled 1st-order linear ODEs expressed in matrix-vector form, but which are definied piecewise in n-space (in particular, to represent different linear regimes of a piecewise-linear state-space model). I can successfully use NDSolve in a case such as
sol = X[t] /. NDSolve[{
X'[t] == A . X[t],
X[0] == X0}, X, {t, 0, 10}];
where A is some matrix is X0 is the initial condition. However, I'd like different behavior at different areas in space per a piecewise function, namely
sol1 = X[t] /. NDSolve[{
X'[t] == xdot[X[t]],
X[0] == X0}, X, {t, 0, 10}];
where, for example
xdot[X_] := Piecewise[{{A2 .
X, ((X[[1]] - X[[3]] > 0) && (X[[3]] >=
d/2)) || ((X[[1]] - X[[3]] < 0) && (X[[3]] <= -d/2))}}, A1 . X]
but this fails because the piecewise function must use part specifications but they fail when applied to the undefined 'X[t]' used in NDSolve.
Looking for ways to remedy this or suggestions for other ways to go about implementing the model. Thanks!
Indexed[X, 3]
? $\endgroup$A
andX0
? Please post the complete code. $\endgroup$