Matrix multiplication
From Wikipedia, the free encyclopedia
This article gives an overview of the various ways to perform matrix multiplication.
Contents |
[edit] Ordinary matrix product
By far the most important way to multiply matrices is the usual matrix multiplication. It is defined between two matrices 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-n matrix and B is an n-by-p matrix, then their product is an m-by-p matrix denoted by AB (or sometimes A · B). The product is given by
for each pair i and j with 1 ≤ i ≤ m and 1 ≤ j ≤ p. The algebraic system of "matrix units" summarises the abstract properties of this kind of multiplication.
[edit] Calculating directly from the definition
The picture to the left shows how to calculate the (1,2) element and the (3,3) element of AB if A is a 4×2 matrix, and B is a 2×3 matrix. Elements from each matrix are paired off in the direction of the arrows; each pair is multiplied and the products are added. The location of the resulting number in AB corresponds to the row and column that were considered.
[edit] The coefficients-vectors method
This matrix multiplication can also be considered from a slightly different viewpoint : it adds vectors together after being multiplied by different coefficients. If A and B are matrices given by:
and
then
For example:
The rows in the matrix on the left are the list of coefficients. The matrix on the right is the list of vectors. In the example, the first row is [1 0 2], and thus we take 1 times the first vector, 0 times the second vector, and 2 times the third vector.
[edit] Vector-lists method
The ordinary matrix product can be thought of as a dot product of a column-list of vectors and a row-list of vectors. If A and B are matrices given by:
and
where
- A1 is the vector of all elements of the form a1,x A2 is the vector of all elements of the form a2,x etc,
- and B1 is the vector of all elements of the form bx,1 B2 is the vector of all elements of the form bx,2 etc,
then
[edit] Properties
Matrix multiplication is not commutative (that is, AB ≠ BA), except in special cases. It is easy to see why: you cannot expect to switch the proportions with the vectors and get the same result. It is also easy to see how the order of the factors determines the result when one knows that the number of columns in the proportions matrix has to be the same as the number of rows in the vectors matrix: they have to represent the same number of vectors.
Although matrix multiplication is not commutative, the determinants of AB and BA are always equal (if A and B are square matrices of the same size). See the article on determinants for an explanation.
This notion of multiplication is important because if A and B are interpreted as linear transformations (which is almost universally done), then the matrix product AB corresponds to the composition of the two linear transformations, with B being applied first.
Additionally, all notions of matrix multiplication described here share a set of common properties (please replace this internal section link with correct syntax) described below.
[edit] Algorithms
The complexity of matrix multiplication, if carried out naively, is O(n3), but more efficient algorithms do exist. Strassen's algorithm, devised by Volker Strassen in 1969 and often referred to as "fast matrix multiplication", is based on a clever way of multiplying two 2 × 2 matrices which requires only 7 multiplications (instead of the usual 8). Applying this trick recursively gives an algorithm with a cost of . In practice, though, it is rarely used since it is awkward to implement and it lacks numerical stability. The constant factor implied in the big O notation is about 4.695.
The algorithm with the lowest known exponent, which was presented by Don Coppersmith and Shmuel Winograd in 1990, has an asymptotic complexity of O(n2.376). It is similar to Strassen's algorithm: a clever way is devised for multiplying two k × k matrices with less than k3 multiplications, and this technique is applied recursively. It improves on the constant factor in Strassen's algorithm, reducing it to 4.537. However, the constant term implied in the O(n2.376) result is so large that the Coppersmith–Winograd algorithm is only worthwhile for matrices that are too big to handle on present-day computers.
Since any algorithm for multiplying two n × n matrices has to process all 2 × n2 entries, there is an asymptotic lower bound of Ω(n2) operations. Most researchers believe that an optimal algorithm will run in essentially O(n2) time (Robinson, 2005). Raz proves a lower bound of Ω(m2logm) for bounded coefficient arithmetic circuits over the real or complex numbers.[1]
[edit] Scalar multiplication
The scalar multiplication of a matrix A = (aij) and a scalar r gives a product rA of the same size as A. The entries of rA are given by
If we are concerned with matrices over a ring, then the above multiplication is sometimes called the left multiplication while the right multiplication is defined to be
When the underlying ring is commutative, for example, the real or complex number field, the two multiplications are the same. However, if the ring is not commutative, such as the quaternions, they may be different. For example
[edit] Hadamard product
For two matrices of the same dimensions, we have the Hadamard product or entrywise product. The Hadamard product of two m-by-n matrices A and B, denoted by A • B, is an m-by-n matrix given by (A•B)ij = aijbij. For instance
Note that the Hadamard product is a submatrix of the Kronecker product (see below). The Hadamard product is studied by matrix theorists, but it is virtually untouched by linear algebraists. It is discussed in (Horn & Johnson, 1994, Ch. 5).
[edit] Kronecker product
Main article: Kronecker product.
For any two arbitrary matrices A and B, we have the direct product or Kronecker product A ⊗ B defined as
Note that if A is m-by-n and B is p-by-r then A ⊗ B is an mp-by-nr matrix. Again this multiplication is not commutative.
For example
.
If A and B represent linear transformations V1 → W1 and V2 → W2, respectively, then A ⊗ B represents the tensor product of the two maps, V1 ⊗ V2 → W1 ⊗ W2.
[edit] Common properties
All three notions of matrix multiplication are associative:
- A(BC) = (AB)C
and distributive:
- A(B + C) = AB + AC, and
- (A + B)C = AC + BC.
and compatible with scalar multiplication:
- c(AB) = (cA)B,
- (Ac)B = A(cB), and
- (AB)c = A(Bc).
Note that these three separate couples of expressions will be equal to each other only if the multiplication and addition on the scalar field are commutative, i.e. the scalar field is a commutative ring. See Scalar multiplication above for a counter-example such as the scalar field of quaternions.
[edit] Frobenius inner product
The Frobenius inner product, sometimes denoted A:B is the component-wise inner product of two matrices as though they are vectors. In other words, the sum of the entries of the Hadamard product. That is,
This inner product induces the Frobenius norm.
[edit] See also
- Strassen algorithm (1969)
- Winograd algorithm (1980)
- Coppersmith–Winograd algorithm (1990)
- Logical matrix
- Matrix chain multiplication
- Matrix inversion
- Relation composition
- Basic Linear Algebra Subprograms
- Matrix addition
- Dot product
[edit] External links
- WIMS Online Matrix Multiplier
- Animated Matrix Multiplication Examples (purplemath)
- Matrix Multiplication in C
- Matrix Multiplication in Javascript (works in Firefox)
- Online Matrix Multiplication using AJAX
[edit] References
- Strassen, Volker, Gaussian Elimination is not Optimal, Numer. Math. 13, p. 354-356, 1969.
- Coppersmith, D., Winograd S., Matrix multiplication via arithmetic progressions, J. Symbolic Comput. 9, p. 251-280, 1990.
- Horn, Roger; Johnson, Charles: "Topics in Matrix Analysis", Cambridge, 1994.
- Robinson, Sara, Toward an Optimal Algorithm for Matrix Multiplication, SIAM News 38(9), November 2005. PDF
- Petros Drineas, Ravi Kannan Fast Monte-Carlo Algorithms for Approximate Matrix Multiplication FOCS, 2001 [1]
- Petros Drineas, Ravi Kannan and Michael Mahoney Fast Monte Carlo Algorithms for Matrices I: Approximating Matrix Multiplication SIAM Journal of Computing, 2006 [2]
- Edith Cohen, David D. Lewis Approximating Matrix Multiplication for Pattern Recognition Tasks SODA, 1997 [3]