3
$\begingroup$

I am looking to decompose a matrix in terms of a sum of matrices with the same coefficients, i want something in this form :

$ m1= \begin{pmatrix} a^2 + 2a + 3 & 1 \\ 2a & a^2 \end{pmatrix} =a^2\begin{pmatrix} 1& 0\\ 0& 1 \end{pmatrix} +a\begin{pmatrix} 2& 0\\ 2 & 0 \end{pmatrix}+\begin{pmatrix} 3& 1\\ 0& 0 \end{pmatrix}$

I tried to use Collect[m1,a] but it collects the terms inside the matrix instead of giving a sum of matrices.

$\endgroup$
1
  • 1
    $\begingroup$ Please, add always copyable code to your posts. $\endgroup$ – Henrik Schumacher Apr 24 '19 at 16:26
3
$\begingroup$

Here is a possible approach:

decompose[m_,a_]:=With[{max = Max @ Exponent[m, a]},
    terms = SeriesCoefficient[m, {a, 0, #}]& /@ Range[0,max];
    a^Range[0,max] . MatrixForm/@terms
]

Then:

    decompose[{{3+2 a+a^2,1},{2 a,a^2}}, a] //TeXForm

$a^2 \left( \begin{array}{cc} 1 & 0 \\ 0 & 1 \\ \end{array} \right)+a \left( \begin{array}{cc} 2 & 0 \\ 2 & 0 \\ \end{array} \right)+\left( \begin{array}{cc} 3 & 1 \\ 0 & 0 \\ \end{array} \right)$

$\endgroup$
1
  • $\begingroup$ Very nice (+1). This could be useful in a number of linear algebra environments. $\endgroup$ – David G. Stork Apr 24 '19 at 18:32

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