## Mathematica for linear algebra

Here is some mathematica code to be used by my linear algebra students. The post will be periodically updated as the course progresses.

### Entering matrices

Mathematica views matrices as lists of columns. Thus to enter the matrix
$\left( \begin{array}{cccc} 1 & 1 & -1 & -1 \\ 1 & 2 & 3 & 4 \\ 1 & 3 & 5 & 7 \\ \end{array} \right)$
we type in

mat = {{1, 1, -1, -1}, {1, 2, 3, 4}, {1, 3, 5, 7}};


and hit [enter]. Here we have given the matrix the name mat and suppressed the output.

To view the matrix, type in the code

MatrixForm[mat]


and hit [enter].

### Row reducing a matrix

To row reduce the matrix, type in the code

RowReduce[mat]


and hit [enter]. Notice that the output is just given in list format. To display the result as a matrix, you can use either

MatrixForm[RowReduce[mat]]


or

RowReduce[mat] // MatrixForm

This entry was posted in Linear Algebra, Mathematica. Bookmark the permalink.