This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / The Mathematica Book / Advanced Mathematics / Linear Algebra  /

3.7.5 Multiplying Vectors and Matrices

Different kinds of vector and matrix multiplication.

  • This multiplies each element of the vector by the scalar k.
  • In[1]:= k {a, b, c}


  • The "dot" operator gives the scalar product of two vectors.
  • In[2]:= {a, b, c} . {ap, bp, cp}


  • You can also use dot to multiply a matrix by a vector.
  • In[3]:= {{a, b}, {c, d}} . {x, y}


  • Dot is also the notation for matrix multiplication in Mathematica.
  • In[4]:= {{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. Mathematica makes no distinction between "row" and "column" vectors. 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.
  • In[5]:= 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.
  • In[6]:= m . v


  • You can also use dot to right-multiply v by m. Now v is effectively treated as a row vector.
  • In[7]:= v . m


  • You can multiply m by v on both sides, to get a scalar.
  • In[8]:= v . m . v


    For some purposes, you may need to represent vectors and matrices symbolically, without explicitly giving their elements. You can use dot to represent multiplication of such symbolic objects.

  • Dot effectively acts here as a non-commutative form of multiplication.
  • In[9]:= a . b . a


  • It is, nevertheless, associative.
  • In[10]:= (a . b) . (a . b)


  • Dot products of sums are not automatically expanded out.
  • In[11]:= (a + b) . c . (d + e)


  • You can apply the distributive law in this case using the function Distribute, as discussed in Section 2.2.10.
  • In[12]:= 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 Outer to do this.

  • The outer product of two vectors is a matrix.
  • In[13]:= Outer[Times, {a, b}, {c, d}]


  • The outer product of a matrix and a vector is a rank three tensor.
  • In[14]:= Outer[Times, {{1, 2}, {3, 4}}, {x, y, z}]


    Outer products will be discussed in more detail in Section 3.7.11.