1
$\begingroup$

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?

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$
    – bmf
    Jan 17, 2023 at 4:38
  • 1
    $\begingroup$ 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? $\endgroup$
    – A. Kato
    Jan 17, 2023 at 6:39

1 Answer 1

2
$\begingroup$
Clear["Global`*"]

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

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

enter image description here

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

enter image description here

eqns /. sol // Simplify

(* {True, True} *)

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

enter image description here

$\endgroup$
5
  • $\begingroup$ Thank you very much!! That's what I need!! $\endgroup$
    – YS_Jin
    Jan 17, 2023 at 20:37
  • $\begingroup$ 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? $\endgroup$
    – YS_Jin
    Jan 17, 2023 at 21:39
  • $\begingroup$ 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! $\endgroup$
    – YS_Jin
    Jan 17, 2023 at 22:01
  • $\begingroup$ 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}}. $\endgroup$
    – Bob Hanlon
    Jan 17, 2023 at 23:42
  • $\begingroup$ AH!! Plus is a head, I need to find a book to study Wolfram language. Thank you very much, Bob! $\endgroup$
    – YS_Jin
    Jan 17, 2023 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.