title: How to expand matrix expressions in SymPy?
body: <p>In SymPy, I am trying to perform a matrix multiplication and expand it afterwards. However, SymPy does not seem to support the expansion of matrix expressions. For example, here is the 4th order Runge-Kutta (RK4) for matrices:</p>
  
  <pre class="lang-py prettyprint-override"><code>from sympy import init_session
  init_session()
  from sympy import *
  
  A = MatrixSymbol('A', 3, 3)
  x = MatrixSymbol('x', 3, 1)
  dt = symbols('dt')
  
  k1 = A*x
  k2 = A*(x + S(1)/2*k1*dt)
  k3 = A*(x + S(1)/2*k2*dt)
  k4 = A*(x + k3*dt)
  final = dt*S(1)/6*(k1 + 2*k2 + 2*k3 + k4)
  final.expand()
  </code></pre>
  
  <p>which produces the result</p>
  
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last)
  &lt;ipython-input-38-b3ff67883c61&gt; in &lt;module&gt;()
       12 final = dt*1/6*(k1+2*k2+2*k3+k4)
       13 
  ---&gt; 14 final.expand()
  
  AttributeError: 'MatMul' object has no attribute 'expand'
  </code></pre>
  
  <p>I hope the expression can be expanded just like the scalar variant:</p>
  
  <pre><code>A,x,dt = symbols('A x dt')
  k1 = A*x
  k2 = A*(x+k1*dt*S(1)/2)
  k3 = A*(x+k2*dt*S(1)/2)
  k4 = A*(x+k3*dt)
  final = x+dt*(S(1)/6)*(k1+k2+k3+k4)
  collect(expand((final)),x)
  </code></pre>
  
  <p>with the result: </p>
  
  <pre><code>x*(A**4*dt**4/24 + A**3*dt**3/8 + A**2*dt**2/3 + 2*A*dt/3 + 1)
  </code></pre>
  
  <p>Is it possible to alter a matrix expression likewise?</p>
  
  <p>nicoguaro's answer takes the error away, but expands the the whole expression into one matrix. As illustrated with the scalar example, not what I'm looking for.</p>