The elementary row operations

### 5.45.11 The elementary row operations

#### Adding a row to another row: rowAdd

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

Input:

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

Output:

⎡ ⎢ ⎣ |
1 | 2
4 | 6
| ⎤ ⎥ ⎦

#### Multiplying a row by an expression: mRow scale SCALE

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.

#### Example

Input:

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

Output:

⎡ ⎢ ⎣ |
1 | 2
36 | 48
| ⎤ ⎥ ⎦

The scale command is the same as mRow except that it takes the arguments in a different order.
SCALE is a synonym for scale.

- 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.

#### Example

Input:

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

Output:

⎡ ⎢ ⎣ |
1 | 2
36 | 48
| ⎤ ⎥ ⎦

#### Adding k times a row to an another row: mRowAdd scaleadd SCALEADD

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.

#### Example

Input:

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

Output:

⎡ ⎢ ⎢ ⎣ |
5 | 7
3 | 4
4.3 | 6.4
| ⎤ ⎥ ⎥ ⎦

The scaleadd command is the same as mRowAdd except that it takes the arguments in a different order.
SCALEADD is a synonym for scaleadd.

- 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.

#### Example

Input:

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

Output:

⎡ ⎢ ⎢ ⎣ |
5 | 7
3 | 4
4.3 | 6.4
| ⎤ ⎥ ⎥ ⎦

#### Exchanging two rows: rowSwap rowswap swaprow

The rowSwap command switches two rows in a matrix.
rowswap and swaprow are synonyms for rowSwap.

- 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

Input:

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

Output:

⎡ ⎢ ⎣ |
3 | 4
1 | 2
| ⎤ ⎥ ⎦

#### Exchanging two columns: colSwap colswap swapcol

The colSwap command switches two columns in a matrix.
colswap and swapcol are synonyms for colSwap.

- 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

Input:

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

Output:

⎡ ⎢ ⎣ |
2 | 1
4 | 3
| ⎤ ⎥ ⎦