# Differential Equations with Matrices

I'm trying to implement the differential equation of a Cellular Neural Network in Mathematica as seen below:

A = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
B = {{9, 8, 7}, {6, 5, 4}, {3, 2, 1}};
u = {{10, 11, 12, 1}, {20, 21, 22, 1}, {66, 77, 88, 1}};
Ioff = 1;

NDSolve[{x'[t] == -x[t] + ListConvolve[A, x[t], 1] + ListConvolve[B, u, 1] + Ioff,
x == u}, x, {t, 0, 2}]


But NDSolve returns two errors:

ListConvolve::kldims: "The kernel {{1,2,3},{4,5,6},{7,8,9}} and list x[t] are not both non-empty lists with the same tensor rank."

NDSolve::ndfdmc: Computed derivatives do not have dimensionality consistent with the initial conditions.

I would really appreciate any help since I'm a beginner in Mathematica and I don't know what I'm doing wrong

• You should probably include the actual differential equation you're trying to solve. – RunnyKine Feb 5 '13 at 2:13

You need to define a little helper function. First, however, note that this computes:

NDSolveValue[{x'[t] == -x[t] + ListConvolve[B, u, 1] + Ioff,
x == u}, x, {t, 0, 2}]


So, the issue is with the ListConvolve that related to the unknown x[t]. You can feed x[t] back into a function:

 fun[xValAtT_] /; MatrixQ[xValAtT, NumericQ] :=
ListConvolve[A, xValAtT, 1]


and then call NDSolve with that function:

if = NDSolveValue[{x'[t] == -x[t] + fun[x[t]] +
ListConvolve[B, u, 1] + Ioff, x == u}, x, {t, 0, 2}];
if[0.2]
(*
{{193.082, 206.046, 294.78, 182.994}, {151.239, 169.641, 227.922,
127.526}, {321.59, 337.303, 480.992, 271.091}}
*)


Note, however, that this system seems to explode for larger values of t; perhaps you need to re-check your model, I am not sure.

• +1, nice ;) Is 2nd block of code missing just last bracket or more? – Vitaliy Kaurov Feb 5 '13 at 2:45
• @VitaliyKaurov, thanks for the typo, fixed now. – user21 Feb 5 '13 at 2:47
• Thank you! It seems to solve my problem. I think it is exploding because I have to apply a sigmoidal function to the x[t] inside ListConvolve but maybe it's happening because the values of A, B, Ioff and u are not the real ones. – Lucas Vinícius Feb 5 '13 at 11:31