title: VBA: matrix inverse
body: <p>I'm trying to do something simple: take a matrix in cells A1:C3 and write the inverse into cells E1:G3. This doesn't work and the error I get is "type mismatch". Why?</p>
  
  <pre><code>Sub f()
      Range("E1:G3").Value = g(Range("A1:C3"))
  End Sub
  
  Function g(m As Range) As Double()
      Dim r As Integer, c As Integer
      Dim minv() As Double
      r = m.Rows.Count
      c = m.Columns.Count
      ReDim minv(1 To r, 1 To c)
      minv = WorksheetFunction.MInverse(m)
      g = minv
  End Function
  </code></pre>