In mathematics, particularly in linear algebra, matrix multiplication is a binary operation that produces a matrix from two matrices. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The resulting matrix, known as the matrix product, has the number of rows of the first and the number of columns of the second matrix. The product of matrices and is denoted as .[1]
Matrix multiplication was first described by the French mathematician Jacques Philippe Marie Binet in 1812, to represent the composition of linear maps that are represented by matrices. Matrix multiplication is thus a basic tool of linear algebra, and as such has numerous applications in many areas of mathematics, as well as in applied mathematics, statistics, physics, economics, and engineering.[2] [3] Computing matrix products is a central operation in all computational applications of linear algebra.
This article will use the following notational conventions: matrices are represented by capital letters in bold, e.g. ; vectors in lowercase bold, e.g. ; and entries of vectors and matrices are italic (they are numbers from a field), e.g. and . Index notation is often the clearest way to express definitions, and is used as standard in the literature. The entry in row, column of matrix is indicated by, or . In contrast, a single subscript, e.g., is used to select a matrix (not a matrix entry) from a collection of matrices.
If is an matrix and is an matrix,the matrix product (denoted without multiplication signs or dots) is defined to be the matrix[4] [5] [6] [7] such that for and .
That is, the entry of the product is obtained by multiplying term-by-term the entries of the th row of and the th column of, and summing these products. In other words, is the dot product of the th row of and the th column of .
Therefore, can also be written as
Thus the product is defined if and only if the number of columns in equals the number of rows in, in this case .
In most scenarios, the entries are numbers, but they may be any kind of mathematical objects for which an addition and a multiplication are defined, that are associative, and such that the addition is commutative, and the multiplication is distributive with respect to the addition. In particular, the entries may be matrices themselves (see block matrix).
A vector
x
n
n x 1
X
Xi1=xi.
A
m x n
Ax
y
m x 1
AX.
yi=\sum
n | |
j=1 |
aijxj.
Similarly, a vector
x
n
1 x n
xTA.
xTA=(ATx)T
A
n x p
xTA=yT
yk=\sum
n | |
j=1 |
xjajk.
a ⋅ b
a
b
1 x 1
aTb
bTa,
1 x 1
The figure to the right illustrates diagrammatically the product of two matrices and, showing how each intersection in the product matrix corresponds to a row of and a column of .
= \overset
The values at the intersections, marked with circles in figure to the right, are:
Historically, matrix multiplication has been introduced for facilitating and clarifying computations in linear algebra. This strong relationship between matrix multiplication and linear algebra remains fundamental in all mathematics, as well as in physics, chemistry, engineering and computer science.
If a vector space has a finite basis, its vectors are each uniquely represented by a finite sequence of scalars, called a coordinate vector, whose elements are the coordinates of the vector on the basis. These coordinate vectors form another vector space, which is isomorphic to the original vector space. A coordinate vector is commonly organized as a column matrix (also called a column vector), which is a matrix with only one column. So, a column vector represents both a coordinate vector, and a vector of the original vector space.
A linear map from a vector space of dimension into a vector space of dimension maps a column vector
x=\begin{pmatrix}x1\ x2\ \vdots\ xn\end{pmatrix}
y=A(x)=\begin{pmatrix}a11x1+ … +a1nxn\ a21x1+ … +a2nxn\ \vdots\ am1x1+ … +amnxn\end{pmatrix}.
A=\begin{pmatrix} a11&a12& … &a1n\\ a21&a22& … &a2n\\ \vdots&\vdots&\ddots&\vdots\\ am1&am2& … &amn\\ \end{pmatrix},
x
y=Ax.
If is another linear map from the preceding vector space of dimension, into a vector space of dimension, it is represented by a matrix
B.
BA.
(BA)x=B(Ax)=BAx.
Using a Cartesian coordinate system in a Euclidean plane, the rotation by an angle
\alpha
(x,y)
(x',y')
The composition of the rotation by
\alpha
\beta
\alpha+\beta
As an example, a fictitious factory uses 4 kinds of basic commodities,
b1,b2,b3,b4
m1,m2,m3
f1,f2,f3
A=\begin{pmatrix}1&0&1\ 2&1&1\ 0&1&1\ 1&1&2\ \end{pmatrix}
B=\begin{pmatrix}1&2&1\ 2&3&1\ 4&2&2\ \end{pmatrix}
m1
b1
b2
b3
b4
A
Using matrix multiplication, compute
AB=\begin{pmatrix}5&4&3\ 8&9&5\\ 6&5&3\ 11&9&6\ \end{pmatrix};
AB
1 ⋅ 1+1 ⋅ 2+2 ⋅ 4=11
11
b4
f1
b4
m1
m2
2
m3
f1
In order to produce e.g. 100 units of the final product
f1
f2
f3
(AB)\begin{pmatrix}100\ 80\ 60\ \end{pmatrix}=\begin{pmatrix}1000\ 1820\ 1180\ 2180\end{pmatrix},
1000
b1
1820
b2
1180
b3
2180
b4
AB
The general form of a system of linear equations is
\begin{matrix}a11x1+ … +a1nxn=b1, \ a21x1+ … +a2nxn=b2, \ \vdots \ am1x1+ … +amnxn=bm.\end{matrix}
Using same notation as above, such a system is equivalent with the single matrix equation
Ax=b.
The dot product of two column vectors is the unique entry of the matrix product
xTy,
xT
x
More generally, any bilinear form over a vector space of finite dimension may be expressed as a matrix product
xTAy,
x\daggerAy,
x\dagger
x
Matrix multiplication shares some properties with usual multiplication. However, matrix multiplication is not defined if the number of columns of the first factor differs from the number of rows of the second factor, and it is non-commutative,[9] even when the product remains defined after changing the order of the factors.[10] [11]
An operation is commutative if, given two elements and such that the product
AB
BA
AB=BA.
If and are matrices of respective sizes and, then
AB
BA
AB ≠ BA.
\begin{pmatrix}0&1\ 0&0\end{pmatrix}\begin{pmatrix}0&0\ 1&0\end{pmatrix}=\begin{pmatrix}1&0\ 0&0\end{pmatrix},
\begin{pmatrix}0&0\ 1&0\end{pmatrix}\begin{pmatrix}0&1\ 0&0\end{pmatrix}=\begin{pmatrix}0&0\ 0&1\end{pmatrix}.
This example may be expanded for showing that, if is a matrix with entries in a field, then
AB=BA
A=cI
One special case where commutativity does occur is when and are two (square) diagonal matrices (of the same size); then . Again, if the matrices are over a general ring rather than a field, the corresponding entries in each must also commute with each other for this to hold.
The matrix product is distributive with respect to matrix addition. That is, if are matrices of respective sizes,,, and, one has (left distributivity)
A(B+C)=AB+AC,
(B+C)D=BD+CD.
This results from the distributivity for coefficients by
\sumkaik(bkj+ckj)=\sumkaikbkj+\sumkaikckj
\sumk(bik+cik)dkj=\sumkbikdkj+\sumkcikdkj.
If is a matrix and a scalar, then the matrices
cA
Ac
cA=Ac.
If the product
AB
c(AB)=(cA)B
(AB)c=A(Bc).
These properties result from the bilinearity of the product of scalars:
c\left(\sumkaikbkj\right)=\sumk(caik)bkj
\left(\sumkaikbkj\right)c=\sumkaik(bkjc).
If the scalars have the commutative property, the transpose of a product of matrices is the product, in the reverse order, of the transposes of the factors. That is
(AB)T=BTAT
This identity does not hold for noncommutative entries, since the order between the entries of and is reversed, when one expands the definition of the matrix product.
If and have complex entries, then
(AB)*=A*B*
This results from applying to the definition of matrix product the fact that the conjugate of a sum is the sum of the conjugates of the summands and the conjugate of a product is the product of the conjugates of the factors.
Transposition acts on the indices of the entries, while conjugation acts independently on the entries themselves. It results that, if and have complex entries, one has
(AB)\dagger=B\daggerA\dagger,
where denotes the conjugate transpose (conjugate of the transpose, or equivalently transpose of the conjugate).
Given three matrices and, the products and are defined if and only if the number of columns of equals the number of rows of, and the number of columns of equals the number of rows of (in particular, if one of the products is defined, then the other is also defined). In this case, one has the associative property
(AB)C=A(BC).
As for any associative operation, this allows omitting parentheses, and writing the above products as
This extends naturally to the product of any number of matrices provided that the dimensions match. That is, if are matrices such that the number of columns of equals the number of rows of for, then the product
n | |
\prod | |
i=1 |
Ai=A1A2 … An
These properties may be proved by straightforward but complicated summation manipulations. This result also follows from the fact that matrices represent linear maps. Therefore, the associative property of matrices is simply a specific case of the associative property of function composition.
Although the result of a sequence of matrix products does not depend on the order of operation (provided that the order of the matrices is not changed), the computational complexity may depend dramatically on this order.
For example, if and are matrices of respective sizes, computing needs multiplications, while computing needs multiplications.
Algorithms have been designed for choosing the best order of products; see Matrix chain multiplication. When the number of matrices increases, it has been shown that the choice of the best order has a complexity of
O(nlogn).
P
P
SP(A)=P-1AP.
Similarity transformations map product to products, that is
SP(AB)=SP(A)SP(B).
In fact, one has
P-1(AB)P=P-1A(PP-1)BP =(P-1AP)(P-1BP).
Let us denote
lMn(R)
In
lMn(R)
lMn(R)
If, many matrices do not have a multiplicative inverse. For example, a matrix such that all entries of a row (or a column) are 0 does not have an inverse. If it exists, the inverse of a matrix is denoted, and, thus verifies
AA-1=A-1A=I.
A product of matrices is invertible if and only if each factor is invertible. In this case, one has
(AB)-1=B-1A-1.
When is commutative, and, in particular, when it is a field, the determinant of a product is the product of the determinants. As determinants are scalars, and scalars commute, one has thus
\det(AB)=\det(BA)=\det(A)\det(B).
The other matrix invariants do not behave as well with products. Nevertheless, if is commutative, and have the same trace, the same characteristic polynomial, and the same eigenvalues with the same multiplicities. However, the eigenvectors are generally different if .
One may raise a square matrix to any nonnegative integer power multiplying it by itself repeatedly in the same way as for ordinary numbers. That is,
A0=I,
A1=A,
Ak=\underbrace{AA … A
Computing the th power of a matrix needs times the time of a single matrix multiplication, if it is done with the trivial algorithm (repeated multiplication). As this may be very time consuming, one generally prefers using exponentiation by squaring, which requires less than matrix multiplications, and is therefore much more efficient.
An easy case for exponentiation is that of a diagonal matrix. Since the product of diagonal matrices amounts to simply multiplying corresponding diagonal elements together, the th power of a diagonal matrix is obtained by raising the entries to the power :
\begin{bmatrix} a11&0& … &0\\ 0&a22& … &0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0& … &ann\end{bmatrix}k= \begin{bmatrix}
k | |
a | |
11 |
&0& … &0\\ 0&
k | |
a | |
22 |
& … &0\\ \vdots&\vdots&\ddots&\vdots\\ 0&0& … &
k | |
a | |
nn |
\end{bmatrix}.
The definition of matrix product requires that the entries belong to a semiring, and does not require multiplication of elements of the semiring to be commutative. In many applications, the matrix elements belong to a field, although the tropical semiring is also a common choice for graph shortest path problems.[14] Even in the case of matrices over fields, the product is not commutative in general, although it is associative and is distributive over matrix addition. The identity matrices (which are the square matrices whose entries are zero outside of the main diagonal and 1 on the main diagonal) are identity elements of the matrix product. It follows that the matrices over a ring form a ring, which is noncommutative except if and the ground ring is commutative.
A square matrix may have a multiplicative inverse, called an inverse matrix. In the common case where the entries belong to a commutative ring, a matrix has an inverse if and only if its determinant has a multiplicative inverse in . The determinant of a product of square matrices is the product of the determinants of the factors. The matrices that have an inverse form a group under matrix multiplication, the subgroups of which are called matrix groups. Many classical groups (including all finite groups) are isomorphic to matrix groups; this is the starting point of the theory of group representations.
Matrices are the morphisms of a category, the category of matrices. The objects are the natural numbers that measure the size of matrices, and the composition of morphisms is matrix multiplication. The source of a morphism is the number of columns of the corresponding matrix, and the target is the number of rows.
See main article: Computational complexity of matrix multiplication.
The matrix multiplication algorithm that results from the definition requires, in the worst case, multiplications and additions of scalars to compute the product of two square matrices. Its computational complexity is therefore, in a model of computation for which the scalar operations take constant time.
Rather surprisingly, this complexity is not optimal, as shown in 1969 by Volker Strassen, who provided an algorithm, now called Strassen's algorithm, with a complexity of
O(
log27 | |
n |
) ≈ O(n2.8074).
Since matrix multiplication forms the basis for many algorithms, and many operations on matrices even have the same complexity as matrix multiplication (up to a multiplicative constant), the computational complexity of matrix multiplication appears throughout numerical linear algebra and theoretical computer science.
Other types of products of matrices include:
abT