0
$\begingroup$

I'm trying to solve a system of differential equations, using Table to define the equations I want to solve. I managed to do it with a table with one index, as there is an example in the docs, but I couldn't do it with a matrix. I tried the following code:

eqns = {
  Table[
   Derivative[1][y[i, j]][t] == y[i, j][t] - y[i, j][t - 1],
   {i, 1, 3},
   {j, 1, 3}
   ],
  Table[
   y[i, j][t /; t <= 0] == Exp[t*i + j],
   {i, 1, 3},
   {j, 1, 3}
   ]
  }
NDSolve[eqns, Table[y[i, j], {i, 3}, {j, 3}], {t, 30}];
Plot[Evaluate[Table[y[i, j][t], {i, 3}, {j, 3}] /. %], {t, 0, 30}, 
 PlotLegends -> Automatic]

Any ideas? Thanks!

$\endgroup$
2
  • 1
    $\begingroup$ Try NDSolve[eqns,Table[y[i,j],{i,3},{j,3}]//Flatten,{t,30}]. The only difference is the additional // Flatten. Look at the output of NDSolve with and without // Flatten to see the difference. $\endgroup$
    – user293787
    Aug 11 at 3:29
  • $\begingroup$ @user293787 thank you very much! I understand the difference now. If you want to put the comment as an answer, I'll accept it as the solution. $\endgroup$
    – lvass
    Aug 11 at 14:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.