4
$\begingroup$

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.

$\endgroup$
2
  • 5
    $\begingroup$ Stack the matrices and right hand sides and do LinearSolve[Astack,bstack]. Both of these can be done with Join. $\endgroup$ Nov 20 '14 at 23:34
  • 4
    $\begingroup$ In other words, use LinearSolve[Join[A1,...,An], Join[b1,...,bn]]. $\endgroup$ Nov 20 '14 at 23:36
1
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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