linalg::submatrix -- extract a
submatrix or a subvector from a matrix or a vector, respectively
Introductionlinalg::submatrix(A, r1..r2, c1..c2)
returns a copy of the submatrix of the matrix A obtained by
selecting the rows r1,r1+1,...,r2 and the columns
c1,c1+1,...,c2.
linalg::submatrix(v,i1..i2) returns a copy
of the subvector of the vector v obtained by selecting the
components with indices i1,i1+1,...,i2.
Call(s)linalg::submatrix(A, r1..r2, c1..c2)
linalg::submatrix(A, rlist, clist)
linalg::submatrix(v, i1..i2)
linalg::submatrix(v, list)
ParametersA |
- | an m x n matrix of a domain of category
Cat::Matrix |
v |
- | a vector with k components, i.e., a k
x 1 or 1 x k matrix of a domain of category Cat::Matrix |
r1..r2, c1..c2 |
- | ranges of row/column indices: positive integers less or equal to m and n, respectively |
rlist, clist |
- | lists of row/column indices: positive integers less or equal to m and n, respectively |
i1..i2 |
- | a range of vector indices: positive integers less or equal to k |
list |
- | a list of vector indices: positive integers less or equal to k |
Returnsa matrix of the same domain type as A or a vector of
the same domain type as v, respectively.
Related
Functionslinalg::col, linalg::row, linalg::substitute
DetailsA[r1..r2,c1..c2] and
v[i1..i2], respectively, can be used instead of
linalg::submatrix(A, r1..r2, c1..c2) and
linalg::submatrix(v, i1..i2).linalg::submatrix(A,rlist,clist) returns
the submatrix of the matrix A whose (i,j)-th
component is A[rlist[i],clist[j]].linalg::submatrix(v,list) returns the
subvector of the vector v whose i-th component
is v[list[i]].v is a row vector or a column vector, then
linalg::submatrix(v, 1..1, i1..i2) and
linalg::submatrix(v, i1..i1, 1..1),
respectively, are valid inputs, and they both are equivalent to the
call linalg::submatrix(v,i1..i2).
Example
1We define the following matrix:
>> A := matrix([[1, x, 0], [0, x^2, 1]])
+- -+
| 1, x, 0 |
| |
| 2 |
| 0, x , 1 |
+- -+
The submatrix A[1..1][1..2] of A
is given by:
>> linalg::submatrix(A, 1..1, 1..2)
+- -+
| 1, x |
+- -+
Equivalent to the use of the index operator we obtain:
>> A[1..1, 1..2]
+- -+
| 1, x |
+- -+
We extract the first and the third column of
A and get the 2 x 2 identity matrix:
>> linalg::submatrix(A, [1, 2], [1, 3])
+- -+
| 1, 0 |
| |
| 0, 1 |
+- -+
Example
2Vector components can be accessed by a single index or a range of indices. For example, to extract the first two components of the following vector:
>> v := matrix([1, 2, 3])
+- -+
| 1 |
| |
| 2 |
| |
| 3 |
+- -+
just enter the command:
>> v[1..2]
+- -+
| 1 |
| |
| 2 |
+- -+
Of course, the same subvector can be extracted with the
command linalg::submatrix( v,1..2 ).
The following input returns the vector comprising the
first and the third component of v:
>> linalg::submatrix(v, [1, 3])
+- -+
| 1 |
| |
| 3 |
+- -+
linalg::extractMatrix