I have several systems of linear equations in matrix form, and I would like to find the $\vec{x}$ that simultaneously solves them: $$A_1\vec{x} = b_1$$ $$\vdots$$ $$A_n\vec{x} = b_n$$ Is there a quick/neat way to do this? That is, something like: $$\text{LinearSolve}[A_1,b_1,\ldots,A_n,b_n]$$ If not, I will take a messy one.
1 Answer
Since nobody has posted a "messy" solution yet, let me: if the matrices are in one list alist = {a1,a2,...,an}
and the rhs' are in another, blist = {b1,b2,...,bn}
then
Clear[x];
vars = x[#] & /@ Range[n];
vars /. Solve[Dot[#1, vars] == #2 & @@@ Transpose[{alist, blist}], vars]
LinearSolve[Astack,bstack]
. Both of these can be done withJoin
. $\endgroup$LinearSolve[Join[A1,...,An], Join[b1,...,bn]]
. $\endgroup$