Why does MatrixForm affect calculations?

MatrixForm is a wrapper that pretty-prints your matrices. When you do the following:

cov = {{0.02, -0.01}, {-0.01, 0.04}} // MatrixForm

you're assigning the prettified matrix to cov (i.e., wrapped inside a MatrixForm). This is not accepted as an input by most functions (perhaps all) that take matrix arguments. What you should be doing to actually assign the raw matrix to cov, yet get a pretty print in the output, is the following:

(cov = {{0.02, -0.01}, {-0.01, 0.04}}) // MatrixForm

You can also read more about why this happens due to the different precedences here in Leonid's book.


You can also avoid having to use MatrixForm every time by setting the default display for matrix outputs to be typeset accordingly. For this, you set the $PrePrint variable in your init.m file as:

$PrePrint = Replace[# , mat_?MatrixQ :> MatrixForm[mat]] &

You can also find this in Szabolcs's mathematica tricks. To reset the value of $PrePrint, simply unset it with $PrePrint=.


While the question has been more than answered there are still some things that seem to me worth adding. The first is that, in my opinion, MatrixForm is "essentially" obsolete. If you wish your matrices always look like matrices (in the output) you can set the format type of output cells to TraditionalForm (use the Appearance tab in the Preferences menu). In fact, you can also set the format type of your input cells to TraditionalForm, although you have to be a little careful if you do that (doing that is not recommended by WRI but it has some well known supporters...).

Alternatively you can use the ConvertTo menu to convert any matrices to TraditionalForm while keeping other cells or expressions in StandardForm (if you prefer that). The keyboard shortcut for this is Ctrl-Shift-T. Finally, if you would like all your matrices always to appear in MatrixForm and avoid these evaluation problems, you can evaluate at the beginning of your Mathematica session

$Post = If[MatrixQ[#], MatrixForm[#], #] & 

or you can put it into an init file and have it evaluate automatically. (Of course you can use TraditionalForm in place of MatrixForm).

Coming back to the issue of TraditionalForm vs MatrixForm for matrices: the only problem I can see with using the former is that it looks "too nice" so that if the rest of your output is in StandardForm the style of your matrices will not match the rest of your output. But other than that I can't think of any use for MatrixForm.


MatrixForm is a function to prettyprint matrices and cannot be used in computations. Just leave the MatrixForm away and you're fine:

a = {{1, 0, 1, 0}, {2, 1, 1, 1}, {1, 2, 1, 0}, {0, 1, 1, 1}};
inv = Inverse[a];
b = {{0}, {0}, {0}, {1}};
soln = inv.b
{{-(1/2)}, {0}, {1/2}, {1/2}}

If you want that result displayed (!) in a nice readable way, you can of course use MatrixForm again:

soln // MatrixForm

$\left( \begin{array}{c} -\frac{1}{2} \\ 0 \\ \frac{1}{2} \\ \frac{1}{2} \\ \end{array} \right)$