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

3.7.7 Basic Matrix Operations


Some basic matrix operations.







Transposing a matrix interchanges the rows and columns in the matrix. If you transpose an matrix, you get an


matrix as the result.







  • Transposing a matrix gives a


    result.
  • In[1]:= Transpose[ {{a, b, c}, {ap, bp, cp}} ]

    Out[1]=




    Det[m] gives the determinant of a square matrix m. Minors[m,k] gives a matrix of the determinants of all the submatrices of m. You can apply Minors


    to rectangular, as well as square, matrices.




  • Here is the determinant of a simple


    matrix.
  • In[2]:= Det[ {{a, b}, {c, d}} ]

    Out[2]=










  • This generates a matrix, whose


    entry is a[


    i,j].
  • In[3]:= m = Array[a, {3, 3}]

    Out[3]=

  • Here is the determinant of m.
  • In[4]:= Det[ m ]

    Out[4]=




  • This gives the matrix of all minors of m


    .
  • In[5]:= Minors[m, 2]

    Out[5]=

    You can use Det to find the characteristic polynomial for a matrix. Section 3.7.9 discusses ways to find eigenvalues and eigenvectors directly.




  • Here is a


    matrix.
  • In[6]:= m = Table[ 1/(i + j), {i, 3}, {j, 3} ]

    Out[6]=

  • Following precisely the standard mathematical definition, this gives the characteristic polynomial for m.
  • In[7]:= Det[ m - x IdentityMatrix[3] ]

    Out[7]=

    There are many other operations on matrices that can be built up from standard Mathematica functions. One example is the trace or spur of a matrix, given by the sum of the terms on the leading diagonal.




  • Here is a simple


    matrix.
  • In[8]:= m = {{a, b}, {c, d}}

    Out[8]=

  • You can get the trace of the matrix by explicitly constructing a sum of the elements on its leading diagonal.
  • In[9]:= Sum[ m[[i, i]], {i, 2} ]

    Out[9]=


    Powers and exponentials of matrices.




  • Here is a


    matrix.
  • In[10]:= m = {{0.4, 0.6}, {0.525, 0.475}}

    Out[10]=

  • This gives the third matrix power of m.
  • In[11]:= MatrixPower[m, 3]

    Out[11]=

  • It is equivalent to multiplying three copies of the matrix.
  • In[12]:= m . m . m

    Out[12]=

  • Here is the millionth matrix power.
  • In[13]:= MatrixPower[m, 10^6]

    Out[13]=

  • This gives the matrix exponential of m.
  • In[14]:= MatrixExp[m]

    Out[14]=

  • Here is an approximation to the exponential of m, based on a power series approximation.
  • In[15]:= Sum[MatrixPower[m, i]/i!, {i, 0, 5}]

    Out[15]=