Let's say I have a matrix, $\mathbf{M}$, that is polynomially dependent on a single variable, such as
M = {{15 + a^2, a + 5 a^2}, {a - 5 a^2, 2}}
and I want to find the individual matrices, $\mathbf{A}_i$, such that
$$\mathbf{M} = \mathbf{A}_0 + a \mathbf{A}_1 + a^2 \mathbf{A}_2 + \ldots$$
How do I do this? What do I use if there are multiple variables? Also, can I specify that certain symbols are not to be treated in this manner, e.g.
M = {{15 + a^2, a + 5 a^2}, {a - 5 a^2, 2 c}}
where the constant matrix would be {{15, 0}, {0, 2 c}}? Ideally, this should be applicable to vectors and tensors, also.


M = {{ArcTan[a], Zeta[a]}, {Sinh[a], Sqrt[a]}}. The only route seems to be expanding every entry in Taylor series. – Artes Jun 29 '12 at 14:35