The invariant theory of matrices