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 / Add-ons / Standard Packages / LinearAlgebra  /

LinearAlgebra`MatrixManipulation`

This package includes functions for composing and separating matrices using rows, columns, and submatrices. All of the definitions involve simple combinations of built-in functions. Also included are functions for constructing a variety of special matrices.


Functions for combining matrices.

  • This loads the package.
  • In[1]:= << LinearAlgebra`MatrixManipulation`;

  • Define a

    matrix.
  • In[2]:= a = {{a11, a12}, {a21, a22}}; MatrixForm[a]

    Out[2]//MatrixForm=

  • Define a second matrix.
  • In[3]:= b = {{b11, b12}, {b21, b22}}; MatrixForm[b]

    Out[3]//MatrixForm=

  • This constructs a matrix by combining the columns of the two matrices.
  • In[4]:= AppendColumns[a, b]

    Out[4]=

  • Here is the same matrix displayed using MatrixForm.
  • In[5]:= MatrixForm[%]

    Out[5]//MatrixForm=

  • A matrix can also be constructed by combining the rows of these matrices.
  • In[6]:= AppendRows[a, b] //MatrixForm

    Out[6]//MatrixForm=

  • Here is a matrix constructed from submatrices a and b.
  • In[7]:= BlockMatrix[{{a, b}, {b, {{0, 0},
    {0, 0}}}}] //MatrixForm

    Out[7]//MatrixForm=


    Functions for picking out pieces of matrices.

  • Here is a

    matrix.
  • In[8]:= mat = Array[m, {3, 4}]; MatrixForm[mat]

    Out[8]//MatrixForm=

  • This takes the last two rows of the matrix.
  • In[9]:= TakeRows[mat, -2] //MatrixForm

    Out[9]//MatrixForm=

  • This takes the second and third columns of the matrix.
  • In[10]:= TakeColumns[mat, {2,3}] //MatrixForm

    Out[10]//MatrixForm=

  • This takes the submatrix between the element at position

    2,3 and the element at position

    3,4

    .
  • In[11]:= TakeMatrix[mat, {2, 3}, {3, 4}] //MatrixForm

    Out[11]//MatrixForm=

  • Here is the same submatrix, specified as a matrix starting with the element at position

    2,3

    .
  • In[12]:= SubMatrix[mat, {2, 3}, {2, 2}] //MatrixForm

    Out[12]//MatrixForm=


    Special matrices.

  • Here is an upper diagonal matrix with elements f[i,j].
  • In[13]:= UpperDiagonalMatrix[f, 3] //MatrixForm

    Out[13]//MatrixForm=

  • Matrix elements can be specified using a pure function.
  • In[14]:= LowerDiagonalMatrix[#1 + #2 &, 3] //MatrixForm

    Out[14]//MatrixForm=

  • Here is a

    Hilbert matrix.
  • In[15]:= HilbertMatrix[2, 4] //MatrixForm

    Out[15]//MatrixForm=

  • The elements of the Hankel matrix can be given as a list.
  • In[16]:= HankelMatrix[{w, x, y, z}] //MatrixForm

    Out[16]//MatrixForm=


    Creating matrices from a set of linear equations.

  • This extracts the matrix of coefficients and the vector of right-hand sides from a list of linear equations.
  • In[17]:= LinearEquationsToMatrices[
    {a[1,1]*x + a[1,2]*y == c[1],
    a[2,1]*x + a[2,2]*y == c[2]}, {x, y}]

    Out[17]=


    Polar decomposition of a matrix.

  • This computes the polar decomposition of a matrix, then extracts the matrices and

    .
  • In[18]:= {u, s} = PolarDecomposition[ {{2., 0, 0},
    {3., 4., 0}, {4., 5., 6.}} ]

    Out[18]=

  • This gives the identity matrix.
  • In[19]:= u . Transpose[Conjugate[u]] // Chop

    Out[19]=

  • This gives the original matrix.
  • In[20]:= u . s // Chop

    Out[20]=


    Square matrix test.