Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Matrix multiplication
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Mathematical operation in linear algebra}} [[File:Matrix multiplication qtl1.svg|thumb|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 (mathematics)|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 {{math|'''A'''}} and {{math|'''B'''}} is denoted as {{math|'''AB'''}}.<ref name=":1">{{Cite web|last=Nykamp|first=Duane|title=Multiplying matrices and vectors|url=https://mathinsight.org/matrix_vector_multiplication|access-date=September 6, 2020|website=Math Insight}}</ref> Matrix multiplication was first described by the French mathematician [[Jacques Philippe Marie Binet]] in 1812,<ref>{{MacTutor|id=Binet|title=Jacques Philippe Marie Binet}}</ref> to represent the [[composition of functions|composition]] of [[linear map]]s 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]].<ref name="Physics 1991">{{cite book|title=Encyclopaedia of Physics|edition=2nd|first1=R. G. |last1=Lerner|author1-link=Rita G. Lerner | first2= G. L. |last2 = Trigg|publisher=VHC publishers|date=1991|isbn=978-3-527-26954-9}}</ref><ref>{{cite book|title=McGraw Hill Encyclopaedia of Physics|edition=2nd|first=C. B.|last=Parker|date=1994|publisher=McGraw-Hill |isbn=978-0-07-051400-3|url-access=registration|url=https://archive.org/details/mcgrawhillencycl1993park}}</ref> 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. {{math|'''A'''}}; [[Euclidean vector|vectors]] in lowercase bold, e.g. {{math|'''a'''}}; and entries of vectors and matrices are italic (they are numbers from a field), e.g. {{math|''A''}} and {{math|''a''}}. [[Index notation]] is often the clearest way to express definitions, and is used as standard in the literature. The entry in row {{mvar|i}}, column {{mvar|j}} of matrix {{math|'''A'''}} is indicated by {{math|('''A''')<sub>''ij''</sub>}}, {{math|''A''<sub>''ij''</sub>}} or {{math|''a''<sub>''ij''</sub>}}. In contrast, a single subscript, e.g. {{math|'''A'''<sub>1</sub>, '''A'''<sub>2</sub>}}, is used to select a matrix (not a matrix entry) from a collection of matrices. ==Definitions== ===Matrix times matrix=== If {{math|'''A'''}} is an {{math|''m'' Γ ''n''}} matrix and {{math|'''B'''}} is an {{math|''n'' Γ ''p''}} matrix, <math display="block">\mathbf{A}=\begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \\ \end{pmatrix},\quad\mathbf{B}=\begin{pmatrix} b_{11} & b_{12} & \cdots & b_{1p} \\ b_{21} & b_{22} & \cdots & b_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ b_{n1} & b_{n2} & \cdots & b_{np} \\ \end{pmatrix}</math> the ''matrix product'' {{math|1='''C''' = '''AB'''}} (denoted without multiplication signs or dots) is defined to be the {{math|''m'' Γ ''p''}} matrix<ref>{{cite book| title=Linear Algebra | edition=4th | first1 = S. | last1 = Lipschutz | first2 = M. | last2 = Lipson|series=Schaum's Outlines | publisher=McGraw Hill (USA) | date=2009 | pages=30β31 | isbn=978-0-07-154352-1}}</ref><ref>{{cite book | title=Mathematical methods for physics and engineering | url=https://archive.org/details/mathematicalmeth00rile | url-access = registration | first1 = K. F. | last1 = Riley | first2 = M. P. | last2 = Hobson | first3 = S. J. | last3 = Bence| publisher=Cambridge University Press | date=2010 | isbn=978-0-521-86153-3}}</ref><ref>{{cite book | title=Calculus, A Complete Course | edition=3rd| first = R. A. | last = Adams|publisher=Addison Wesley |date=1995 |page=627 |isbn=0-201-82823-5}}</ref><ref>{{cite book|title=Matrix Analysis | last = Horn | first = Johnson |edition=2nd | publisher=Cambridge University Press | date=2013 |page=6 |isbn=978-0-521-54823-6}}</ref> <math display="block">\mathbf{C} = \begin{pmatrix} c_{11} & c_{12} & \cdots & c_{1p} \\ c_{21} & c_{22} & \cdots & c_{2p} \\ \vdots & \vdots & \ddots & \vdots \\ c_{m1} & c_{m2} & \cdots & c_{mp} \\ \end{pmatrix}</math> such that <math display="block"> c_{ij} = a_{i1} b_{1j} + a_{i2} b_{2j} + \cdots + a_{in} b_{nj} = \sum_{k=1}^n a_{ik} b_{kj}, </math> for {{math|1=''i'' = 1, ..., ''m''}} and {{math|1=''j'' = 1, ..., ''p''}}. That is, the entry {{tmath|c_{ij} }} of the product is obtained by multiplying term-by-term the entries of the {{mvar|i}}th row of {{math|'''A'''}} and the {{mvar|j}}th column of {{math|'''B'''}}, and summing these {{mvar|n}} products. In other words, {{tmath|c_{ij} }} is the [[dot product]] of the {{mvar|i}}th row of {{math|'''A'''}} and the {{mvar|j}}th column of {{math|'''B'''}}. Therefore, {{math|'''AB'''}} can also be written as <math display="block">\mathbf{C} = \begin{pmatrix} a_{11}b_{11} +\cdots + a_{1n}b_{n1} & a_{11}b_{12} +\cdots + a_{1n}b_{n2} & \cdots & a_{11}b_{1p} +\cdots + a_{1n}b_{np} \\ a_{21}b_{11} +\cdots + a_{2n}b_{n1} & a_{21}b_{12} +\cdots + a_{2n}b_{n2} & \cdots & a_{21}b_{1p} +\cdots + a_{2n}b_{np} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1}b_{11} +\cdots + a_{mn}b_{n1} & a_{m1}b_{12} +\cdots + a_{mn}b_{n2} & \cdots & a_{m1}b_{1p} +\cdots + a_{mn}b_{np} \\ \end{pmatrix} </math> Thus the product {{math|'''AB'''}} is defined if and only if the number of columns in {{math|'''A'''}} equals the number of rows in {{math|'''B'''}},<ref name=":1" /> in this case {{math|''n''}}. In most scenarios, the entries are numbers, but they may be any kind of [[mathematical object]]s for which an addition and a multiplication are defined, that are [[associative property|associative]], and such that the addition is [[commutative property|commutative]], and the multiplication is [[distributive property|distributive]] with respect to the addition. In particular, the entries may be matrices themselves (see [[block matrix]]). ===Matrix times vector=== A vector <math>\mathbf x</math> of length <math>n</math> can be viewed as a [[column vector]], corresponding to an <math>n\times1</math> matrix <math>\mathbf X</math> whose entries are given by <math>\mathbf X_{i1}=\mathbf x_i.</math> If <math>\mathbf A</math> is an <math>m\times n</math> matrix, the matrix-times-vector product denoted by <math>\mathbf {Ax}</math> is then the vector <math>\mathbf y</math> that, viewed as a column vector, is equal to the <math>m\times1</math> matrix <math>\mathbf{AX}.</math> In index notation, this amounts to: :<math>y_i=\sum_{j=1}^n a_{ij}x_j.</math> 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 <math>\mathbf x</math> of length <math>n</math> can be viewed as a [[row vector]], corresponding to a <math>1\times n</math> 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 <math>\mathbf{x}^\mathrm{T}\mathbf{A}.</math> The identity <math>\mathbf{x}^\mathrm{T}\mathbf{A}=(\mathbf{A}^\mathrm{T}\mathbf{x})^\mathrm{T}</math> holds. In index notation, if <math>\mathbf A</math> is an <math>n\times p</math> matrix, <math>\mathbf{x}^\mathrm{T}\mathbf{A}=\mathbf{y}^\mathrm{T}</math> amounts to: <math>y_k=\sum_{j=1}^n x_j a_{jk}.</math> ===Vector times vector=== The [[dot product]] <math>\mathbf a\cdot\mathbf b</math> of two vectors <math>\mathbf a</math> and <math>\mathbf b</math> of equal length is equal to the single entry of the <math>1\times 1</math> matrix resulting from multiplying these vectors as a row and a column vector, thus: <math>\mathbf{a}^\mathrm{T}\mathbf{b}</math> (or <math>\mathbf{b}^\mathrm{T}\mathbf{a},</math> which results in the same <math>1\times 1</math> matrix). ===Illustration=== [[File:Matrix multiplication diagram 2.svg|right|thumb]] The figure to the right illustrates diagrammatically the product of two matrices {{math|'''A'''}} and {{math|'''B'''}}, showing how each intersection in the product matrix corresponds to a row of {{math|'''A'''}} and a column of {{math|'''B'''}}. <math display="block"> \overset{4\times 2 \text{ matrix}}{\begin{bmatrix} a_{11} & a_{12} \\ \cdot & \cdot \\ a_{31} & a_{32} \\ \cdot & \cdot \\ \end{bmatrix}} \overset{2\times 3\text{ matrix}}{\begin{bmatrix} \cdot & b_{12} & b_{13} \\ \cdot & b_{22} & b_{23} \\ \end{bmatrix}} = \overset{4\times 3\text{ matrix}}{\begin{bmatrix} \cdot & c_{12} & \cdot \\ \cdot & \cdot & \cdot \\ \cdot & \cdot & c_{33} \\ \cdot & \cdot & \cdot \\ \end{bmatrix}} </math> The values at the intersections, marked with circles in figure to the right, are: <math display="block">\begin{align} c_{12} & = a_{11} b_{12} + a_{12} b_{22} \\ c_{33} & = a_{31} b_{13} + a_{32} b_{23} . \end{align}</math> ==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 (linear algebra)|basis]], its vectors are each uniquely represented by a finite [[sequence (mathematics)|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 [[isomorphism|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]] {{mvar|A}} from a vector space of dimension {{mvar|n}} into a vector space of dimension {{mvar|m}} maps a column vector :<math>\mathbf x=\begin{pmatrix}x_1 \\ x_2 \\ \vdots \\ x_n\end{pmatrix}</math> onto the column vector :<math>\mathbf y= A(\mathbf x)= \begin{pmatrix}a_{11}x_1+\cdots + a_{1n}x_n\\ a_{21}x_1+\cdots + a_{2n}x_n \\ \vdots \\ a_{m1}x_1+\cdots + a_{mn}x_n\end{pmatrix}.</math> The linear map {{mvar|A}} is thus defined by the matrix :<math>\mathbf{A}=\begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \\ \end{pmatrix}, </math> and maps the column vector <math>\mathbf x</math> to the matrix product :<math>\mathbf y = \mathbf {Ax}.</math> If {{mvar|B}} is another linear map from the preceding vector space of dimension {{mvar|m}}, into a vector space of dimension {{mvar|p}}, it is represented by a {{tmath|p\times m}} matrix <math>\mathbf B.</math> A straightforward computation shows that the matrix of the [[function composition|composite map]] {{tmath|B\circ A}} is the matrix product <math>\mathbf {BA}.</math> The general formula {{tmath|1=(B\circ A)(\mathbf x) = B(A(\mathbf x))}}) that defines the function composition is instanced here as a specific case of associativity of matrix product (see {{slink||Associativity}} below): :<math>(\mathbf{BA})\mathbf x = \mathbf{B}(\mathbf {Ax}) = \mathbf{BAx}.</math> ====Geometric rotations==== {{See also|Rotation matrix}} Using a [[Cartesian coordinate]] system in a Euclidean plane, the [[rotation (mathematics)|rotation]] by an angle <math>\alpha</math> around the [[origin (mathematics)|origin]] is a linear map. More precisely, <math display="block"> \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos \alpha & - \sin \alpha \\ \sin \alpha & \cos \alpha \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix},</math> where the source point <math>(x,y)</math> and its image <math>(x',y')</math> are written as column vectors. The composition of the rotation by <math>\alpha</math> and that by <math>\beta</math> then corresponds to the matrix product <math display="block">\begin{bmatrix} \cos \beta & - \sin \beta \\ \sin \beta & \cos \beta \end{bmatrix} \begin{bmatrix} \cos \alpha & - \sin \alpha \\ \sin \alpha & \cos \alpha \end{bmatrix} = \begin{bmatrix} \cos \beta \cos \alpha - \sin \beta \sin \alpha & - \cos \beta \sin \alpha - \sin \beta \cos \alpha \\ \sin \beta \cos \alpha + \cos \beta \sin \alpha & - \sin \beta \sin \alpha + \cos \beta \cos \alpha \end{bmatrix} = \begin{bmatrix} \cos (\alpha+\beta) & - \sin(\alpha+\beta) \\ \sin(\alpha+\beta) & \cos(\alpha+\beta) \end{bmatrix},</math> where appropriate [[List of trigonometric identities#Angle sum and difference identities|trigonometric identities]] are employed for the second equality. That is, the composition corresponds to the rotation by angle <math>\alpha+\beta</math>, as expected. ====Resource allocation in economics==== [[File:Mmult factory svg.svg|thumb|400px|The computation of the bottom left entry of <math>\mathbf{AB}</math> corresponds to the consideration of all paths (highlighted) from basic commodity <math>b_4</math> to final product <math>f_1</math> in the production flow graph.]] As an example, a fictitious factory uses 4 kinds of [[primary commodity|basic commodities]], <math>b_1, b_2, b_3, b_4</math> to produce 3 kinds of [[intermediate good]]s, <math>m_1, m_2, m_3</math>, which in turn are used to produce 3 kinds of [[final product]]s, <math>f_1, f_2, f_3</math>. The matrices :<math>\mathbf{A} = \begin{pmatrix} 1 & 0 & 1 \\ 2 & 1 & 1 \\ 0 & 1 & 1 \\ 1 & 1 & 2 \\ \end{pmatrix} </math> and <math>\mathbf{B} = \begin{pmatrix} 1 & 2 & 1 \\ 2 & 3 & 1 \\ 4 & 2 & 2 \\ \end{pmatrix} </math> 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 <math>m_1</math>, one unit of basic commodity <math>b_1</math>, two units of <math>b_2</math>, no units of <math>b_3</math>, and one unit of <math>b_4</math> are needed, corresponding to the first column of <math>\mathbf{A}</math>. Using matrix multiplication, compute :<math>\mathbf{AB} = \begin{pmatrix} 5 & 4 & 3 \\ 8 & 9 & 5 \\\ 6 & 5 & 3 \\ 11 & 9 & 6 \\ \end{pmatrix} ;</math> this matrix directly provides the amounts of basic commodities needed for given amounts of final goods. For example, the bottom left entry of <math>\mathbf{AB}</math> is computed as <math>1 \cdot 1 + 1 \cdot 2 + 2 \cdot 4 = 11</math>, reflecting that <math>11</math> units of <math>b_4</math> are needed to produce one unit of <math>f_1</math>. Indeed, one <math>b_4</math> unit is needed for <math>m_1</math>, one for each of two <math>m_2</math>, and <math>2</math> for each of the four <math>m_3</math> units that go into the <math>f_1</math> unit, see picture. In order to produce e.g. 100 units of the final product <math>f_1</math>, 80 units of <math>f_2</math>, and 60 units of <math>f_3</math>, the necessary amounts of basic goods can be computed as :<math>(\mathbf{AB}) \begin{pmatrix} 100 \\ 80 \\ 60 \\ \end{pmatrix} = \begin{pmatrix} 1000 \\ 1820 \\ 1180 \\ 2180 \end{pmatrix} ,</math> that is, <math>1000</math> units of <math>b_1</math>, <math>1820</math> units of <math>b_2</math>, <math>1180</math> units of <math>b_3</math>, <math>2180</math> units of <math>b_4</math> are needed. Similarly, the product matrix <math>\mathbf{AB}</math> can be used to compute the needed amounts of basic goods for other final-good amount data.<ref>{{cite book | isbn=3-446-18668-9 | author=Peter Stingl | title=Mathematik fΓΌr Fachhochschulen – Technik und Informatik | location=[[Munich]] | publisher=[[Carl Hanser Verlag]] | edition=5th | year=1996 | language=German }} Here: Exm.5.4.10, p.205-206</ref> ===System of linear equations=== The general form of a [[system of linear equations]] is :<math>\begin{matrix}a_{11}x_1+\cdots + a_{1n}x_n=b_1, \\ a_{21}x_1+\cdots + a_{2n}x_n =b_2, \\ \vdots \\ a_{m1}x_1+\cdots + a_{mn}x_n =b_m. \end{matrix}</math> Using same notation as above, such a system is equivalent with the single matrix [[equation]] :<math>\mathbf{Ax}=\mathbf b.</math> ===Dot product, bilinear form and sesquilinear form=== The [[dot product]] of two column vectors is the unique entry of the matrix product :<math>\mathbf x^\mathsf T \mathbf y,</math> where <math>\mathbf x^\mathsf T</math> is the [[row vector]] obtained by [[transpose|transposing]] <math>\mathbf x</math>. (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 :<math>\mathbf x^\mathsf T \mathbf {Ay},</math> and any [[sesquilinear form]] may be expressed as :<math>\mathbf x^\dagger \mathbf {Ay},</math> where <math>\mathbf x^\dagger</math> denotes the [[conjugate transpose]] of <math>\mathbf x</math> (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]],<ref name=":2">{{Cite web|last=Weisstein|first=Eric W.|title=Matrix Multiplication|url=https://mathworld.wolfram.com/MatrixMultiplication.html|access-date=2020-09-06|website=mathworld.wolfram.com|language=en}}</ref> even when the product remains defined after changing the order of the factors.<ref>{{cite book|title=Linear Algebra|edition=4th| first1 = S. | last1 = Lipcshutz | first2 = M. | last2 = Lipson|series=Schaum's Outlines|publisher=McGraw Hill (USA)|chapter=2|date=2009|isbn=978-0-07-154352-1}}</ref><ref>{{cite book|title=Matrix Analysis| last = Horn | first = Johnson |edition=2nd |chapter=Chapter 0 |publisher=Cambridge University Press |date=2013|isbn=978-0-521-54823-6}}</ref> ===Non-commutativity=== An operation is [[commutative property|commutative]] if, given two elements {{math|'''A'''}} and {{math|'''B'''}} such that the product <math>\mathbf{A}\mathbf{B}</math> is defined, then <math>\mathbf{B}\mathbf{A}</math> is also defined, and <math>\mathbf{A}\mathbf{B}=\mathbf{B}\mathbf{A}.</math> If {{math|'''A'''}} and {{math|'''B'''}} are matrices of respective sizes {{tmath|m\times n}} and {{tmath|p\times q}}, then <math>\mathbf{A}\mathbf{B}</math> is defined if {{tmath|1=n=p}}, and <math>\mathbf{B}\mathbf{A}</math> is defined if {{tmath|1=m=q}}. Therefore, if one of the products is defined, the other one need not be defined. If {{tmath|1=m=q\neq n=p}}, the two products are defined, but have different sizes; thus they cannot be equal. Only if {{tmath|1=m=q= n=p}}, that is, if {{math|'''A'''}} and {{math|'''B'''}} are [[square matrices]] of the same size, are both products defined and of the same size. Even in this case, one has in general :<math>\mathbf{A}\mathbf{B} \neq \mathbf{B}\mathbf{A}.</math> For example :<math>\begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}=\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix},</math> but :<math>\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}\begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix} = \begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix}.</math> This example may be expanded for showing that, if {{math|'''A'''}} is a {{tmath|n\times n}} matrix with entries in a [[field (mathematics)|field]] {{mvar|F}}, then <math>\mathbf{A}\mathbf{B} = \mathbf{B}\mathbf{A}</math> for every {{tmath|n\times n}} matrix {{math|'''B'''}} with entries in {{mvar|F}}, [[if and only if]] <math>\mathbf{A}=c\,\mathbf{I}</math> where {{tmath|c\in F}}, and {{math|'''I'''}} is the {{tmath|n\times n}} [[identity matrix]]. If, instead of a field, the entries are supposed to belong to a [[ring (mathematics)|ring]], then one must add the condition that {{mvar|c}} belongs to the [[center (ring theory)|center]] of the ring. One special case where commutativity does occur is when {{math|'''D'''}} and {{math|'''E'''}} are two (square) [[diagonal matrices]] (of the same size); then {{math|1='''DE''' = '''ED'''}}.<ref name=":2" /> 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 property|distributive]] with respect to [[matrix addition]]. That is, if {{math|'''A''', '''B''', '''C''', '''D'''}} are matrices of respective sizes {{math|''m'' Γ ''n''}}, {{math|''n'' Γ ''p''}}, {{math|''n'' Γ ''p''}}, and {{math|''p'' Γ ''q''}}, one has (left distributivity) :<math>\mathbf{A}(\mathbf{B} + \mathbf{C}) = \mathbf{AB} + \mathbf{AC},</math> and (right distributivity) :<math>(\mathbf{B} + \mathbf{C} )\mathbf{D} = \mathbf{BD} + \mathbf{CD}.</math><ref name=":2" /> This results from the distributivity for coefficients by :<math>\sum_k a_{ik}(b_{kj} + c_{kj}) = \sum_k a_{ik}b_{kj} + \sum_k a_{ik}c_{kj} </math> :<math>\sum_k (b_{ik} + c_{ik}) d_{kj} = \sum_k b_{ik}d_{kj} + \sum_k c_{ik}d_{kj}. </math> ===Product with a scalar=== If {{math|'''A'''}} is a matrix and {{mvar|c}} a scalar, then the matrices <math>c\mathbf{A}</math> and <math>\mathbf{A}c</math> are obtained by left or right multiplying all entries of {{math|'''A'''}} by {{mvar|c}}. If the scalars have the [[commutative property]], then <math>c\mathbf{A} = \mathbf{A}c.</math> If the product <math>\mathbf{AB}</math> is defined (that is, the number of columns of {{math|'''A'''}} equals the number of rows of {{math|'''B'''}}), then :<math> c(\mathbf{AB}) = (c \mathbf{A})\mathbf{B}</math> and <math> (\mathbf{A} \mathbf{B})c=\mathbf{A}(\mathbf{B}c).</math> If the scalars have the commutative property, then all four matrices are equal. More generally, all four are equal if {{math|''c''}} belongs to the [[Center (ring theory)|center]] of a [[ring (mathematics)|ring]] containing the entries of the matrices, because in this case, {{math|''c'''''X''' {{=}} '''X'''''c''}} for all matrices {{math|'''X'''}}. These properties result from the [[bilinearity]] of the product of scalars: :<math>c \left(\sum_k a_{ik}b_{kj}\right) = \sum_k (c a_{ik} ) b_{kj} </math> :<math>\left(\sum_k a_{ik}b_{kj}\right) c = \sum_k a_{ik} ( b_{kj}c). </math> ===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 :<math> (\mathbf{AB})^\mathsf{T} = \mathbf{B}^\mathsf{T}\mathbf{A}^\mathsf{T} </math> where <sup>T</sup> 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 {{math|'''A'''}} and {{math|'''B'''}} is reversed, when one expands the definition of the matrix product. ===Complex conjugate=== If {{math|'''A'''}} and {{math|'''B'''}} have [[complex number|complex]] entries, then :<math> (\mathbf{AB})^* = \mathbf{A}^*\mathbf{B}^* </math> where {{math|<sup>*</sup>}} 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 {{math|'''A'''}} and {{math|'''B'''}} have complex entries, one has :<math> (\mathbf{AB})^\dagger = \mathbf{B}^\dagger\mathbf{A}^\dagger ,</math> where {{math|<sup>β </sup>}} denotes the [[conjugate transpose]] (conjugate of the transpose, or equivalently transpose of the conjugate). ===Associativity=== Given three matrices {{math|'''A''', '''B'''}} and {{math|'''C'''}}, the products {{math|('''AB''')'''C'''}} and {{math|'''A'''('''BC''')}} are defined if and only if the number of columns of {{math|'''A'''}} equals the number of rows of {{math|'''B'''}}, and the number of columns of {{math|'''B'''}} equals the number of rows of {{math|'''C'''}} (in particular, if one of the products is defined, then the other is also defined). In this case, one has the [[associative property]] :<math>(\mathbf{AB})\mathbf{C}=\mathbf{A}(\mathbf{BC}).</math> As for any associative operation, this allows omitting parentheses, and writing the above products as {{tmath|\mathbf{ABC}.}} This extends naturally to the product of any number of matrices provided that the dimensions match. That is, if {{math|'''A'''<sub>1</sub>, '''A'''<sub>2</sub>, ..., '''A'''<sub>''n''</sub>}} are matrices such that the number of columns of {{math|'''A'''<sub>''i''</sub>}} equals the number of rows of {{math|'''A'''<sub>''i'' + 1</sub>}} for {{math|1=''i'' = 1, ..., ''n'' β 1}}, then the product :<math> \prod_{i=1}^n \mathbf{A}_i = \mathbf{A}_1\mathbf{A}_2\cdots\mathbf{A}_n </math> is defined and does not depend on the [[order of operations|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 map]]s. 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 {{math|'''A''', '''B'''}} and {{math|'''C'''}} are matrices of respective sizes {{math|10Γ30, 30Γ5, 5Γ60}}, computing {{math|('''AB''')'''C'''}} needs {{math|1=10Γ30Γ5 + 10Γ5Γ60 = 4,500}} multiplications, while computing {{math|'''A'''('''BC''')}} needs {{math|1=30Γ5Γ60 + 10Γ30Γ60 = 27,000}} multiplications. Algorithms have been designed for choosing the best order of products; see [[Matrix chain multiplication]]. When the number {{mvar|n}} of matrices increases, it has been shown that the choice of the best order has a complexity of <math>O(n \log n).</math><ref>{{cite journal | last1 = Hu | first1 = T. C. | author1-link = T. C. Hu | last2 = Shing | first2 = M.-T. | title = Computation of Matrix Chain Products, Part I | journal = SIAM Journal on Computing | volume = 11 | issue = 2 | pages = 362β373 | year = 1982 | url = http://www.cs.ust.hk/mjg_lib/bibs/DPSu/DPSu.Files/0211028.pdf | issn = 0097-5397 | doi=10.1137/0211028 | citeseerx = 10.1.1.695.2923 }} </ref><ref>{{cite journal | last1 = Hu | first1 = T. C. | author1-link = T. C. Hu | last2 = Shing | first2 = M.-T. | title = Computation of Matrix Chain Products, Part II | journal = SIAM Journal on Computing | volume = 13 | issue = 2 | pages = 228β251 | year = 1984 | url = http://www.cs.ust.hk/mjg_lib/bibs/DPSu/DPSu.Files/0213017.pdf | issn = 0097-5397 | doi=10.1137/0213017 | citeseerx = 10.1.1.695.4875 }} </ref> ====Application to similarity==== Any [[invertible matrix]] <math>\mathbf{P}</math> defines a [[similar matrix|similarity transformation]] (on square matrices of the same size as <math>\mathbf{P}</math>) :<math>S_\mathbf{P}(\mathbf{A}) = \mathbf{P}^{-1} \mathbf{A} \mathbf{P}.</math> Similarity transformations map product to products, that is :<math>S_\mathbf{P}(\mathbf{AB}) = S_\mathbf{P}(\mathbf{A})S_\mathbf{P}(\mathbf{B}).</math> In fact, one has :<math>\mathbf{P}^{-1} (\mathbf{AB}) \mathbf{P} = \mathbf{P}^{-1} \mathbf{A}(\mathbf{P}\mathbf{P}^{-1})\mathbf{B} \mathbf{P} =(\mathbf{P}^{-1} \mathbf{A}\mathbf{P})(\mathbf{P}^{-1}\mathbf{B} \mathbf{P}).</math> ==Square matrices== Let us denote <math>\mathcal M_n(R)</math> the set of {{math|''n''Γ''n''}} [[square matrices]] with entries in a [[ring (mathematics)|ring]] {{mvar|R}}, which, in practice, is often a [[field (mathematics)|field]]. In <math>\mathcal M_n(R)</math>, the product is defined for every pair of matrices. This makes <math>\mathcal M_n(R)</math> a [[ring (mathematics)|ring]], which has the [[identity matrix]] {{math|'''I'''}} 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 {{mvar|R}}-algebra]]. If {{math|''n'' > 1}}, 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 {{math|'''A'''}} is denoted {{math|'''A'''<sup>β1</sup>}}, and, thus verifies :<math> \mathbf{A}\mathbf{A}^{-1} = \mathbf{A}^{-1}\mathbf{A} = \mathbf{I}. </math> 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 :<math>(\mathbf{A}\mathbf{B})^{-1} = \mathbf{B}^{-1}\mathbf{A}^{-1}.</math> When {{mvar|R}} is [[commutative ring|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 :<math> \det(\mathbf{AB}) = \det(\mathbf{BA}) =\det(\mathbf{A})\det(\mathbf{B}). </math> The other matrix [[invariant (mathematics)|invariants]] do not behave as well with products. Nevertheless, if {{mvar|R}} is commutative, {{math|'''AB'''}} and {{math|'''BA'''}} have the same [[Trace (linear algebra)|trace]], the same [[characteristic polynomial]], and the same [[eigenvalues]] with the same multiplicities. However, the [[eigenvector]]s are generally different if {{math|'''AB''' β '''BA'''}}. ===Powers of a matrix=== One may raise a square matrix to any [[exponentiation|nonnegative integer power]] multiplying it by itself repeatedly in the same way as for ordinary numbers. That is, :<math>\mathbf{A}^0 = \mathbf{I},</math> :<math>\mathbf{A}^1 = \mathbf{A},</math> :<math>\mathbf{A}^k = \underbrace{\mathbf{A}\mathbf{A}\cdots\mathbf{A}}_{k\text{ times}}.</math> Computing the {{mvar|k}}th power of a matrix needs {{math|''k'' β 1}} 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 {{math|2 log<sub>2</sub> ''k''}} 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 {{mvar|k}}th power of a diagonal matrix is obtained by raising the entries to the power {{mvar|k}}: :<math> \begin{bmatrix} a_{11} & 0 & \cdots & 0 \\ 0 & a_{22} & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & a_{nn} \end{bmatrix}^k = \begin{bmatrix} a_{11}^k & 0 & \cdots & 0 \\ 0 & a_{22}^k & \cdots & 0 \\ \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & \cdots & a_{nn}^k \end{bmatrix}. </math> ==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 property|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.<ref>{{cite book|title=Randomized Algorithms|first1=Rajeev|last1=Motwani|author1-link=Rajeev Motwani|first2=Prabhakar|last2=Raghavan|author2-link=Prabhakar Raghavan|publisher=Cambridge University Press|year=1995|isbn=9780521474658|page=280|url=https://books.google.com/books?id=QKVY4mDivBEC&pg=PA280}}</ref> Even in the case of matrices over fields, the product is not commutative in general, although it is [[Associative property|associative]] and is [[Distributive property|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 element]]s of the matrix product. It follows that the {{math|''n'' Γ ''n''}} matrices over a [[Ring (mathematics)|ring]] form a ring, which is noncommutative except if {{math|1=''n'' = 1}} 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]] {{mvar|R}}, a matrix has an inverse if and only if its [[determinant]] has a multiplicative inverse in {{mvar|R}}. The determinant of a product of square matrices is the product of the determinants of the factors. The {{math|''n'' Γ ''n''}} matrices that have an inverse form a [[group (mathematics)|group]] under matrix multiplication, the [[subgroup]]s of which are called [[matrix group]]s. Many classical groups (including all [[finite group]]s) are [[group isomorphism|isomorphic]] to matrix groups; this is the starting point of the theory of [[group representation]]s. Matrices are the [[morphisms]] of a [[category (mathematics)|category]], the [[category of matrices]]. The objects are the [[natural number]]s 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== {{Main|Computational complexity of matrix multiplication}} {{For|implementation techniques (in particular parallel and distributed algorithms)|Matrix multiplication algorithm}} [[File:MatrixMultComplexity svg.svg|thumb|400px|right|Improvement of estimates of exponent {{math|Ο}} over time for the computational complexity of matrix multiplication <math>O(n^\omega)</math>]] The matrix multiplication [[algorithm]] that results from the definition requires, in the [[worst-case complexity|worst case]], {{tmath|n^3}} multiplications and {{tmath|(n-1)n^2}} additions of scalars to compute the product of two square {{math|''n''Γ''n''}} matrices. Its [[computational complexity]] is therefore {{tmath|O(n^3)}}, 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 <math>O( n^{\log_{2}7}) \approx O(n^{2.8074}).</math><ref> {{cite journal | doi=10.1007/BF02165411 | url=http://www.digizeitschriften.de/dms/img/?PID=GDZPPN001168215 | author=Volker Strassen | title=Gaussian elimination is not optimal | journal=Numerische Mathematik | volume=13 | pages=354–356 | date=Aug 1969 | issue = 4 | s2cid = 121656251 }}</ref> Strassen's algorithm can be parallelized to further improve the performance.<ref>{{cite journal | url=https://core.ac.uk/download/pdf/82778592.pdf | author=C.-C. Chou and Y.-F. Deng and G. Li and Y. Wang | title=Parallelizing Strassen's Method for Matrix Multiplication on Distributed-Memory MIMD Architectures | journal=Computers Math. Applic. | volume=30 | number=2 | pages=49–69 | year=1995 | doi=10.1016/0898-1221(95)00077-C }}</ref> {{As of|2024|01}}, the best peer-reviewed matrix multiplication algorithm is by [[Virginia Vassilevska Williams]], Yinzhan Xu, Zixuan Xu, and Renfei Zhou and has complexity {{math|''O''(''n''<sup>2.371552</sup>)}}.<ref name="wxxz23">{{cite conference |last1=Vassilevska Williams |first1=Virginia |last2=Xu |first2=Yinzhan |last3=Xu |first3=Zixuan |last4=Zhou |first4=Renfei |title=New Bounds for Matrix Multiplication: from Alpha to Omega |conference=Proceedings of the 2024 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA) |pages=3792β3835 |arxiv=2307.07970 |doi=10.1137/1.9781611977912.134}}</ref><ref>{{cite web |last=Nadis |first=Steve |date=March 7, 2024 |title=New Breakthrough Brings Matrix Multiplication Closer to Ideal |url=https://www.quantamagazine.org/new-breakthrough-brings-matrix-multiplication-closer-to-ideal-20240307 |access-date=2024-03-09}}</ref> It is not known whether matrix multiplication can be performed in {{math|''n''<sup>2 + o(1)</sup>}} time.<ref>that is, in time {{math|''n''<sup>2+f(n)</sup>}}, for some function {{mvar|''f''}} with {{math|''f''(''n'')[[limit of a function|β]]0}} as {{math|''n''ββ}}</ref> This would be optimal, since one must read the {{tmath|n^2}} 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#Block matrix operations|Block matrix operations]] * [[Cracovian product]], defined as {{math|1='''A''' β§ '''B''' = '''B'''<sup>T</sup>'''A'''}} * [[Frobenius inner product]], the [[dot product]] of matrices considered as vectors, or, equivalently the sum of the entries of the Hadamard product * [[Hadamard product (matrices)|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]], also called [[dyadic product]] or [[tensor product]] of two column matrices, which is <math>\mathbf{a}\mathbf{b}^\mathsf{T}</math> * [[Scalar multiplication]] ==See also== * [[Matrix calculus]], for the interaction of matrix multiplication with operations from calculus ==Notes== {{Reflist|30em}} ==References== {{Commons category|Matrix multiplication|matrix multiplication}} {{wikibooks |1= Linear Algebra |2= Matrix Multiplication |3= Matrix multiplication }} {{wikibooks|Applicable Mathematics|Matrices#Multiplying Matrices|Multiplying Matrices}} {{refbegin}} * Henry Cohn, [[Robert Kleinberg]], [[BalΓ‘zs Szegedy]], and Chris Umans. Group-theoretic Algorithms for Matrix Multiplication. {{arxiv|math.GR/0511460}}. ''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. {{arxiv|math.GR/0307321}}. ''Proceedings of the 44th Annual IEEE Symposium on Foundations of Computer Science'', 11β14 October 2003, Cambridge, MA, IEEE Computer Society, pp. 438β449. * {{cite journal | last1 = Coppersmith | first1 = D. | last2 = Winograd | first2 = S. | year = 1990 | title = Matrix multiplication via arithmetic progressions | journal = J. Symbolic Comput. | volume = 9 | issue = 3| pages = 251β280 | doi=10.1016/s0747-7171(08)80013-2| doi-access = free }} * {{Citation | last1=Horn | first1=Roger A. | last2=Johnson | first2=Charles R. | title=Topics in Matrix Analysis | publisher=[[Cambridge University Press]] | isbn=978-0-521-46713-1 | year=1991}} * [[Donald Knuth|Knuth, D.E.]], ''[[The Art of Computer Programming]] Volume 2: Seminumerical Algorithms''. Addison-Wesley Professional; 3 edition (November 14, 1997). {{isbn|978-0-201-89684-8}}. pp. 501. * {{Citation | last1=Press | first1=William H. | last2=Flannery | first2=Brian P. | last3=Teukolsky | first3=Saul A. | author3-link=Saul Teukolsky | last4=Vetterling | first4=William T. | title=Numerical Recipes: The Art of Scientific Computing | publisher=[[Cambridge University Press]] | edition=3rd | isbn=978-0-521-88068-8 | year=2007| title-link=Numerical Recipes }}. * [[Ran Raz]]. On the complexity of matrix product. In Proceedings of the thirty-fourth annual ACM symposium on Theory of computing. ACM Press, 2002. {{doi|10.1145/509907.509932}}. * Robinson, Sara, ''Toward an Optimal Algorithm for Matrix Multiplication,'' SIAM News 38(9), November 2005. [https://web.archive.org/web/20100331095603/http://www.siam.org/pdf/news/174.pdf PDF] * Strassen, Volker, ''Gaussian Elimination is not Optimal'', Numer. Math. 13, p. 354β356, 1969. * {{Citation | doi=10.1016/0024-3795(73)90023-2 | last=Styan | first=George P. H. | title=Hadamard Products and Multivariate Statistical Analysis | journal=Linear Algebra and Its Applications | year=1973 | volume=6 | pages=217β240| url=http://dml.cz/bitstream/handle/10338.dmlcz/102190/CzechMathJ_37-1987-4_14.pdf | doi-access=free }} * {{Cite book|last=Williams|first=Virginia Vassilevska|date=2012-05-19|chapter=Multiplying matrices faster than coppersmith-winograd|chapter-url=http://dl.acm.org/citation.cfm?id=2213977.2214056|publisher=ACM|pages=887β898|doi=10.1145/2213977.2214056|isbn=9781450312455|title=Proceedings of the 44th symposium on Theory of Computing - STOC '12|citeseerx=10.1.1.297.2680|s2cid=14350287}} {{refend}} {{Linear algebra}} [[Category:Matrix theory]] [[Category:Bilinear maps]] [[Category:Multiplication]] [[Category:Numerical linear algebra]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Arxiv
(
edit
)
Template:As of
(
edit
)
Template:Citation
(
edit
)
Template:Cite book
(
edit
)
Template:Cite conference
(
edit
)
Template:Cite journal
(
edit
)
Template:Cite web
(
edit
)
Template:Commons category
(
edit
)
Template:Doi
(
edit
)
Template:For
(
edit
)
Template:Isbn
(
edit
)
Template:Linear algebra
(
edit
)
Template:MacTutor
(
edit
)
Template:Main
(
edit
)
Template:Math
(
edit
)
Template:Mvar
(
edit
)
Template:Navbox
(
edit
)
Template:Refbegin
(
edit
)
Template:Refend
(
edit
)
Template:Reflist
(
edit
)
Template:See also
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Slink
(
edit
)
Template:Tmath
(
edit
)
Template:Wikibooks
(
edit
)