Elementary Matrices in Mathematica

Print This Post

You can enter a matrix in Mathematica in a number of ways. One way is to type up the entries as a nested list with each sublist serving as the rows of the matrix. For example the matrix

Latex formula

can be entered as

A={{1,2,3},{4,5,6},{7,8,0}}

You can also enter a matrix using the Basic Math Assistant Palette (Paletts -> Basic Math Assistant).

Basic Math Assistant Palette - Typsetting
Typesetting

By default, the matrix that appears is [math]2\times 2[/math]. If you want to add more rows then you can use keyboard shortcuts CTRL + ENTER and to add more columns use CTRL + , (comma). Here is a link to a wolfram tutorial.

Whether you define a matrix as a nested list, using keyboard shortcuts, or any other method, MatrixForm changes the output format to look like standard mathematical typsetting. For example once the matrix A is define with the code above, the code

A//MatrixForm

or

MatrixForm[A]

will produce a nicely typeset version.

Now we are going to talk about using elementary matrices Latex formula that multiply the matrix Latex formula to produce a lower triangular matrix.

The matrix Latex formula will subtract 4 times the first row from the second row:

Latex formula

enter this in Mathematica as

E21={{1,0,0},{-4,1,0},{0,0,1}};

E21//MatrixForm

This code has two lines, the first line defines the matrix E21 but suppresses output because the line ends with a semicolon. The second line display this matrix with nice typesetting. We will now multiply these two matrices:

E21 . A

produces

{{1, 2, 3}, {0, -3, -6}, {7, 8, 0}}

You may or may not put a space before and after the dot, I used a space to make the code more readable. Once again, using MatrixForm we can get a nicer version of the output:

MatrixForm[E21 . A]

At this point we have

Latex formula

Now define the matrix E31 that subtracts 7 times the first row from the third row:

E31 = {{1,0,0},{0,1,0},{-7,0,1}};

E31 . E21 . A//MatrixForm

Latex formula

One final matrix

E32 = {{1,0,0},{0,1,0},{0,-2,1}};

E32 . E31 . E21 . A//MatrixForm

Latex formula

Let’s now define a new matrix F that takes care of all of these row operations at once.

F = E32 . E31 . E21;

F//MatrixForm

F . A//MatrixForm

These three lines of code will produce

Latex formula

Latex formula

This is good stuff! This new matrix F immediately does all row operations and gives us an upper triangular matrix. The great thing is, we can now solve the matrix equation

Latex formula

for any Latex formula! All we have to do is setup the augmented matrix Latex formula and multiply this matrix on left with F:

Ab = {{1,2,3,b1},{4,5,6,b2},{7,8,0,b3}};

Ab//MatrixForm

F . Ab //MatrixForm

These three lines of code give

Latex formula

Let’s now take a particular vector

Latex formula

and apply F to the augmented matrix:

{b1,b2,b3} = {4, 3, 5};

MatrixForm[Ab]

MatrixForm[F . Ab]

This code produces an updated version of the augmented matrix and the result of applying F to it.

Here is a link to a Mathematica Notebook showing the computations of this post. Here is a link to the PDF version of the same file.