# Equations with matrices

Posted 7 months ago
1307 Views
|
4 Replies
|
0 Total Likes
|
 I have a system of linear equations A.x=b. Now, I divide the matrix A into 9 submatrices, so I get the following systems of equations:A11.x1+A12.x2+A13.x3=b1 (1)A21.x1+A22.x2+A23.x3=b2 (2)A31.x1+A32.x2+A33.x3=b3. (3)I would like to solve the third system with respect to x3 and to get:x3=A33^-1.b3-A33^-1.A31.x1-A33^-1.A32.x2Substituting x3 into the system (2), I would like to get an expressionx2=(A22-A23.A33^-1.A32).(b2-A23.A33^-1.b3-(A21-A23.A33^-1.A31).x1). The same should apply to x1.How can I indicate in Mathematica that my equations contain matrices? In other words how can I force Mathematica to work with matrices and not just with numbers? Thanks and best regards, B. P.
4 Replies
Sort By:
Posted 7 months ago
 I am afraid there is no simple command in Mathematica to do it. But perhaps by doing it yourself: mul[mat_, vec_] := Table[Sum[mat[[i, j]].vec[[j]], {j, 1, Length[vec]}], {i, 1, Length[mat]}] mul[( { {a1, a2}, {a3, a4}, {a5, a6} } ), {x1, x2} ]and appropriate modifications for the multiplication of matrices.
Anonymous User
Anonymous User
Posted 7 months ago
 While not asked above, Mathematica Help doesn't appear to mention support for solving partitioned Matrixes. Yet mm certainly can multiply and add them.My book (david c. lay p. 123) says this. Take A as a 4x4 block matrix with A11 a pxp and A22 qxq. Find A^-1. Let B=A^-1. Let A be valued and B be unknown. A = { {A11, A12}, {0, A22} } (* example *) A B = { { Ip, 0}, {0, Iq} } (* solving for B is A^-1 *) I assume that means if one multiplies A B and solves the result equal to the correct Identity matrix, that means Mathematica does not need to know whether or not (or how) your matrix is privately partitioned to solve it.
Posted 6 months ago
 Hello B.P.,I tried to implement the procedure that you described above. First I define the matrix and the vectors using Array amat = Array[Subscript[a, ##] &, {3, 3}]; xvec = Array[Subscript[x, #] &, 3]; bvec = Array[Subscript[b, #] &, 3]; Now the equation is set up as you referenced it at the very top. (eq1 = amat. xvec == bvec) // TraditionalForm The equation in matrix form can be broken down into a list of equations as you stated it (eq2 = Thread[eq1]) // TableForm // TraditionalForm Next is to solve for x3 to x1 sequentially by picking on of the equations, repectively. sol3 = Flatten[Solve[Take[eq2, {3}], Subscript[x, 3]]] sol2 = Flatten[ Solve[Take[eq2, {2}] /. sol3, Subscript[x, 2]]] sol1 = Simplify[ Flatten[ Solve[Take[eq2, {1}] /. sol3 /. sol2, Subscript[x, 1]]]] If I understood correctly this should be what you asked for.Using FoldList, the sequential solving steps can be carried out in one command using the function f1 (but this is a bit tricky) f1[ rule_, {eq_, var_}] := Simplify[Flatten[ Solve[ eq /. rule, var]]] Drop[FoldList[ f1[#1, #2] &, {}, {eq2, xvec}\[Transpose]], 1] Regards, Michael
Posted 6 months ago
 On small correction: in order that the FoldLIst expression is really doing the same, the order of the equations and the order of the xi elemnts in xvec have to be reversed Drop[FoldList[ f1[#1, #2] &, {}, {Reverse[eq2], Reverse[xvec]}\[Transpose]], 1] 
Community posts can be styled and formatted using the Markdown syntax.