Matrix multiplication

From testwiki
Jump to navigation Jump to search

Template:Short description

For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The result matrix has the number of rows of the first and the number of columns of the second matrix.

In mathematics, specifically 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 Template:Math and Template:Math is denoted as Template:Math.[1]

Matrix multiplication was first described by the French mathematician Jacques Philippe Marie Binet in 1812,[2] 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.[3][4] 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. Template:Math; vectors in lowercase bold, e.g. Template:Math; and entries of vectors and matrices are italic (they are numbers from a field), e.g. Template:Math and Template:Math. Index notation is often the clearest way to express definitions, and is used as standard in the literature. The entry in row Template:Mvar, column Template:Mvar of matrix Template:Math is indicated by Template:Math, Template:Math or Template:Math. In contrast, a single subscript, e.g. Template:Math, is used to select a matrix (not a matrix entry) from a collection of matrices.

Definitions

Matrix times matrix

If Template:Math is an Template:Math matrix and Template:Math is an Template:Math matrix, 𝐀=(a11a12a1na21a22a2nam1am2amn),𝐁=(b11b12b1pb21b22b2pbn1bn2bnp) the matrix product Template:Math (denoted without multiplication signs or dots) is defined to be the Template:Math matrix[5][6][7][8] 𝐂=(c11c12c1pc21c22c2pcm1cm2cmp) such that cij=ai1b1j+ai2b2j++ainbnj=k=1naikbkj, for Template:Math and Template:Math.

That is, the entry Template:Tmath of the product is obtained by multiplying term-by-term the entries of the Template:Mvarth row of Template:Math and the Template:Mvarth column of Template:Math, and summing these Template:Mvar products. In other words, Template:Tmath is the dot product of the Template:Mvarth row of Template:Math and the Template:Mvarth column of Template:Math.

Therefore, Template:Math can also be written as 𝐂=(a11b11++a1nbn1a11b12++a1nbn2a11b1p++a1nbnpa21b11++a2nbn1a21b12++a2nbn2a21b1p++a2nbnpam1b11++amnbn1am1b12++amnbn2am1b1p++amnbnp)

Thus the product Template:Math is defined if and only if the number of columns in Template:Math equals the number of rows in Template:Math,[1] in this case Template:Math.

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).

Matrix times vector

A vector 𝐱 of length n can be viewed as a column vector, corresponding to an n×1 matrix 𝐗 whose entries are given by 𝐗i1=𝐱i. If 𝐀 is an m×n matrix, the matrix-times-vector product denoted by 𝐀𝐱 is then the vector 𝐲 that, viewed as a column vector, is equal to the m×1 matrix 𝐀𝐗. In index notation, this amounts to:

yi=j=1naijxj.

One way of looking at this is that the changes from "plain" vector to column vector and back are assumed and left implicit.

Vector times matrix

Similarly, a vector 𝐱 of length n can be viewed as a row vector, corresponding to a 1×n matrix. To make it clear that a row vector is meant, it is customary in this context to represent it as the transpose of a column vector; thus, one will see notations such as 𝐱T𝐀. The identity 𝐱T𝐀=(𝐀T𝐱)T holds. In index notation, if 𝐀 is an n×p matrix, 𝐱T𝐀=𝐲T amounts to: yk=j=1nxjajk.

Vector times vector

The dot product πšπ› of two vectors 𝐚 and 𝐛 of equal length is equal to the single entry of the 1×1 matrix resulting from multiplying these vectors as a row and a column vector, thus: 𝐚T𝐛 (or 𝐛T𝐚, which results in the same 1×1 matrix).

Illustration

The figure to the right illustrates diagrammatically the product of two matrices Template:Math and Template:Math, showing how each intersection in the product matrix corresponds to a row of Template:Math and a column of Template:Math. [a11a12a31a32]4×2 matrix[b12b13b22b23]2×3 matrix=[c12c33]4×3 matrix

