linalg::swapRow -- swap two rows
in a matrix
Introductionlinalg::swapRow(A, r1, r2) returns a copy
of the matrix A with the rows with indices r1 and
r2 interchanged.
Call(s)linalg::swapRow(A, r1, r2)
linalg::swapRow(A, r1, r2, c1..c2)
ParametersA |
- | an m x n matrix of a domain of category
Cat::Matrix |
r1, r2 |
- | the row indices: positive integers <= m |
c1..c2 |
- | a range of column indices (positive integers <= n) |
Returnsa matrix of the same domain type as A.
Related
Functionslinalg::col, linalg::delCol, linalg::delRow, linalg::row, linalg::setCol, linalg::setRow, linalg::swapCol
Detailslinalg::swapRow(A, r1, r2,
c1..c2) is that only the components from column c1
to column c2 of row r1 are interchanged with
the corresponding components of row r2.
Example
1We consider the following matrix:
>> A := matrix(3, 3, (i, j) -> 3*(i - 1) + j)
+- -+
| 1, 2, 3 |
| |
| 4, 5, 6 |
| |
| 7, 8, 9 |
+- -+
The following command interchanges the first and the
second row of A. The result is the following matrix:
>> linalg::swapRow(A, 1, 2)
+- -+
| 4, 5, 6 |
| |
| 1, 2, 3 |
| |
| 7, 8, 9 |
+- -+
If only the components in the first two columns should be affected, we enter:
>> linalg::swapRow(A, 1, 2, 1..2)
+- -+
| 4, 5, 3 |
| |
| 1, 2, 6 |
| |
| 7, 8, 9 |
+- -+
The third column remains unchanged.