This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / The Mathematica Book / Advanced Mathematics in Mathematica / Linear Algebra /

3.7.2 Getting and Setting Pieces of Matrices

Ways to get pieces of matrices.

Matrices in Mathematica are represented as lists of lists. You can use all the standard Mathematica list-manipulation operations on matrices.

Here is a sample matrix.

In[1]:= t = Array[a, {3, 3}]


This picks out the second row of the matrix.

In[2]:= t[[2]]


Here is the second column of the matrix.

In[3]:= t[[All, 2]]


This picks out a submatrix.

In[4]:= Take[t, {1, 2}, {2, 3}]


Resetting parts of matrices.

Here is a matrix.

In[5]:= m = {{a, b}, {c, d}}


This resets the 2, 2 element to be x, then shows the whole matrix.

In[6]:= m[[2, 2]] = x; m


This resets all elements in the second column to be z.

In[7]:= m[[All, 2]] = z; m


This separately resets the two elements in the second column.

In[8]:= m[[All, 2]] = {i, j}; m


This increments all the values in the second column.

In[9]:= m[[All, 2]]++; m