The values at the intersections, marked with circles in figure to the right, are: c12=a11b12+a12b22c33=a31b13+a32b23.

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, 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, 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 Template:Mvar from a vector space of dimension Template:Mvar into a vector space of dimension Template:Mvar maps a column vector

𝐱=(x1x2xn)

onto the column vector

𝐲=A(𝐱)=(a11x1++a1nxna21x1++a2nxnam1x1++amnxn).

The linear map Template:Mvar is thus defined by the matrix

𝐀=(a11a12a1na21a22a2nam1am2amn),

and maps the column vector 𝐱 to the matrix product

𝐲=𝐀𝐱.

If Template:Mvar is another linear map from the preceding vector space of dimension Template:Mvar, into a vector space of dimension Template:Mvar, it is represented by a Template:Tmath matrix 𝐁. A straightforward computation shows that the matrix of the composite map Template:Tmath is the matrix product 𝐁𝐀. The general formula Template:Tmath) that defines the function composition is instanced here as a specific case of associativity of matrix product (see Template:Slink below):

(𝐁𝐀)𝐱=𝐁(𝐀𝐱)=𝐁𝐀𝐱.

Geometric rotations

Template:See also Using a Cartesian coordinate system in a Euclidean plane, the rotation by an angle α around the origin is a linear map. More precisely, [xy]=[cosαsinαsinαcosα][xy], where the source point (x,y) and its image (x,y) are written as column vectors.

The composition of the rotation by α and that by β then corresponds to the matrix product [cosβsinβsinβcosβ][cosαsinαsinαcosα]=[cosβcosαsinβsinαcosβsinαsinβcosαsinβcosα+cosβsinαsinβsinα+cosβcosα]=[cos(α+β)sin(α+β)sin(α+β)cos(α+β)], 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

The computation of the bottom left entry of 𝐀𝐁 corresponds to the consideration of all paths (highlighted) from basic commodity b4 to final product f1 in the production flow graph.

As an example, a fictitious factory uses 4 kinds of basic commodities, b1,b2,b3,b4 to produce 3 kinds of intermediate goods, m1,m2,m3, which in turn are used to produce 3 kinds of final products, f1,f2,f3. The matrices

𝐀=(101211011112)   and   𝐁=(121231422)

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 m1, one unit of basic commodity b1, two units of b2, no units of b3, and one unit of b4 are needed, corresponding to the first column of 𝐀.

Using matrix multiplication, compute

𝐀𝐁=(543895 6531196);

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 11+12+24=11, reflecting that 11 units of b4 are needed to produce one unit of f1. Indeed, one b4 unit is needed for m1, one for each of two m2, and 2 for each of the four m3 units that go into the f1 unit, see picture.

In order to produce e.g. 100 units of the final product f1, 80 units of f2, and 60 units of f3, the necessary amounts of basic goods can be computed as

(𝐀𝐁)(1008060)=(1000182011802180),

that is, 1000 units of b1, 1820 units of b2, 1180 units of b3, 2180 units of b4 are needed. Similarly, the product matrix 𝐀𝐁 can be used to compute the needed amounts of basic goods for other final-good amount data.[9]

System of linear equations

The general form of a system of linear equations is

a11x1++a1nxn=b1,a21x1++a2nxn=b2,am1x1++amnxn=bm.

Using same notation as above, such a system is equivalent with the single matrix equation

𝐀𝐱=𝐛.

Dot product, bilinear form and sesquilinear form

The dot product of two column vectors is the unique entry of the matrix product

𝐱𝖳𝐲,

where 𝐱𝖳 is the row vector obtained by transposing 𝐱. (As usual, a 1Γ—1 matrix is identified with its unique entry.)

More generally, any bilinear form 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. 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,[10] even when the product remains defined after changing the order of the factors.[11][12]

Non-commutativity

An operation is commutative if, given two elements Template:Math and Template:Math such that the product 𝐀𝐁 is defined, then 𝐁𝐀 is also defined, and 𝐀𝐁=𝐁𝐀.

