# Matrix solving problem

I have a linear system like this: $$\left[\begin{array}{l}x_2\\y_2\end{array}\right] = \left[\begin{array}{l}A_{11}&A_{12}\\A_{21}&A_{22}\end{array}\right]\left[\begin{array}{l}x_1\\y_1\end{array}\right]$$ $$A_{11},A_{12},A_{21},A_{22}$$ are known. The target is to get the matrix: $$\left[\begin{array}{l}y_1\\y_2\end{array}\right] = \left[\begin{array}{l}B_{11}&B_{12}\\B_{21}&B_{22}\end{array}\right]\left[\begin{array}{l}x_1\\x_2\end{array}\right]$$. For 2-by-2 matrix, I can solve it manually. But now I have a 4-by-4(6-by-6) matrix which I have to use Mathematica to get answer. Any suggestions on this problem?

• Welcome to Mathematica SE. To start: 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, since the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) consider accepting the answer, if any, that solves your problem, by clicking checkmark sign, 4) give help too, by answering questions in your areas of expertise.
– bmf
Jan 17 at 4:38
• Hi. It is not clear how the unknown variables are shuffled in 4-by-4 or 6-by-6 cases. Can you write the above two equations, say, for the 4-by-4 case? Jan 17 at 6:39

Clear["Global*"]

(Format[#[n__]] := Subscript[#, Row[{n}]]) & /@ {a, x, y};

eqns = Thread[{x[2], y[2]} == Array[a, {2, 2}] . {x[1], y[1]}]


sol = Collect[Solve[eqns, {y[1], y[2]}][[1]], {x[1], x[2]}]


eqns /. sol // Simplify

(* {True, True} *)

B = List @@@ Values[sol] /. {x[1] -> 1, x[2] -> 1}


• Thank you very much!! That's what I need!! Jan 17 at 20:37
• Hello Bob, I have a question about the slot substitution: (Format[#[n__]] := Subscript[#, Row[{n}]]) & /@ {a, x, y}; &/@{a,x,y} means the slot # could be substituted by any of array members {a,x,y}, is this understanding correct? What's the function of "/@" here? Jan 17 at 21:39
• And I have another question about the last step map apply. Why List@@@[expr] can split the y1,y2 with substitution x1->1 x2->1 into two matrix cells? Thank you very much! Jan 17 at 22:01
• f /@ {a, x, y} maps f onto the list (evaluates to {f[a], f[x], f[y]}). In the first instance, f is the pure function (Format[#[n__]] := Subscript[#, Row[{n}]]) & The slots are filled with each of the elements of the list. Values[sol] /. {x[1] -> 1, x[2] -> 1} is a vector with the form {b11 + b12, b21 + b22}. MapApply: f @@@ expr replaces heads at level 1 of expr by f. In this case, the head Plus is replaced by List, converting the vector into the matrix {{b11, b12}, {b21, b22}}`. Jan 17 at 23:42
• AH!! Plus is a head, I need to find a book to study Wolfram language. Thank you very much, Bob! Jan 17 at 23:51