All Topics  
Matrix multiplication

 

   Email Print
   Bookmark   Link






 

Matrix multiplication



 
 
In mathematics
Mathematics

Mathematics is the study of quantity, structure, space, change, and related topics of pattern and form. Mathematicians seek out patterns whether found in numbers, space, natural science, computers, imaginary abstractions, or elsewhere....
, matrix multiplication is the operation of multiplying a matrix
Matrix (mathematics)

In mathematics, a matrix is a rectangular array of numbers, as shown at the right. In addition to a number of elementary, entrywise operations such as matrix addition a key notion is matrix multiplication....
 with either a scalar
Scalar (mathematics)

In linear algebra, real numbers are called scalars and relate to vectors in a vector space through the operation of scalar multiplication, in which a vector can be multiplied by a number to produce another vector....
 or another matrix. This article gives an overview of the various ways to perform matrix multiplication.

is the most often used and most important way to multiply matrices. It is defined between two matrices only if the number of columns of the first matrix is the same as the number of rows of the second matrix.

Formally, for , then where the elements of are given by

for each pair i and j with 1 = i = m and 1 = j = p.






Discussion
Ask a question about 'Matrix multiplication'
Start a new discussion about 'Matrix multiplication'
Answer questions from other users
Full Discussion Forum



Recent Posts









Encyclopedia


In mathematics
Mathematics

Mathematics is the study of quantity, structure, space, change, and related topics of pattern and form. Mathematicians seek out patterns whether found in numbers, space, natural science, computers, imaginary abstractions, or elsewhere....
, matrix multiplication is the operation of multiplying a matrix
Matrix (mathematics)

In mathematics, a matrix is a rectangular array of numbers, as shown at the right. In addition to a number of elementary, entrywise operations such as matrix addition a key notion is matrix multiplication....
 with either a scalar
Scalar (mathematics)

In linear algebra, real numbers are called scalars and relate to vectors in a vector space through the operation of scalar multiplication, in which a vector can be multiplied by a number to produce another vector....
 or another matrix. This article gives an overview of the various ways to perform matrix multiplication.

Ordinary matrix product

This is the most often used and most important way to multiply matrices. It is defined between two matrices only if the number of columns of the first matrix is the same as the number of rows of the second matrix.

Formally, for , then where the elements of are given by

for each pair i and j with 1 = i = m and 1 = j = p. The algebraic system of "matrix unit
Matrix unit

In mathematics, a matrix unit is an idealisation of the concept of a Matrix , with a focus on the algebraic properties of matrix multiplication....
s" summarises the abstract properties of this kind of multiplication.

Calculating directly from the definition


The picture to the left shows how to calculate the (1,2) element and the (3,3) element of AB if A is a 3×2 matrix, and B is a 2×3 matrix. Elements from each matrix are paired off in the direction of the arrows; each pair is multiplied and the products are added. The location of the resulting number in AB corresponds to the row and column that were considered.


For example BA:

The coefficients-vectors method

This matrix multiplication can also be considered from a slightly different viewpoint: it adds vectors together after being multiplied by different coefficients. If A and B are matrices given by:

and

then

The example revisited:

The rows in the matrix on the left can be thought of as the list of coefficients and the matrix on the right as the list of vectors. In the example, the first row is [1 0 2], and thus we take 1 times the first vector, 0 times the second vector, and 2 times the third vector.

The equation can be simplified further by using outer product
Outer product

In linear algebra, the outer product typically refers to the Tensor product of two vector . The result of applying the outer product to a pair of vectors is a matrix ....
s:

The terms of this sum are matrices of the same shape, each describing the effect of one column of A and one row of B on the result. The columns of A can be seen as a coordinate system of the transform, i.e. given a vector x we have where are coordinates along the "axes". The terms are like , except that contains the ith coordinate for each column vector of B, each of which is transformed independently in parallel.

The example revisited:

The vectors and have been transformed to and in parallel. One could also transform them one by one with the same steps:

Vector-lists method


