### 14.3.11 Elementary row operations

##### Adding a row to another row.

The rowAdd command adds one row of a matrix to another row.

- rowAdd takes three arguments:
  - A, a matrix.
  - n1 and n2, two integers.
- rowAdd(A,n1,n2) returns the matrix obtained by replacing in A, the row of index n2 by the sum of the rows of index n1 and n2.

#### Example

rowAdd([[1,2],[3,4]],0,1)

⎡
⎢
⎣

1 | 2
4 | 6

⎤
⎥
⎦

##### Multiplying a row by an expression.

The mRow, scale and SCALE commands multiply a row of a matrix by an expression.

- mRow takes three arguments:
  - expr, an expression.
  - A, a matrix.
  - n, an integer.
- mRow(expr,A,n) returns the matrix obtained by replacing in A, the row of index n by the product of the row of index n by expr.

The scale or SCALE command is similar to mRow except for a different order of arguments.

- scale takes three arguments:
  - A, a matrix.
  - expr, an expression.
  - n, an integer.
- scale(A,expr,n) returns the matrix obtained by replacing in A, the row of index n by the product of the row of index n by expr.

#### Examples

mRow(12,[[1,2],[3,4]],1)

⎡
⎢
⎣

1 | 2
36 | 48

⎤
⎥
⎦

scale([[1,2],[3,4]],12,1)

⎡
⎢
⎣

1 | 2
36 | 48

⎤
⎥
⎦

##### Adding k times a row to another row.

The mRowAdd, scaleadd and SCALEADD commands add a multiple of one row of a matrix to another.

- mRowAdd takes four arguments:
  - k, a real number.
  - A, a matrix.
  - n1 and n2, two integers.
- mRowAdd(k,A,n1,n2) returns the matrix obtained by replacing in A, the row with index n2 by the sum of the row with index n2 and k times the row with index n1.

The scaleadd or SCALEADD command is similar mRowAdd except for a different order of arguments.

- scaleadd takes four arguments:
  - A, a matrix.
  - k, a real number.
  - n1 and n2, two integers.
- scaleadd(A,k,n1,n2) returns the matrix obtained by replacing in A, the row with index n2 by the sum of the row with index n2 and k times the row with index n1.

#### Examples

mRowAdd(1.1,[[5,7],[3,4],[1,2]],1,2)

⎡
⎢
⎢
⎣

5 | 7
3 | 4
4.3 | 6.4

⎤
⎥
⎥
⎦

scaleadd([[5,7],[3,4],[1,2]],1.1,1,2)

⎡
⎢
⎢
⎣

5 | 7
3 | 4
4.3 | 6.4

⎤
⎥
⎥
⎦

##### Exchanging two rows.

The rowSwap or rowswap or swaprow command switches two rows in a matrix.

- rowSwap takes three arguments:
  - A, a matrix.
  - n1 and n2, integers.
- rowSwap(A,n1,n2) returns the matrix obtained by exchanging in A, the row with index n1 with the row with index n2.

#### Example

rowSwap([[1,2],[3,4]],0,1)

⎡
⎢
⎣

3 | 4
1 | 2

⎤
⎥
⎦

##### Exchanging two columns.

The colSwap or colswap or swapcol command switches two columns in a matrix.

- colSwap takes three arguments:
  - A, a matrix.
  - n1 and n2, integers.
- colSwap(A,n1,n2) returns the matrix obtained by exchanging in A, the column with index n1 with the column with index n2.

#### Example

colSwap([[1,2],[3,4]],0,1)

⎡
⎢
⎣

2 | 1
4 | 3

⎤
⎥
⎦