![Matrix multiplication qtl1](https://upload.wikimedia.org/wikipedia/commons/1/18/Matrix_multiplication_qtl1.svg)
In
mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
, particularly in
linear algebra, matrix multiplication is a
binary operation
In mathematics, a binary operation or dyadic operation is a rule for combining two elements (called operands) to produce another element. More formally, a binary operation is an operation of arity two.
More specifically, an internal binary op ...
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 .
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
Statistics (from German language, German: ''wikt:Statistik#German, Statistik'', "description of a State (polity), state, a country") is the discipline that concerns the collection, organization, analysis, interpretation, and presentation of ...
,
physics,
economics, and
engineering.
Computing matrix products is a central operation in all computational applications of linear algebra.
Notation
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.
Definition
If is an matrix and is an matrix,
:
the ''matrix product'' (denoted without multiplication signs or dots) is defined to be the matrix
:
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
In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement f ...
, 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
In mathematics, a block matrix or a partitioned matrix is a matrix that is '' interpreted'' as having been broken into sections called blocks or submatrices. Intuitively, a matrix interpreted as a block matrix can be visualized as the original mat ...
).
Illustration
![Matrix multiplication diagram 2](https://upload.wikimedia.org/wikipedia/commons/e/eb/Matrix_multiplication_diagram_2.svg)
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 .
:
The values at the intersections marked with circles are:
:
Fundamental applications
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
Chemistry is the science, scientific study of the properties and behavior of matter. It is a natural science that covers the Chemical element, elements that make up matter to the chemical compound, compounds made of atoms, molecules and ions ...
,
engineering and
computer science.
Linear maps
If a
vector space has a finite
basis, its vectors are each uniquely represented by a finite
sequence of scalars, called a
coordinate vector
In linear algebra, a coordinate vector is a representation of a vector as an ordered list of numbers (a tuple) that describes the vector in terms of a particular ordered basis. An easy example may be a position such as (5, 2, 1) in a 3-dimensiona ...
, whose elements are the
coordinates
In geometry, a coordinate system is a system that uses one or more numbers, or coordinates, to uniquely determine the position of the points or other geometric elements on a manifold such as Euclidean space. The order of the coordinates is sig ...
of the vector on the basis. These coordinate vectors form another vector space, which is
isomorphic
In mathematics, an isomorphism is a structure-preserving mapping between two structures of the same type that can be reversed by an inverse mapping. Two mathematical structures are isomorphic if an isomorphism exists between them. The word is ...
to the original vector space. A coordinate vector is commonly organized as a
column matrix
In linear algebra, a column vector with m elements is an m \times 1 matrix consisting of a single column of m entries, for example,
\boldsymbol = \begin x_1 \\ x_2 \\ \vdots \\ x_m \end.
Similarly, a row vector is a 1 \times n matrix for some n, ...
(also called ''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
:
onto the column vector
:
The linear map is thus defined by the matrix
:
and maps the column vector
to the matrix product
:
If is another linear map from the preceding vector space of dimension , into a vector space of dimension , it is represented by a matrix
A straightforward computation shows that the matrix of the
composite map is the matrix product
The general formula ) that defines the function composition is instanced here as a specific case of associativity of matrix product (see below):
:
Geometric rotations
Using a
Cartesian coordinate system in a Euclidean plane, the
rotation
Rotation, or spin, is the circular movement of an object around a '' central axis''. A two-dimensional rotating object has only one possible central axis and can rotate in either a clockwise or counterclockwise direction. A three-dimensional ...
by an angle
around the
origin is a linear map.
More precisely,
:
where the source point
and its image
are written as column vectors.
The composition of the rotation by
and that by
then corresponds to the matrix product
:
where appropriate
trigonometric identities are employed for the second equality.
That is, the composition corresponds to the rotation by angle
, as expected.
Resource allocation in economics
![Mmult factory svg](https://upload.wikimedia.org/wikipedia/commons/3/30/Mmult_factory_svg.svg)
As an example, a fictitious factory uses 4 kinds of ,
to produce 3 kinds of
intermediate goods,
, which in turn are used to produce 3 kinds of
final products,
. The matrices
:
and
provide the amount of basic commodities needed for a given amount of intermediate goods, and the amount of intermediate goods needed for a given amount of final products, respectively.
For example, to produce one unit of intermediate good
, one unit of basic commodity
, two units of
, no units of
, and one unit of
are needed, corresponding to the first column of
.
Using matrix multiplication, compute
:
this matrix directly provides the amounts of basic commodities needed for given amounts of final goods. For example, the bottom left entry of
is computed as
, reflecting that
units of
are needed to produce one unit of
. Indeed, one
unit is needed for
, 2 for
, and
for each of the two
units that go into the
unit, see picture.
In order to produce e.g. 100 units of the final product
, 80 units of
, and 60 units of
, the necessary amounts of basic goods can be computed as
:
that is,
units of
,
units of
,
units of
,
units of
are needed.
Similarly, the product matrix
can be used to compute the needed amounts of basic goods for other final-good amount data.
System of linear equations
The general form of a
system of linear equations
In mathematics, a system of linear equations (or linear system) is a collection of one or more linear equations involving the same variable (math), variables.
For example,
:\begin
3x+2y-z=1\\
2x-2y+4z=-2\\
-x+\fracy-z=0
\end
is a system of three ...
is
:
Using same notation as above, such a system is equivalent with the single matrix
equation
In mathematics, an equation is a formula that expresses the equality of two expressions, by connecting them with the equals sign . The word ''equation'' and its cognates in other languages may have subtly different meanings; for example, in ...
:
Dot product, bilinear form and sesquilinear form
The
dot product of two column vectors is the matrix product
:
where
is the
row vector obtained by
transposing and the resulting 1×1 matrix is identified with its unique entry.
More generally, any
bilinear form
In mathematics, a bilinear form is a bilinear map on a vector space (the elements of which are called '' vectors'') over a field ''K'' (the elements of which are called ''scalars''). In other words, a bilinear form is a function that is linear i ...
over a vector space of finite dimension may be expressed as a matrix product
:
and any
sesquilinear form may be expressed as
:
where
denotes the
conjugate transpose of
(conjugate of the transpose, or equivalently transpose of the conjugate).
General properties
Matrix multiplication shares some properties with usual
multiplication
Multiplication (often denoted by the cross symbol , by the mid-line dot operator , by juxtaposition, or, on computers, by an asterisk ) is one of the four elementary mathematical operations of arithmetic, with the other ones being additi ...
. 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,
even when the product remains definite after changing the order of the factors.
Non-commutativity
An operation is
commutative if, given two elements and such that the product
is defined, then
is also defined, and
If and are matrices of respective sizes and , then
is defined if , and
is defined if . Therefore, if one of the products is defined, the other one need not be defined. If , the two products are defined, but have different sizes; thus they cannot be equal. Only if , that is, if and are
square matrices of the same size, are both products defined and of the same size. Even in this case, one has in general
:
For example
:
but
:
This example may be expanded for showing that, if is a matrix with entries in a
field , then
for every matrix with entries in ,
if and only if where , and is the
identity matrix
In linear algebra, the identity matrix of size n is the n\times n square matrix with ones on the main diagonal and zeros elsewhere.
Terminology and notation
The identity matrix is often denoted by I_n, or simply by I if the size is immaterial o ...
. If, instead of a field, the entries are supposed to belong to a
ring, then one must add the condition that belongs to the
center of the ring.
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.
Distributivity
The matrix product is
distributive with respect to
matrix addition. That is, if are matrices of respective sizes , , , and , one has (left distributivity)
:
and (right distributivity)
:
This results from the distributivity for coefficients by
:
:
Product with a scalar
If is a matrix and a scalar, then the matrices
and
are obtained by left or right multiplying all entries of by . If the scalars have the
commutative property, then
If the product
is defined (that is, the number of columns of equals the number of rows of ), then
:
and
If the scalars have the commutative property, then all four matrices are equal. More generally, all four are equal if belongs to the
center of a
ring containing the entries of the matrices, because in this case, for all matrices .
These properties result from the
bilinearity of the product of scalars:
:
:
Transpose
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
:
where
T denotes the transpose, that is the interchange of rows and columns.
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.
Complex conjugate
If and have
complex entries, then
:
where denotes the entry-wise
complex conjugate of a matrix.
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
:
where denotes the
conjugate transpose (conjugate of the transpose, or equivalently transpose of the conjugate).
Associativity
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
:
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
:
is defined and does not depend on the
order of the multiplications, if the order of the matrices is kept fixed.
These properties may be proved by straightforward but complicated
summation
In mathematics, summation is the addition of a sequence of any kind of numbers, called ''addends'' or ''summands''; the result is their ''sum'' or ''total''. Beside numbers, other types of values can be summed as well: functions, vectors, mat ...
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
In mathematics, function composition is an operation that takes two functions and , and produces a function such that . In this operation, the function is applied to the result of applying the function to . That is, the functions and ...
.
Computational complexity depends on parenthezation
Although the result of a sequence of matrix products does not depend on the
order of operation
In mathematics and computer programming, the order of operations (or operator precedence) is a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.
For exampl ...
(provided that the order of the matrices is not changed), the
computational complexity
In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations) ...
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
Application to similarity
Any
invertible matrix defines a
similarity transformation (on square matrices of the same size as
)
:
Similarity transformations map product to products, that is
:
In fact, one has
:
Square matrices
Let us denote
the set of
square matrices with entries in a
ring , which, in practice, is often a
field.
In
, the product is defined for every pair of matrices. This makes
a
ring, which has the
identity matrix
In linear algebra, the identity matrix of size n is the n\times n square matrix with ones on the main diagonal and zeros elsewhere.
Terminology and notation
The identity matrix is often denoted by I_n, or simply by I if the size is immaterial o ...
as
identity element (the matrix whose diagonal entries are equal to 1 and all other entries are 0). This ring is also an
associative -algebra.
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
:
A matrix that has an inverse is an
invertible matrix. Otherwise, it is a
singular matrix.
A product of matrices is invertible if and only if each factor is invertible. In this case, one has
:
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
:
The other matrix
invariants do not behave as well with products. Nevertheless, if is commutative, and have the same
trace, the same
characteristic polynomial
In linear algebra, the characteristic polynomial of a square matrix is a polynomial which is invariant under matrix similarity and has the eigenvalues as roots. It has the determinant and the trace of the matrix among its coefficients. The chara ...
, and the same
eigenvalues
In linear algebra, an eigenvector () or characteristic vector of a linear transformation is a nonzero vector that changes at most by a scalar factor when that linear transformation is applied to it. The corresponding eigenvalue, often denoted b ...
with the same multiplicities. However, the
eigenvectors are generally different if .
Powers of a matrix
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,
:
:
:
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 :
:
Abstract algebra
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. Even in the case of matrices over fields, the product is not commutative in general, although it is
associative
In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement f ...
and is
distributive over
matrix addition. The
identity matrices
In linear algebra, the identity matrix of size n is the n\times n square matrix with ones on the main diagonal and zeros elsewhere.
Terminology and notation
The identity matrix is often denoted by I_n, or simply by I if the size is immaterial or ...
(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
In mathematics, a commutative ring is a ring in which the multiplication operation is commutative. The study of commutative rings is called commutative algebra. Complementarily, noncommutative algebra is the study of ring properties that are not sp ...
, 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 group
Finite is the opposite of infinite. It may refer to:
* Finite number (disambiguation)
* Finite set, a set whose cardinality (number of elements) is some natural number
* Finite verb, a verb form that has a subject, usually being inflected or marked ...
s) are
isomorphic
In mathematics, an isomorphism is a structure-preserving mapping between two structures of the same type that can be reversed by an inverse mapping. Two mathematical structures are isomorphic if an isomorphism exists between them. The word is ...
to matrix groups; this is the starting point of the theory of
group representations.
Computational complexity
![MatrixMultComplexity svg](https://upload.wikimedia.org/wikipedia/commons/5/5b/MatrixMultComplexity_svg.svg)
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
In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations) ...
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
In linear algebra, the Strassen algorithm, named after Volker Strassen, is an algorithm for matrix multiplication. It is faster than the standard matrix multiplication algorithm for large matrices, with a better asymptotic complexity, although th ...
, with a complexity of
[
]
Strassen's algorithm can be parallelized to further improve the performance.
, the best matrix multiplication algorithm is by Josh Alman and
Virginia Vassilevska Williams and has complexity .
[
]
It is not known whether matrix multiplication can be performed in time. This would be optimal, since one must read the elements of a matrix in order to multiply it with another matrix.
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.
Generalizations
Other types of products of matrices include:
*
Block matrix multiplication
*
Cracovian product
In astronomical and geodetic calculations, Cracovians are a clerical convenience introduced in the 1930s by Tadeusz Banachiewicz for solving systems of linear equations by hand. Such systems can be written as in matrix notation where x and b ...
, defined as
*
Frobenius inner product, the
dot product of matrices considered as vectors, or, equivalently the sum of the entries of the Hadamard product
*
Hadamard product of two matrices of the same size, resulting in a matrix of the same size, which is the product entry-by-entry
*
Kronecker product or
tensor product, the generalization to any size of the preceding
*
Khatri-Rao product and
Face-splitting product
*
Outer product
In linear algebra, the outer product of two coordinate vector
In linear algebra, a coordinate vector is a representation of a vector as an ordered list of numbers (a tuple) that describes the vector in terms of a particular ordered basis. An ea ...
, also called
dyadic product or
tensor product of two column matrices, which is
*
Scalar multiplication
See also
*
Matrix calculus, for the interaction of matrix multiplication with operations from calculus
Notes
References
* Henry Cohn,
Robert Kleinberg,
Balázs Szegedy
Balázs Szegedy is a Hungarian mathematician whose research concerns combinatorics and graph theory.
Szegedy earned a master's degree in 1998 and a PhD in 2003 from Eötvös Loránd University in Budapest. , and Chris Umans. Group-theoretic Algorithms for Matrix Multiplication. . ''Proceedings of the 46th Annual Symposium on Foundations of Computer Science'', 23–25 October 2005, Pittsburgh, PA, IEEE Computer Society, pp. 379–388.
* Henry Cohn, Chris Umans. A Group-theoretic Approach to Fast Matrix Multiplication. . ''Proceedings of the 44th Annual IEEE Symposium on Foundations of Computer Science'', 11–14 October 2003, Cambridge, MA, IEEE Computer Society, pp. 438–449.
*
*
*
Knuth, D.E., ''
The Art of Computer Programming Volume 2: Seminumerical Algorithms''. Addison-Wesley Professional; 3 edition (November 14, 1997). . pp. 501.
* .
*
Ran Raz. On the complexity of matrix product. In Proceedings of the thirty-fourth annual ACM symposium on Theory of computing. ACM Press, 2002. .
* Robinson, Sara, ''Toward an Optimal Algorithm for Matrix Multiplication,'' SIAM News 38(9), November 2005
PDF* Strassen, Volker, ''Gaussian Elimination is not Optimal'', Numer. Math. 13, p. 354-356, 1969.
*
*
{{Linear algebra
Matrix theory
Bilinear maps
Multiplication
Numerical linear algebra