The ordinary matrix product can be thought of as a dot product
Dot product

In mathematics, the dot product, also known as the scalar product, is an operation which takes two vector over the real numbers R and returns a real-valued scalar quantity....
 of a column-list
Column vector

In linear algebra, a column vector or column matrix is an m × 1 matrix , i.e. a matrix consisting of a single column of elements....
 of vectors and a row-list
Row vector

In linear algebra, a row vector or row matrix is a 1 × n matrix , that is, a matrix consisting of a single row:The transpose of a row vector is a column vector:...
 of vectors. If A and B are matrices given by:

and

where
A1 is the row vector of all elements of the form a1,x      A2 is the row vector of all elements of the form a2,x     etc,
and B1 is the column vector of all elements of the form bx,1      B2 is the column vector of all elements of the form bx,2     etc,


then

Properties

  • Matrix multiplication is not generally commutative


  • If A and B are both n x n matrices, then the determinants of their product is equal, regardless of order.


  • If both matrices are diagonal
    Diagonal matrix

    In linear algebra, a diagonal matrix is a square matrix in which the entries outside the main diagonal are all zero. The diagonal entries themselves may or may not be zero....
     square matrices of the same dimension, their product is commutative.


  • If A is a matrix representative of a linear transformation L and B is a matrix representative of a linear transformation P then AB is a matrix representative of a linear transform P followed by the linear transformation L.
  • Matrix multiplication is associative:


  • Matrix multiplication is distributive:
.

  • If the matrix is defined over a field (for example, over the Real or Complex fields), then it is compatible with scalar multiplication in that field.
where c is a scalar.


Algorithms for efficient matrix multiplication


The complexity
Computational complexity theory

Computational complexity theory, as a branch of the theory of computation in computer science, investigates the problems related to the Computational resource required for the execution of algorithms , and the inherent difficulty in providing efficient algorithms for specific computational problems....
 of matrix multiplication, if carried out naively, is , but more efficient algorithms do exist. Strassen's algorithm
Strassen algorithm

In the mathematics discipline of linear algebra, the Strassen algorithm, named after Volker Strassen, is an algorithm used for matrix multiplication....
, devised by Volker Strassen
Volker Strassen

File:Strassen Knuth Prize lecture.jpgVolker Strassen is a Germany mathematician, a professor emeritus in the department of mathematics and statistics at the University of Konstanz....
 in 1969 and often referred to as "fast matrix multiplication", is based on a clever way of multiplying two 2 × 2 matrices which requires only 7 multiplications (instead of the usual 8), at the expense of several additional addition and subtraction operations. Applying this trick recursively gives an algorithm with a multiplicative cost of . Strassen's algorithm is awkward to implement, compared to the naive algorithm, and it lacks numerical stability
Numerical stability

In the mathematics subfield of numerical analysis, numerical stability is a desirable property of numerical algorithms. The precise definition of stability depends on the context, but it is related to the accuracy of the algorithm....
. Nevertheless, it is beginning to appear in libraries such as BLAS, where it is computationally interesting for matrices with dimensions n > 100 (Press 2007, p. 108), and is very useful for large matrices over exact domains such as finite fields, where numerical stability is not an issue.

The algorithm with the lowest known exponent
Coppersmith–Winograd algorithm

In the mathematics discipline of linear algebra, the Coppersmith?Winograd algorithm, named after Don Coppersmith and Shmuel Winograd, is the asymptotically fastest known algorithm for square matrix multiplication as of 2008....
, which was presented by Don Coppersmith
Don Coppersmith

Don Coppersmith is a cryptographer and mathematician. He was involved in the design of the Data Encryption Standard block cipher at IBM, particularly the design of the S-box, strengthening them against differential cryptanalysis....
 and Shmuel Winograd
Shmuel Winograd

