Basics

  • Matrices as collections of column vectors
  • Transpose
  • Matrices as collections of row vectors
  • Sparse matrices

Matrices as collections of column vectors

Matrices 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 n vectors a_{1}, \dots, a_{n} in \mathbb{R}^{m} we can define the m \times n matrix A with a_{j}'s as columns:

    \[A= \begin{pmatrix} a_{1} & \dots & a_{n} \end{pmatrix} .\]

Geometrically, A represents n points in a m-dimensional space. The notation \mathbb{R}^{m \times n} denotes the set of m \times n matrices.

With our convention, a column vector in \mathbb{R}^{m} is thus a matrix in \mathbb{R}^{m \times 1}, while a row vector in \mathbb{R}^{n} is a matrix in \mathbb{R}^{1 \times n}.

Transpose

The notation A_{ij} denotes the element of A sitting in row i and column j. The transpose of a matrix A denoted by A^{T}, is the matrix with (i; j) element A_{ji}, i = 1, \dots, m and j = 1, \dots, n.

Matrices as collections of rows

Similarly, we can describe a matrix in row-wise fashion: given m vectors b_{1}, \dots, b_{n} in \mathbb{R}^{n}, we can define the m \times n matrix B with the transposed vectors b_{i}^{T} as rows:

    \[B = \begin{pmatrix} b_{1}^{T} \\ b_{2}^{T} \\ \vdots \\ b_{m}^{T} \end{pmatrix}.\]

Geometrically, B represents m points in a n-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 Matrices

In 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 (i; j) 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

License

Hyper-Textbook: Optimization Models and Applications Copyright © by L. El Ghaoui. All Rights Reserved.

Share This Book