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