This question already has an answer here:

I have a big system of linear equations $f_i(x_1,...x_n)$ with $n$ variables and $n$ equations. I want to extract the matrix $M$ where $\vec{f}(\vec{x})=M\vec{x}$. For example if I have

$$ f_1(x) = x + 2y \\ f_2(x) = 3x-y $$ then I want to get the matrix

{{1,2}, {3,-1}}.

Is there a way to do this in Mathematica?


marked as duplicate by Mr.Wizard Aug 1 '14 at 17:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

l = {x + 2 y, 3 x - y};
Normal@CoefficientArrays[l, {x, y}][[2]]

{{1, 2}, {3, -1}}

  • $\begingroup$ This is the convenient way to do it. I got confused when looking at CoefficientArrays. $\endgroup$ – Szabolcs Sep 26 '13 at 0:05
  • $\begingroup$ @Szabolcs Me too (blush) $\endgroup$ – Dr. belisarius Sep 26 '13 at 0:09

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