I have a N×N general matrix H with rank n(<N).
Is there any way to get a n×n matrix with rank n from H?
For example,
|1 2 3|
H = |4 8 6|
|0 0 1|
has three eigenvalues 0,1,9 and its rank is 2. I want to get a 2×2 matrix with rank 2 which corresponds to the eigenspace sappaned by eigenvectors of 1,9.
CodePudding user response:
We are given a 3x3 matrix H
that is known to have rank r < 3
:
1 2 3
4 8 6
0 0 1
One can obtain an nxn
matrix comprised of the intersection of rows and columns of H
that has rank n
by computing the reduced row echelon form (RREF) of H
(also called the row canonical form).
After doing so, for each of n
row indices i
there will be a column in the RREF that contains a 1
in row i
(i.e., the row having index i
) and zeroes in all other rows. It is seen here that the RREF of H
is the following.
1 2 0
0 0 1
0 0 0
As column 0
(i.e., the column having index 0
) in the RREF has a 1
in row 0
and zeroes in all other rows, and column 2
has a 1
in row 1
and zeroes in all other rows, and no other column has a 1
in one row and zeroes in all other rows, we conclude that:
H
has rank2
; and- the
nxn
matrix comprised of elements inH
that are in rows0
and1
and columns0
and2
has rankn
.
Here an nxn
matrix with rank n
is therefore found to be
1 3
4 6
The same procedure is followed regardless of the size of H
(which need not be square) and the rank of H
need not be known in advance.
CodePudding user response:
Using the RowEchelon.jl package, we can apply the method described in @CarySwoveland's answer pretty easily. (This is not my area of expertise though, so any corrections to it are welcome; specifically, the choice of rows as 1 to number of pivots is an educated guess based on some trials.)
julia> H = [1 2 3
4 8 6
0 0 1];
julia> using RowEchelon
julia> _, pivotcols = rref_with_pivots(H)
([1.0 2.0 0.0; 0.0 0.0 1.0; 0.0 0.0 0.0], [1, 3])
julia> result = H[1:length(pivotcols), pivotcols]
2×2 Matrix{Int64}:
1 3
4 6
The package is just a home for code that used to be in Base Julia, so you can even just copy the code if you don't want to add it as a dependency.