Setting Pieces of MatricesSetting elements, rows, and columns so that a sparse matrix is updated is quite straightforward by using the Mathematica function Part on the left-hand side of an assignment. Resetting parts of matrices. Here is a sample sparse matrix. In[1]:=  |
Out[2]//MatrixForm=
|
To update parts of a matrix you can use Part on the left-hand side of an assignment. This sets the third element of the third row. In[3]:=  |
Out[4]//MatrixForm=
|
This sets the second row of the matrix. In[5]:=  |
Out[6]//MatrixForm=
|
Here, the second column is set. In[7]:=  |
Out[8]//MatrixForm=
|
Setting Multiple PiecesIt is possible to set multiple elements by using indices in lists. This will be demonstrated with the following sample matrix. In[1]:=  |
Out[2]//MatrixForm=
|
The following sets the first and third elements of the second row. In[3]:=  |
Out[4]//MatrixForm=
|
If the right-hand side of the assignment is a list that matches the number of elements being assigned, the assignment is done element by element. Thus, the following gives two different values for the first and third elements of the second row. In[5]:=  |
Out[6]//MatrixForm=
|
The following sets the second and third rows. In[7]:=  |
Out[8]//MatrixForm=
|
The following gives two different values for the second and third rows. In[9]:=  |
Out[10]//MatrixForm=
|
The following sets the first and third elements of the second and third rows. In[11]:=  |
Out[13]//MatrixForm=
|
The following sets the first and third elements of the second and third rows with different values. In[14]:=  |
Out[15]//MatrixForm=
|
|