# Math 218: Matrices and Vector Spaces

This is the webpage for the Fall 2018 manifestation of Dr. Fitzpatrick's section of Math 218 at Duke University.

## SageMath

SageMath is an open source computer algebra system written python.

## Useful Commands

Use the syntax A = matrix([(1/2,-3,5),(-4/5,2,11),(6,-4,9)]) to define the matrix $A = \left[\begin{array}{rrr} \frac{1}{2} & -3 & 5 \\ -\frac{4}{5} & 2 & 11 \\ 6 & -4 & 9 \end{array}\right]$ Avoid using decimal notation! Input 1/2 instead of .5.

• The command A.rref() computes the reduced row-echelon form of A.
• The command A.det() computes the determinant of A, provided that A is square.
• The command A.rank() computes the rank of A.
• If A and B are $$m\times n$$ matrices, then the command A+B computes the sum of A and B.
• If c is a scalar, then the command c*A computes the scalar product of c and A.
• If A is $$\ell\times m$$ and B is $$m\times n$$, then A*B computes the product of A and B.
• The command A.transpose() computes the transpose of A.
• The command A.is_symmetric() tests if A is symmetric.

## Reduced Row-Echelon Form

The following code computes the reduced row-echelon form of a given matrix $$A$$.

## $$PA=LU$$-Factorization

The following code computes the $$LU$$-Factorization of a given matrix $$A$$.

## Reduced Row-Echelon form Practice!

Enter the number of rows and the number of columns of the matrix.

## $$PA=LU$$ Practice!

Enter the size of the matrix.

## The Four Fundamental Subspaces

Enter the matrix.

To practice finding bases, you can generate a random $$m\times n$$ matrix with the command A = random_matrix(ZZ, m, n).

A random $$m\times n$$ matrix with rank $$r$$ whose reduced row-echelon form has integer entries can be generated with the command A = random_matrix(ZZ, m, n, algorithm='echelonizable', rank=r).

## Projections

The following code computes the projection matrix $$P$$ onto the column space of the input matrix $$A$$.

## Least Squares Approximation

The following code computes the least squares approximation of a given list of points.

## Gram-Schmidt

This code performs the Gram-Schmidt algorithm (without the normalization step) on the columns of the input matrix $$A$$. The output is a matrix $$Q$$ whose columns are produced by the Gram-Schmidt algorithm.

## Pseudoinverses

Sage can compute the pseudoinverse of any matrix.