If Template:Math and Template:Math are matrices of respective sizes Template:Tmath and Template:Tmath, then 𝐀𝐁 is defined if Template:Tmath, and 𝐁𝐀 is defined if Template:Tmath. Therefore, if one of the products is defined, the other one need not be defined. If Template:Tmath, the two products are defined, but have different sizes; thus they cannot be equal. Only if Template:Tmath, that is, if Template:Math and Template:Math 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

(0100)(0010)=(1000),

but

(0010)(0100)=(0001).

This example may be expanded for showing that, if Template:Math is a Template:Tmath matrix with entries in a field Template:Mvar, then 𝐀𝐁=𝐁𝐀 for every Template:Tmath matrix Template:Math with entries in Template:Mvar, if and only if 𝐀=c𝐈 where Template:Tmath, and Template:Math is the Template:Tmath identity matrix. If, instead of a field, the entries are supposed to belong to a ring, then one must add the condition that Template:Mvar belongs to the center of the ring.

One special case where commutativity does occur is when Template:Math and Template:Math are two (square) diagonal matrices (of the same size); then Template:Math.[10] 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 Template:Math are matrices of respective sizes Template:Math, Template:Math, Template:Math, and Template:Math, one has (left distributivity)

𝐀(𝐁+𝐂)=𝐀𝐁+𝐀𝐂,

and (right distributivity)

(𝐁+𝐂)𝐃=𝐁𝐃+𝐂𝐃.[10]

This results from the distributivity for coefficients by

kaik(bkj+ckj)=kaikbkj+kaikckj
k(bik+cik)dkj=kbikdkj+kcikdkj.

Product with a scalar

If Template:Math is a matrix and Template:Mvar a scalar, then the matrices c𝐀 and 𝐀c are obtained by left or right multiplying all entries of Template:Math by Template:Mvar. If the scalars have the commutative property, then c𝐀=𝐀c.

If the product 𝐀𝐁 is defined (that is, the number of columns of Template:Math equals the number of rows of Template:Math), then

c(𝐀𝐁)=(c𝐀)𝐁 and (𝐀𝐁)c=𝐀(𝐁c).

If the scalars have the commutative property, then all four matrices are equal. More generally, all four are equal if Template:Math belongs to the center of a ring containing the entries of the matrices, because in this case, Template:Math for all matrices Template:Math.

These properties result from the bilinearity of the product of scalars:

c(kaikbkj)=k(caik)bkj
(kaikbkj)c=kaik(bkjc).

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 Template:Math and Template:Math is reversed, when one expands the definition of the matrix product.

Complex conjugate

If Template:Math and Template:Math have complex entries, then

(𝐀𝐁)*=𝐀*𝐁*

where Template:Math 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 Template:Math and Template:Math have complex entries, one has

(𝐀𝐁)=𝐁𝐀,

where Template:Math denotes the conjugate transpose (conjugate of the transpose, or equivalently transpose of the conjugate).

Associativity

Given three matrices Template:Math and Template:Math, the products Template:Math and Template:Math are defined if and only if the number of columns of Template:Math equals the number of rows of Template:Math, and the number of columns of Template:Math equals the number of rows of Template:Math (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 Template:Tmath

This extends naturally to the product of any number of matrices provided that the dimensions match. That is, if Template:Math are matrices such that the number of columns of Template:Math equals the number of rows of Template:Math for Template:Math, then the product

i=1n𝐀i=𝐀1𝐀2𝐀n

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 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.

Computational complexity depends on parenthesization

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 Template:Math and Template:Math are matrices of respective sizes Template:Math, computing Template:Math needs Template:Math multiplications, while computing Template:Math needs Template:Math multiplications.

Algorithms have been designed for choosing the best order of products; see Matrix chain multiplication. When the number Template:Mvar of matrices increases, it has been shown that the choice of the best order has a complexity of O(nlogn).[13][14]

Application to similarity

Any invertible matrix 𝐏 defines a similarity transformation (on square matrices of the same size as 𝐏)

S𝐏(𝐀)=𝐏1𝐀𝐏.

Similarity transformations map product to products, that is

S𝐏(𝐀𝐁)=S𝐏(𝐀)S𝐏(𝐁).

In fact, one has

𝐏1(𝐀𝐁)𝐏=𝐏1𝐀(𝐏𝐏1)𝐁𝐏=(𝐏1𝐀𝐏)(𝐏1𝐁𝐏).

Square matrices

Let us denote β„³n(R) the set of Template:Math square matrices with entries in a ring Template:Mvar, which, in practice, is often a field.

In β„³n(R), the product is defined for every pair of matrices. This makes β„³n(R) a ring, which has the identity matrix Template:Math 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|associative Template:Mvar-algebra]].

