Multiplying Vectors and Matrices

Different kinds of vector and matrix multiplication.

This multiplies each element of the vector by the scalar k:

k {a,b,c}

The "dot" operator gives the scalar product of two vectors:

{a,b,c}.{ap,bp,cp}

You can also use dot to multiply a matrix by a vector:

{{a,b},{c,d}}.{x,y}

Dot is also the notation for matrix multiplication in the Wolfram Language:

{{a,b},{c,d}}.{{1,2},{3,4}}

It is important to realize that you can use "dot" for both left- and right-multiplication of vectors by matrices. The Wolfram Language makes no distinction between "row" and "column" vectors. (RefLink[Dot, paclet:ref/Dot]) carries out whatever operation is possible. (In formal terms, a.b contracts the last index of the tensor a with the first index of b.)

Here are definitions for a matrix m and a vector v:

m={{a,b},{c,d}};v={x,y}

This left-multiplies the vector v by m. The object v is effectively treated as a column vector in this case:

m.v

You can also use dot to right-multiply v by m. Now v is effectively treated as a row vector:

v.m

You can multiply m by v on both sides to get a scalar:

v.m.v

For some purposes, you may need to represent vectors and matrices symbolically without explicitly giving their elements. You can use (RefLink[Dot, paclet:ref/Dot]) to represent multiplication of such symbolic objects.

Dot effectively acts here as a noncommutative form of multiplication:

a.b.a

It is, nevertheless, associative:

(a.b).(a.b)

Dot products of sums are not automatically expanded out:

(a+b).c.(d+e)

You can apply the distributive law in this case using the function (RefLink[Distribute, paclet:ref/Distribute]), as discussed in "Structural Operations":

Distribute[%]

The "dot" operator gives "inner products" of vectors, matrices, and so on. In more advanced calculations, you may also need to construct outer or Kronecker products of vectors and matrices. You can use the general function (RefLink[Outer, paclet:ref/Outer]) or (RefLink[KroneckerProduct, paclet:ref/KroneckerProduct]) to do this.

The outer product of two vectors is a matrix:

Outer[Times,{a,b},{c,d}]

The outer product of a matrix and a vector is a rank three tensor:

Outer[Times,{{1,2},{3,4}},{x,y,z}]

Outer products are discussed in more detail in "Tensors".

The Kronecker product of a matrix and a vector is a matrix:

KroneckerProduct[{{1,2},{3,4}},{x,y,z}]

The Kronecker product of a pair of 2×2 matrices is a 4×4 matrix:

KroneckerProduct[{{1,2},{3,4}},{{a,b},{c,d}}]