A matrix is a rectangular array of scalars or other kind of elements.
Matrices have many uses in computer graphics, some of which are representing linear transformations, affine transformations or images, among others.
Definitions and notationsEdit
The horizontal lines in a matrix are called rows and the vertical lines are called columns. A matrix with m rows and n columns is called an m-by-n matrix (or m×n matrix) and m and n are called its dimensions. The dimensions of a matrix are always given with the number of rows first, then the number of columns.
The entry of a matrix A that lies in the i -th row and the j-th column is called the i,j entry or (i,j)-th entry of A. This is written as or A[i,j].
We often write to define an m × n matrix A with each entry in the matrix A[i,j] called for all 1 ≤ i ≤ m and 1 ≤ j ≤ n. However, the convention that the indices i and j start at 1 is not universal: some programming languages (and the pseudocode in this wiki) start at zero, in which case we have 0 ≤ i ≤ (m − 1) and 0 ≤ j ≤ (n − 1).
A matrix where one of the dimensions equals one is often called a vector. A 1 × n matrix (one row and n columns) is called a row vector, and an m × 1 matrix (one column and m rows) is called a column vector.
ExampleEdit
The matrix
is a 4×3 matrix. The element A[2,3] or a_{2,3} is 7.
The matrix
is a 1×9 matrix, or 9-element row vector.
The matrix
is a 3×1 matrix, or 3-element column vector
Operations on matricesEdit
AdditionEdit
Given m-by-n matrices A and B, their sum A + B is the m-by-n matrix computed by adding corresponding elements (i.e. (A + B)[i, j] = A[i, j] + B[i, j] ). For example:
Note both A and B must have the same dimension.
pseudocode
Matrix C[m][n], A[m][n], B[m][n] integer i,j
for j in [0..n-1] { for i in [0..m-1] { C[i][j] = A[i][j] + B[i][j] } }
ScalingEdit
Given an m-by-n matrix A and a scalar s, sA is the m-by-n matrix computed by multiplying each element in A by s. For example:
pseudocode
Matrix A[m][n], B[m][n] float s integer i,j
for j in [0..n-1] { for i in [0..m-1] { C[i][j] = s * A[i][j] } }
MultiplicationEdit
The product of two matrices is well-defined only if the number of columns of the first matrix is the same as the number of rows of the second matrix. If A is an m-by-p matrix and B is an p-by-n matrix, then their matrix product AB is the m-by-n matrix (m rows, n columns) given by:
for each pair i and j. For example:
pseudocode
Matrix A[m][n], B[n][p], C[m][p] integer i,j,k
for j in [0..n-1] { for i in [0..m-1] { c[i][j] = 0 for k in [0..p-1] [ C[i][j] = C[i][j] + A[i][k] * B[k][j] } } }
TransposeEdit
The transpose of a matrix is another matrix, produced by turning rows into columns and vice versa. Informally, the transpose of a square matrix is obtained by reflecting at the main diagonal (that runs from the top left to bottom right of the matrix). The transpose of the matrix A is written as A^{tr}, ^{t}A, A′, or A^{T}.
Formally, the transpose of the m-by-n matrix A is the n-by-m matrix A^{T} defined by A^{T}[i, j] = A[j, i] for 1 ≤ i ≤ n and 1 ≤ j ≤ m.
For example:
pseudocode
Matrix A[m][n], B[n][m] integer i,j,k
for j in [0..n-1] { for i in [0..m-1] { B[j][i] = A[i][j] } }
This article is a stub. You can help the Computer Graphics Wiki by expanding it. |