Matrix multiplication
Encyclopedia : M : MA : MAT : Matrix multiplication
This article gives an overview of the various ways to multiply matrices.
- 1 Ordinary matrix product
- 2 \begin 5 & 1 \ 4 & 2\end] The rows in the matrix on the left is 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.
- 3 Scalar multiplication
- 4 Hadamard product
- 5 Kronecker product
- 6 \begin 0 & 3 & 0 & 6 \ 2 & 1 & 4 & 2 \ 0 & 9 & 0 & 3 \ 6 & 3 & 2 & 1 \end]. If ''A'' and ''B'' represent linear transformations ''V''1 → ''W''1 and ''V''2 → ''W''2, respectively, then ''A''
- 7 Common properties
- 8 See also
- 9 External links
- 10 References
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
- [ (AB)_ = \sum_^n a_b_ = a_b_ + a_b_ + \cdots + a_b_. ]
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.
- [(AB)_ = \sum_^2 a_b_ = a_b_+a_b_]
- [(AB)_ = \sum_^2 a_b_ = a_b_+a_b_]
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 matricies given by:
- [ \mathbf =
then
- [\mathbf= \begin a_ \begin b_ & b_ & \dots \end + a_ \begin b_ & b_ & \dots \end + \cdots \\\\ a_ \begin b_ & b_ & \dots \end + a_ \begin b_ & b_ & \dots \end + \cdots \\ \vdots\end]
- [ \begin 1 & 0 & 2 \\ -1 & 3 & 1 \end\cdot \begin 3 & 1 \\ 2 & 1 \\ 1 & 0 \end=\begin 1 \begin 3 & 1 \end + 0 \begin 2 & 1 \end + 2 \begin 1 & 0 \end \\ -1 \begin 3 & 1 \end + 3 \begin 2 & 1 \end + 1 \begin 1 & 0 \end\end=\begin \begin 3 & 1 \end + \begin 0 & 0 \end + \begin 2 & 0 \end \\ \begin -3 & -1 \end + \begin 6 & 3 \end + \begin 1 & 0 \end\end]
- [
\begin 5 & 1 \\ 4 & 2\end]
The rows in the matrix on the left is 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.
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 matricies given by:
- [ \mathbf =
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,
- [\mathbf =
Properties
Matrix multiplication is not commutative (that is, AB ≠ BA), except in special cases. It's easy to see why: you can't expect to switch the proportions with the vectors and get the same result. It's 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.
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 O(nlog2(7)) = O(n2.807...). In practice, though, it is rarely used since it is awkward to implement and it lacks numerical stability. The constant factor involved is about 4.695 asymptotically; Winograd's method improves on this slightly by reducing it to an asymptotic 4.537.
The best algorithm currently known, which was presented by Don Coppersmith and S. 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. However, the constant 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 n2 entries, it cannot run faster than O(n2). Most researchers believe that an optimal algorithm will run in essentially O(n2) time (Robinson, 2005).
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
- [ (rA)_ = r \cdot a_. \, ]
- [ (Ar)_ = a_ \cdot r. \, ]
- [ i\begin i & 0 \\ 0 & j \\ \end= \begin -1 & 0 \\ 0 & k \\ \end\ne \begin -1 & 0 \\ 0 & -k \\ \end= \begin i & 0 \\ 0 & j \\ \endi]
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
- [ \begin 1 & 3 & 2 \\ 1 & 0 & 0 \\ 1 & 2 & 2 \end\bullet \begin 0 & 0 & 2 \\ 7 & 5 & 0 \\ 2 & 1 & 1 \end= \begin 1 \cdot 0 & 3 \cdot 0 & 2 \cdot 2 \\ 1 \cdot 7 & 0 \cdot 5 & 0 \cdot 0 \\ 1 \cdot 2 & 2 \cdot 1 & 2 \cdot 1 \end= \begin 0 & 0 & 4 \\ 7 & 0 & 0 \\ 2 & 2 & 2 \end]
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
- [ \begin a_B & a_B & \cdots & a_B \\ \vdots & \vdots & \ddots & \vdots \\ a_B & a_B & \cdots & a_B \end.]
For example
- [ \begin 1 & 2 \\ 3 & 1 \\ \end\otimes \begin 0 & 3 \\ 2 & 1 \\ \end= \begin 1\cdot 0 & 1\cdot 3 & 2\cdot 0 & 2\cdot 3 \\ 1\cdot 2 & 1\cdot 1 & 2\cdot 2 & 2\cdot 1 \\ 3\cdot 0 & 3\cdot 3 & 1\cdot 0 & 1\cdot 3 \\ 3\cdot 2 & 3\cdot 1 & 1\cdot 2 & 1\cdot 1 \\ \end
\begin 0 & 3 & 0 & 6 \\ 2 & 1 & 4 & 2 \\ 0 & 9 & 0 & 3 \\ 6 & 3 & 2 & 1 \end].
If A and B represent linear transformations V1 → W1 and V2 → W2, respectively, then A
All three notions of matrix multiplication are associative:
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.Common properties
and distributive:
and
and compatible with scalar multiplication:
See also
External links
References
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