If Template:Math, 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 Template:Math is denoted Template:Math, and, thus verifies

𝐀𝐀1=𝐀1𝐀=𝐈.

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

(𝐀𝐁)1=𝐁1𝐀1.

When Template:Mvar 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(𝐀𝐁)=det(𝐁𝐀)=det(𝐀)det(𝐁).

The other matrix invariants do not behave as well with products. Nevertheless, if Template:Mvar is commutative, Template:Math and Template:Math have the same trace, the same characteristic polynomial, and the same eigenvalues with the same multiplicities. However, the eigenvectors are generally different if Template:Math.

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,

𝐀0=𝐈,
𝐀1=𝐀,
𝐀k=𝐀𝐀𝐀k times.

Computing the Template:Mvarth power of a matrix needs Template:Math 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 Template:Math 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 Template:Mvarth power of a diagonal matrix is obtained by raising the entries to the power Template:Mvar:

[a11000a22000ann]k=[a11k000a22k000annk].

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.[15] 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 Template:Math matrices over a ring form a ring, which is noncommutative except if Template:Math 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 Template:Mvar, a matrix has an inverse if and only if its determinant has a multiplicative inverse in Template:Mvar. The determinant of a product of square matrices is the product of the determinants of the factors. The Template:Math 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.

Computational complexity

Template:Main Template:For

Improvement of estimates of exponent Template:Math over time for the computational complexity of matrix multiplication O(nω)

The matrix multiplication algorithm that results from the definition requires, in the worst case, Template:Tmath multiplications and Template:Tmath additions of scalars to compute the product of two square Template:Math matrices. Its computational complexity is therefore Template:Tmath, 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(nlog27)O(n2.8074).[16] Strassen's algorithm can be parallelized to further improve the performance.[17] Template:As of, the best peer-reviewed matrix multiplication algorithm is by Virginia Vassilevska Williams, Yinzhan Xu, Zixuan Xu, and Renfei Zhou and has complexity Template:Math.[18][19] It is not known whether matrix multiplication can be performed in Template:Math time.[20] This would be optimal, since one must read the Template:Tmath 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:

See also

  • Matrix calculus, for the interaction of matrix multiplication with operations from calculus

Notes

Template:Reflist

References

Template:Commons category Template:Wikibooks Template:Wikibooks Template:Refbegin

  • Henry Cohn, Robert Kleinberg, BalΓ‘zs Szegedy, and Chris Umans. Group-theoretic Algorithms for Matrix Multiplication. Template:Arxiv. 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. Template:Arxiv. Proceedings of the 44th Annual IEEE Symposium on Foundations of Computer Science, 11–14 October 2003, Cambridge, MA, IEEE Computer Society, pp. 438–449.
  • Template:Cite journal
  • Template:Citation
  • Knuth, D.E., The Art of Computer Programming Volume 2: Seminumerical Algorithms. Addison-Wesley Professional; 3 edition (November 14, 1997). Template:Isbn. pp. 501.
  • Template:Citation.
  • Ran Raz. On the complexity of matrix product. In Proceedings of the thirty-fourth annual ACM symposium on Theory of computing. ACM Press, 2002. Template:Doi.
  • 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.
  • Template:Citation
  • Template:Cite book

Template:Refend

Template:Linear algebra