Shmuel Winograd is a Computer science, noted for his work on fast algorithms for arithmetic, and in particular for the algorithm known as the Coppersmith-Winograd algorithm and for his FFT algorithm....
 in 1990, has an asymptotic complexity of O(n2.376). It is similar to Strassen's algorithm: a clever way is devised for multiplying two k × k matrices with fewer than k3 multiplications, and this technique is applied recursively. It improves on the constant factor in Strassen's algorithm, reducing it to 4.537. However, the constant term implied in the O(n2.376) result is so large that the Coppersmith–Winograd algorithm is only worthwhile for matrices that are too big to handle on present-day computers (Knuth, 1998).

Since any algorithm for multiplying two n × n matrices has to process all 2 × n² entries, there is an asymptotic lower bound of operations. Raz (2002) proves a lower bound of for bounded coefficient arithmetic circuits over the real or complex numbers.

Cohn et al. (2003, 2005) put methods, such as the Strassen and Coppersmith–Winograd algorithms, in an entirely different group-theoretic
Group theory

In mathematics and abstract algebra, group theory studies the algebraic structures known as group .The concept of a group is central to abstract algebra: other well-known algebraic structures, such as ring , field , and vector spaces can all be seen as groups endowed with additional operations and axioms....
 context. They show that if families of wreath product
Wreath product

In mathematics, the wreath product of group theory is a specialized product of two groups, based on a semidirect product. Wreath products are an important tool in the classification of permutation groups and also provide a way of constructing interesting examples of groups....
s of Abelian with symmetric groups satisfying certain conditions exists, matrix multiplication algorithms with essential quadratic complexity exist. Most researchers believe that this is indeed the case (Robinson, 2005).

Because of the nature of Matrix operations and the layout of Matrices in memory, it is typically possible to gain substantial performance gains through use of parallelisation and vectorisation. It should therefore be noted that some lower time-complexity algorithms on paper may have indirect time complexity costs on real machines.

Relationship to linear transformations

Matrices offer a concise way of representing linear transformation
Linear transformation

In mathematics, a linear map is a function between two vector spaces that preserves the operations of vector addition and scalar multiplication....
s between vector space
Vector space

File:Vector addition ans scaling.pngA vector space is a mathematical structure formed by a collection of vectors: objects that may be Vector addition together and Scalar multiplication by numbers, called scalar s in this context....
s, and (ordinary) matrix multiplication corresponds to the composition
Function composition

In mathematics, a composite function represents the application of one function to the results of another. For instance, the functions and can be composed by first computing a f and then applying a function g to the output of f....
 of linear transformations. This will be illustrated here by means of an example using three vector spaces of specific dimensions, but the correspondence applies equally to any other choice of dimensions.

Let X, Y, and Z be three vector spaces, with dimensions 4, 2, and 3, respectively, all over the same field
Field (mathematics)

In abstract algebra, a field is an algebraic structure with notions of addition, subtraction, multiplication and division , satisfying certain axioms....
, for example the real number
Real number

In mathematics, the real numbers may be described informally in several different ways. The real numbers include both rational numbers, such as 42 and −23/129, and irrational numbers, such as pi and the square root of two; or, a real number can be given by an infinite decimal representation, such as 2.4871773339...., where the digits co...
s. The coordinates of a point in X will be denoted as xi, for i = 1 to 4, and analogously for the other two spaces.

Two linear transformations are given: one from Y to X, which can be expressed by the system of linear equations
System of linear equations

In mathematics, a system of linear equations is a collection of linear equations involving the same set of variables. For example,is a system of three equations in the three variables ....


and one from Z to Y, expressed by the system

These two transformations can be composed to obtain a transformation from Z to X. By substituting, in the first system, the right-hand sides of the equations of the second system for their corresponding left-hand sides, the xi can be expressed in terms of the zk:

These three systems can be written equivalently in matrix–vector notation – thereby reducing each system to a single equation – as follows:


Representing these three equations symbolically and more concisely as

inspection of the entries of matrix C reveals that .

This can be used to formulate a more abstract definition of matrix multiplication, given the special case of matrix–vector multiplication: the product AB of matrices A and B is the matrix C such that for all vectors z of the appropriate shape .

