Search code examples
wolfram-mathematica

Writting many Equations for NDSolve


I'm trying to write the master equations for genetic networks, as they are many equations I'm trying to make a table for writing all of them at time. However, I don't know how to adjust the boundaries, I mean:

  1. I wrote a matrix with all the variables that I need:

p={{p11,p12},{p21,p22}}

  1. Then I wrote a table for creating the differential equations:

Table[p[[i,j]]'[t]== p[[i-1,j]][t]+p[[i,j-1]][t]+p[[i+1,j]][t]+p[[i,j+1]][t],{i,1,2},{j,1,2}]

  1. However the part p[[i-1,j]] when i=1 is p[[0,1]]but it doesn't exist and I need to put 0 instead of this but I dont not how. I tried with If but it doesn't work well. What can i do?

Solution

  • Will this work for you?

    pf[i_,j_]:=If[i<1||i>2||j<1||j>2,0,p[[i,j]][t]];
    Table[p[i,j]'[t]== pf[i-1,j]+pf[i,j-1]+pf[i+1,j]+pf[i,j+1],{i,1,2},{j,1,2}]
    

    which returns

    {{p[1, 1]]'[t] == p[[1,2]][t] + p[[2,1]][t], p[1, 2]]'[t] == p[[1,1]][t] + p[[2,2]][t]}, 
     {p[2, 1]]'[t] == p[[1,1]][t] + p[[2,2]][t], p[2, 2]]'[t] == p[[1,2]][t] + p[[2,1]][t]}}