Matrix and Vector Entry Assignment
Assignment statements can be used to change the value of entries in an existing Matrix or Vector (whose constructor option ro has not been set to readonly).
If assignment statements are used for this purpose, there are consequences regarding how the resulting Matrix or Vector is returned.

In the following sections, A is a Matrix and V is a Vector.


Assigning Values to Entries



Each of the entry selection formats described in Matrix and Vector Entry Extraction can be used on the lefthand side of an assignment statement. Entries selected in the lefthand side of the assignment statement are replaced by the corresponding entries of the righthand side. Unspecified entries are set to 0. The number of dimensions in such an assignment statement must match; a Vector can be assigned to a submatrix, provided it is a 1 x n submatrix.


For example, the assignment

>

A := Matrix([[9,9,9,9],[9,9,9,9],[9,9,9,9],[9,9,9,9]]);

${A}{\u2254}\left[\begin{array}{cccc}{9}& {9}& {9}& {9}\\ {9}& {9}& {9}& {9}\\ {9}& {9}& {9}& {9}\\ {9}& {9}& {9}& {9}\end{array}\right]$
 (1) 
>

A[1..2, 2..4] := Matrix([[5, 6], [7, 8]]);

${{A}}_{{1}{..}{2}{,}{2}{..}{4}}{\u2254}\left[\begin{array}{cc}{5}& {6}\\ {7}& {8}\end{array}\right]$
 (2) 
$\left[\begin{array}{cccc}{9}& {5}& {6}& {0}\\ {9}& {7}& {8}& {0}\\ {9}& {9}& {9}& {9}\\ {9}& {9}& {9}& {9}\end{array}\right]$
 (3) 

replaces A[1, 2] with 5, A[1, 3] with $6$, A[2, 2] with $7$, and A[2, 3] with $8$. The entries A[1, 4] and A[2, 4] are set to 0.


It is not necessary for the selection on the lefthand side of an assignment statement to represent contiguous nor ordered components of the Matrix or Vector. For example, A[[ 3, 1], 1..1] := B replaces row 3 and row 1 of A with, respectively, row 1 and row 2 of some existing Matrix B.



Properties of the Resulting Matrix or Vector



All of the assignment operations mentioned operate in place  the resulting Matrix or Vector overwrites the original Matrix or Vector. One consequence is that the command A[1..1, 1..1] := Matrix([[...], ..., [...]]) causes a replacement of all the entries of A, whereas the command A := Matrix([[...], ..., [...]]) creates a new Matrix.


For all assignments, the values on the righthand side must be of the same or compatible datatype as that of the Matrix or Vector on the lefthand side. Furthermore, it is an error if the righthand side does not fit into the selected submatrix, subvector, or scalar location specified on the lefthand side. It is not an error if the righthand side is smaller than the lefthand side.






