linalg::addCol -- linear
combination of matrix columns
Introductionlinalg::addCol(A, c1, c2, s) returns a
copy of the matrix A in which column c2 of
A is replaced by s*col(A,c1) + col(A,c2).
Call(s)linalg::addCol(A, c1, c2, s)
ParametersA |
- | an m x n matrix of a domain of category
Cat::Matrix |
c1, c2 |
- | the column indices: positive integers <= n |
s |
- | an expression that can be converted into the component
ring of A |
Returnsa matrix of the same domain type as A.
Related
Functionslinalg::addRow,
linalg::col, linalg::multCol, linalg::multRow, Dom::Matrix
Example
1The following defines a 3x3 matrix over the integers:
>> A := Dom::Matrix(Dom::Integer)(
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
)
+- -+
| 1, 2, 3 |
| |
| 4, 5, 6 |
| |
| 7, 8, 9 |
+- -+
We replace the 2nd column by -col(A,1) + col(A,2), i.e., we subtract the first column from the second:
>> linalg::addCol(A, 1, 2, -1)
+- -+
| 1, 1, 3 |
| |
| 4, 1, 6 |
| |
| 7, 1, 9 |
+- -+
Example
2The following defines a 2x3 matrix over the reals:
>> B := Dom::Matrix(Dom::Real)(
[[sin(2), 0, 1], [1, PI, 0]]
)
+- -+
| sin(2), 0, 1 |
| |
| 1, PI, 0 |
+- -+
If s is an expression that does not
represent a real number then an error message is reported. The
following tries to replace the 1st column by x*col(B,3) +
col(B,1), where x is an identifier which cannot be
converted into the component ring Dom::Real of B:
>> delete x: linalg::addCol(B, 3, 1, x)
Error: unable to convert x [linalg::addCol]
Example
3If symbolic expressions are involved, then one may
define matrices over a component ring created by Dom::ExpressionField. The
following example defines a matrix over this default component
ring:
>> delete a11, a12, a21, a22, x: C := matrix([[a11, a12], [a21, a22]])
+- -+
| a11, a12 |
| |
| a21, a22 |
+- -+
We retry the input from the previous example:
>> linalg::addCol(C, 2, 1, x)
+- -+
| a11 + x a12, a12 |
| |
| a21 + x a22, a22 |
+- -+