Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted
l = {x + 2 y, 3 x - y};
Normal@CoefficientArrays[l, {x, y}][[2]]

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

share|improve this answer
    
This is the convenient way to do it. I got confused when looking at CoefficientArrays. –  Szabolcs Sep 26 '13 at 0:05
    
@Szabolcs Me too (blush) –  belisarius Sep 26 '13 at 0:09
    
Thanks, that works :-) –  Thomas Sep 26 '13 at 7:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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