You are on page 1of 7

Linear Algebra in Mathematica

Craig Beasley Department of Electrical and Systems Engineering Washington University in St. Louis St. Louis, MO February 20, 2012

Matrix operations provide a means to write complex systems using simple algebra. The arithmetic computation involved in solving such systems can become laborious, but it is not terribly complicated. With the aid of a computer, large systems with many variables can be solved quickly. Entering a Matrix There are two ways to enter a matrix into Mathematica. The first is to set it up as a list of lists (a TI-89 uses this input method as well). The second is to use templates. The first option is Mathematicas default display for a matrix in the output line, but there is a MatrixForm command that is used to display output as a matrix instead of a list. The template itself takes a little bit of getting used to.

The matrix template is highlighted in red and starts with a 2x2 matrix. The row vector template is highlighted in blue and starts with a 1x2 row vector. The column vector template is highlighted in green and starts with a 2x1 column vector. From either of those three, you must build up a matrix to the appropriate dimensions, using either ctrl+enter to add a new row or ctrl+, to add a new column. Alternatively, you can use the Basic Commands panel and flip to the matrix tab.

Page | 1

Here is what they look like using the MatrixForm command. Note the change to the output line. The command is called both in front of and behind the matrix entry so that you become accustomed to both types of command entry. Be careful not to overuse the MatrixForm command.

Be careful not to overuse the MatrixForm command. It will cause problems if you include it when defining a matrix.

Page | 2

Matrix Transpose This uses the Transpose command. Like MatrixForm, it can be appended to the end of a command line using a double forward slash. Regardless of where you place the commands, order matters. Transpose must occur first, followed by MatrixForm.

Matrix Addition and Subtraction Addition and subtraction of matrices works just like a calculator. There is nothing fancy required. Illegal matrix operations will return error messages.

Matrix Multiplication Multiplication is slightly different from normal arithmetic input. You have to use a period rather than an asterisk.

Page | 3

Gaussian Elimination The RowReduce command puts a matrix into row-echelon form.

Determinants Determinants can be found with the Det command.

Matrix Rank The rank of a matrix can be determined either by using the MatrixRank command or by row-reducing a matrix and counting the rows.

Page | 4

Inverse Matrices An inverse matrix can be determined in one of two ways. The first is to augment a matrix with the identity matrix and use Gaussian elimination. The second is to use the Inverse command.

Eigenvalues and Eigenvectors There are a few ways that Mathematica can be used to solve for eigenvalues and eigenvectors. First, there are Eigenvalues and Eigenvectors commands that will spit out the proper results, however they can be difficult to read. An additional issue with the Eigenvectors command is that it does not return the eigenvalues associated with each eigenvector. Instead, one could also simply compute eigenvalues the old-fashioned way. Remember that eigenvalues are found by taking the determinant of (A - I) to generate a characteristic equation, and setting it equal to zero. For future steps, it will be helpful to define matrix A and use the IdentityMatrix command.

Page | 5

The result is a polynomial, and you are looking for the roots. This is a simple matter of using the Solve or NSolve commands. If you prefer, the entire process can be written out in one line.

Alternatively, instead of taking a determinant, the CharacteristicPolynomial command could be used. As far as ease of input, it's no different than taking a determinant for a small matrix. It could become more convenient to use the CharacteristicPolynomial command as the dimension of the matrix becomes large. If you cant find , another letter could be used instead.

These methods not only generate eigenvalues, but also return their multiplicities. Now to find eigenvectors, use the RowReduce command, and substitute for Lamda.

From this point, it is simple to generate the equations to find x 1, x 2, and x 3. Since the process will have to be repeated for each eigenvalue, it is helpful to write the above steps in a form where the ReplaceAll (/.) command can be used.

Page | 6

As was mentioned at the beginning of this section, there are Eigenvalues and Eigenvectors commands. Here is their output with a matrix that has repeated eigenvalues.

For large matrices, these commands would be preferable assuming one could make heads or tails of the output. The Eigenvectors command returns its output in the same order as the Eigenvalues command, meaning that the vector {-1,-2,1} is associated with = 5. It is therefore important that both commands be used. An Eigensystem command is also included.

If you compare with the Eigenvalues and Eigenvectors commands, Eigensystem first returns a vector containing the eigenvalues for the matrix. It then returns the eigenvectors in the same order as their associated eigenvalues. This command is useful for dealing with large systems containing many variables and equations.

Page | 7

You might also like