# 'Undo' a matrix-vector product

I was wondering if there is an inbuilt Mathematica function that can take a vector $$v$$ whose components are sums of variables $$x_1, x_2, \dots x_{n}$$ and turn it into a matrix-vector product, where the matrix is just a coefficient matrix and vector is right and composed only of the variables? For example, is there a Mathematica function $$F$$ such that

$$\begin{pmatrix} x_{1} + 2x_{2} \\ 3x_{1} + 4x_{2}\end{pmatrix} \stackrel{F}{\to} \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \begin{pmatrix} x_{1} \\ x_{2} \end{pmatrix}$$

Essentially, I'm looking for a function that 'undoes' the matrix-vector multiplication. Apologies if this has been asked before or is very simple to implement, I'm not overly familiar with Mathematica and so I don't even know what to search for.

• CoefficientArrays? – xzczd Apr 6 '20 at 11:05
• @xzczd Thanks for letting me know about this function, I'll give it a try. – mattos Apr 6 '20 at 11:10

## 1 Answer

Just take the derivative with respect to the variables:

D[{x + 2 x, 3 x + 4 x}, {{x, x}, 1}]


{{1, 2}, {3, 4}}

• Didn't even think to do this. It worked a charm too, thanks for your help. – mattos Apr 6 '20 at 11:11