Scalar multiplication


The scalar multiplication of a matrix A = (aij) and a scalar r gives a product r A of the same size as A. The entries of r A are given by
For example, if then

If we are concerned with matrices over a more general ring
Ring (mathematics)

In mathematics, a ring is a type of algebraic structure. There is some variation among mathematicians as to exactly what properties a ring is required to have, as described in detail below....
, then the above multiplication is the left multiplication of the matrix A with scalar p while the right multiplication is defined to be


When the underlying ring is commutative, for example, the real or complex number field, the two multiplications are the same. However, if the ring is not commutative, such as the quaternion
Quaternion

Quaternions, in mathematics, are a non-commutative number system that extends the complex numbers. The quaternions were first described by Irish mathematician Sir William Rowan Hamilton in 1843 and applied to mechanics in three-dimensional space....
s, they may be different. For example

Hadamard product


For two matrices of the same dimensions, we have the Hadamard product (named after French mathematician Jaques Hadamard), also known as the entrywise product and the Schur product.

Formally, for , then where the elements of are given by

Note that the Hadamard product is a submatrix
Submatrix

In mathematics, a submatrix is a matrix formed by selecting certain rows and columns from a bigger matrix. That is, as an array, it is cut down to those entries constrained by row and column....
 of the Kronecker product
Kronecker product

In mathematics, the Kronecker product, denoted by , is an operation on two matrix of arbitrary size resulting in a block matrix. It is a special case of a tensor product....
.

The Hadamard product is commutative.

The Hadamard product is studied by matrix theorists, and it appears in lossy compression algorithms such as JPEG
JPEG

In computing, JPEG is a commonly used method of for photographic images. The degree of compression can be adjusted, allowing a selectable tradeoff between storage size and image quality....
, but it is virtually untouched by linear algebraists. It is discussed in (Horn & Johnson, 1994, Ch. 5).

Kronecker product


For any two arbitrary matrices A and B, we have the direct product or Kronecker
Leopold Kronecker

Leopold Kronecker was a Germany mathematician and logician who argued that arithmetic and Mathematical analysis must be founded on "whole numbers", saying, "God made the integers; all else is the work of man" ....
 product A B defined as

If A is an m-by-n matrix and B is a p-by-q matrix, then their Kronecker product A B is an mp-by-nq matrix.

The Kronecker product is not commutative.

For example .

If A and B represent linear transformations V1 ? W1 and V2 ? W2, respectively, then A B represents the tensor product
Tensor product

In mathematics, the tensor product, denoted by , may be applied in different contexts to vector spaces, matrix , tensors, vector spaces, algebra over a field, topological vector spaces, and module s....
 of the two maps, V1 V2 ? W1 W2.

Common properties


If A, B and C are matrices with appropriate dimensions defined over a commutative Field
Field (mathematics)

In abstract algebra, a field is an algebraic structure with notions of addition, subtraction, multiplication and division , satisfying certain axioms....
 (e.g. where c is a scalar in that field, then for all three types of multiplication:

  • Matrix multiplication is associative:


  • Matrix multiplication is distributive:


.

  • Matrix multiplication compatible with scalar multiplication:

Frobenius inner product

The Frobenius inner product, sometimes denoted A:B is the component-wise inner product of two matrices as though they are vectors. In other words, it is the sum of the entries of the Hadamard product, that is, This inner product induces the Frobenius norm.

Powers of matrices

Square matrices can be multiplied by themselves repeatedly in the same way that ordinary numbers can. This repeated multiplication can be described as a power of the matrix. Using the ordinary notion of matrix multiplication, the following identities hold for an n-by-n matrix A, a positive integer k, and a scalar c:

The naive computation of matrix powers is to multiply k times the matrix A to the result, starting with the identity matrix just like the scalar case. This can be improved using the binary representation of k, a method commonly used to scalars. An even better method is to use the eigenvalue decomposition of A.

See also


External links

  • Multiply or add matrices of a type and with coefficients you choose and see how the result was computed.