Dot

a.b.c or Dot[a,b,c]

gives products of vectors, matrices, and tensors.

Details

  • a.b gives an explicit result when a and b are lists with appropriate dimensions. It contracts the last index in a with the first index in b.
  • Various applications of Dot:
  • {a1,a2}.{b1,b2}scalar product of vectors
    {a1,a2}.{{m11,m12},{m21,m22}}
    product of a vector and a matrix
    {{m11,m12},{m21,m22}}.{a1,a2}
    product of a matrix and a vector
    {{m11,m12},{m21,m22}}.{{n11,n12},{n21,n22}}
    product of two matrices
  • The result of applying Dot to two tensors and is the tensor . Applying Dot to a rank tensor and a rank tensor gives a rank tensor. »
  • Dot can be used on SparseArray objects, returning a SparseArray object when possible. »
  • When its arguments are not lists or sparse arrays, Dot remains unevaluated. It has the attribute Flat.

Examples

open allclose all

Basic Examples  (3)

Scalar product of vectors:

Products of matrices and vectors:

Matrix product:

Scope  (2)

a and b are 5×5 random matrices of zeros and ones:

Use exact arithmetic to find the matrix product of a and b:

Use machine arithmetic:

Use higher-precision arithmetic:

Use SparseArray objects:

Compute the matrix product of random real and complex rectangular matrices:

Generalizations & Extensions  (1)

Dot works for tensors:

The dimensions of the result are those of the input with the common dimension collapsed:

Any combination is allowed as long as products are done with a common dimension:

Applications  (1)

A linear mapping :

Get the matrix representation m for the linear mapping:

Apply the linear mapping to a vector:

Using the matrix with Dot is faster:

Properties & Relations  (5)

a is a 2×3×4 tensor and b is a 4×5 random matrix:

The result of applying Dot to two tensors and is the tensor :

Applying Dot to a rank tensor and a rank tensor gives a rank tensor:

v is a random complex vector:

Norm[v] is given by sqrt(v.TemplateBox[{v}, Conjugate]):

a is a 3×3 matrix:

Compute the matrix product a.a.a:

This is the same as MatrixPower:

This is equivalent to composing the action of a on a vector three times:

Dot is a special case of Inner:

Dot can be implemented as a combination of TensorProduct and TensorContract:

Possible Issues  (3)

Dot effectively treats vectors multiplied from the right as column vectors:

Dot effectively treats vectors multiplied from the left as row vectors:

To get an outer product, you need to form the inputs as matrices:

Or you can use KroneckerProduct:

Or Outer:

Dot is not a Hermitian inner product:

Use Conjugate in one argument to get a Hermitian inner product:

Check that the result coincides with the square of the norm of a:

Introduced in 1988
 (1.0)
 |
Updated in 2003
 (5.0)