BasicsMatrices > Basics | Matrix products | Special matrices | QR | Matrix inverses | Linear maps | Matrix norms | Applications
Matrices as collections of column vectorsMatrices can be viewed simply as a collection of (column) vectors of same size, that is, as a collection of points in a multi-dimensional space. Matrices can be described as follows: given vectors in , we can define the matrix with 's as columns: Geometrically, represents points in a -dimensional space. The notation denotes the set of matrices. With our convention, a column vector in is thus a matrix in , while a row vector in is a matrix in . TransposeThe notation denotes the element of sitting in row and column . The transpose of a matrix . denoted by , is the matrix with element , , . Matrices as collections of rowsSimilarly, we can describe a matrix in row-wise fashion: given vectors in , we can define the matrix with the transposed vectors as rows: Geometrically, represents points in a -dimensional space. Matlab syntax
>> A = [1 2 3; 4 5 6]; % a 2x3 matrix >> B = A'; % this is the transpose of matrix A >> B = [1 4; 2 5; 3 6]; % B can also be declared that way >> C = rand(4,5); % a random 4x5 matrix Examples: Sparse MatricesIn many applications, one has to deal with very large matrices that are sparse, that is, they have many zeros. It often makes sense to use a sparse storage convention to represent the matrix. One of the most common formats involves only listing the non-zero elements, and their associated locations in the matrix. In Matlab, the function sparse allows to create a sparse matrix based on that information. The user needs also to specify the size of the matrix (it cannot infer it from just the above information). Matlab syntax
>> S = sparse([3 2 3 4 1],[1 2 2 3 4],[1 2 3 4 5],4,4) % creates a 4x4 matrix >> S = [0 0 0 5; 0 2 0 0; 1 3 0 0; 0 0 4 0]; % the same matrix with ordinary convention |