# How to create a group of equations?

To solve all the a[i,j] & b[i,j] through Mathematica,I need to create a group of equations.The m & n are arbitrary.And for all the 0<=i<=m & 0<=j<=n,the equations should be estabished. The equations:

a[i-1,j-1]+b[i,j-1]==a[i-1,j]+b[i-1,j-1];
a[i,j]+b[i,j]==a[i-1,j]+b[i,j-1]+P[i,j];
P[x1,y1]==t;
P[x2,y2]==-t;
else P[i,j]==0;
a[-1,x]==0,
a[m,x]==0,
b[x,-1]==0,
b[x,n]==0


（the x here is arbitrary)

• Wrap them in a list {eq1, eq2, ...} or link them with the logical And operator (&&) as eq1 && eq2 && .... – MarcoB Feb 2 at 13:37
• @MarcoB Thanks,but my question is that I need that the equations could be simply changed when I change m or n,for example,if i want to m=3 &n=2,I need to create a group of equations,but when i change n from 2 to 4,I need to create a different group again – cottea Feb 2 at 13:45
• @MarcoB Could you please give me a method to create a group of equations automaticly?I mean that I just need to type in m & n,and the program can change i & j and give out the equations(or the result ofSolve[]) itself – cottea Feb 2 at 13:50

Is this what you want?

First we write all equations that do not depend on i or j. Then we make a list with all equations that depend on i and j. Then we join the 2 lists. For a small example we choose n=m=2:

n = 2; m = 2;

eq1={P[_, _] == 0,
P[x1, y1] == t,
P[x2, y2] == -t,
b[x, n] == 0,
a[-1, x] == 0,
a[m, x] == 0,
b[x, -1] == 0}

eq2= Table[{a[i - 1, j - 1] + b[i, j - 1] == a[i - 1, j] + b[i - 1, j - 1],
a[i, j] + b[i, j] == a[i - 1, j] + b[i, j - 1] + P[i, j]}
, {i, 0, m}, {j, 0, n}] // Flatten;

eq=Join[eq1,eq2]

• Thanks very much,your answer is quite beautiful! I haven't imagine the function flatten could be used in this situation. – cottea Feb 2 at 13:57
• And I have a small question still,how to make all P[i,j]==0 except P[x1,y1] & P[x2,y2] – cottea Feb 2 at 14:01
• Sorry,I mean that how to put 0 to all P[i,j],that isP[i,j]=0, rather than P[i,j]==0 – cottea Feb 2 at 14:38
• You can achieve this by specifying: P[_,_]=0 . Now, do not think that this will set all P[.,.]=0. Instead MMA applies more specific patterns before more general ones. If you specify a more specific pattern like P[1,1]=2 MMA will try first this pattern before the more general one. Note, I changed my answer to include this case – Daniel Huber Feb 2 at 19:57
• Thanks,the method is right.However,before I change x1,x2 or y1,y2,I must close the document and reopen it,or MMA will let both the former and the new P[x1,y1]=t;P[x2,y2]=-t,could you let just the new P = t or -t?Here is my codem =; n =; x1 =; y1 =; x2 =; y2 =; P[_, _] = 0; P[x1, y1] = 1; P[x2, y2] = -1; b[_, n] = 0; a[-1, _] = 0; a[m, _] = 0; b[_, -1] = 0;Solve[Table[{a[i - 1, j - 1] + b[i, j - 1] == a[i - 1, j] + b[i - 1, j - 1], a[i, j] + b[i, j] == a[i - 1, j] + b[i, j - 1] + P[i, j]}, {i, 0, m}, {j, 0, n}] // Flatten] // Flatten – cottea Feb 3 at 4:12