I'm trying to solve a differential equation that's phrased in terms of matrices and vectors.
My minimum working example is this:
k = 1.5*IdentityMatrix[2];
x0 = {1, 3};
v0 = {0, 0};
soln = NDSolve[{x''[t] == k.x[t], x[0] == x0, x'[0] == v0}, x, {t, 0, 2}]
Plot[Evaluate[x[t] /. soln], {t, 0, 2}]
It works fine, and plots two lines against time. AFAIU, this is the solution the system of differential equations:
$ \left[\begin{array}{c} \ddot{x}_{1}\\ \ddot{x}_{2} \end{array}\right]=\left[\begin{array}{cc} 1.5 & 0\\ 0 & 1.5 \end{array}\right]\left[\begin{array}{c} x_{1}\\ x_{2} \end{array}\right].$
But it seems to break if I add a constant vector g
to the RHS:
g = {1, 2}
k = 1.5*IdentityMatrix[2];
x0 = {1, 3};
v0 = {0, 0};
soln = NDSolve[{x''[t] == k.x[t] + g, x[0] == x0, x'[0] == v0}, x, {t, 0, 2}]
Plot[Evaluate[x[t] /. soln], {t, 0, 2}]
Now this should be solving the system:
$\left[\begin{array}{c} \ddot{x}_{1}\\ \ddot{x}_{2} \end{array}\right]=\left[\begin{array}{cc} 1.5 & 0\\ 0 & 1.5 \end{array}\right]\left[\begin{array}{c} x_{1}\\ x_{2} \end{array}\right]+\left[\begin{array}{c} 1\\ 2 \end{array}\right]$
But instead,I now get the error "NDSolve::ndfdmc: Computed derivatives do not have dimensionality consistent with the initial conditions. >>". I don't understand why this happens. It seems like the dimensionality of the differential equation matches that of the initial conditions, matches that of the added vector.
Why am I getting this error?
EDIT: Thanks for the workarounds! I think this is approaching bug territory. I've filed a complaint here ( http://www.wolfram.com/support/contact/email/ ) and encourage others to do the same.
NDSolve
is still not entirely reliable. $\endgroup$