How to get only linearly independent rows in a matrix or to remove linear dependency b/w rows in a matrix?
Ältere Kommentare anzeigen
Say I have a matrix A = [1,1,1;1,2,3;4,4,4]; and I want only the linearly independent rows in my new matrix. The answer might be A_new = [1,1,1;1,2,3] or A_new = [1,2,3;4,4,4]
Since I have a very large matrix so I need to decompose the matrix into smaller linearly independent full rank matrix. Can someone please help?
Akzeptierte Antwort
Weitere Antworten (4)
Wayne King
am 5 Dez. 2013
Bearbeitet: Wayne King
am 5 Dez. 2013
A = [1,1,1;1,2,3;4,4,4];
[R,basiccol] = rref(A);
B = A(:,basiccol);
The columns of B are a basis for the range of A. B has the same rank as A.
3 Kommentare
I have been warned not to trust RREF for this kind of thing. That was my reason for coding the QR-based method in my Answer.
Wayne King
am 5 Dez. 2013
As Matt advises below just transpose to work on rows.
B = A';
[R,basiccol] = rref(B);
B = B(:,basiccol)'
Lem
am 27 Nov. 2015
0 Stimmen
Hello,
I want to ask: instead of rank estimation, can we not just use the minpoly function, get the largest non-zero degree (r) from there and use r instead?
1 Kommentar
There's no way to avoid estimating rank. minpoly sounds like an alternative way to do so, but requires the Symbolic Toolbox. It also appears to be a lot slower than a QR approach, even for rather small matrices:
>> A=rand(10);
>> tic;minpoly(A);toc
Elapsed time is 0.875673 seconds.
>> tic;qr(A);toc
Elapsed time is 0.000063 seconds.
Dave Stanley
am 24 Aug. 2017
I wrote a few functions to handle this. They do basically the same as Matt J's function above, with some added bells and whistles. (Namely, it includes an option for ignoring columns that are shifted by a constant; for example, if col2 = 10 - col1. It also returns indices to clusters of originally linearly dependent columns ). Again, you'd have to add a transpose to operate on rows instead of columns. Hope it's useful to someone.
For numerical matrices: https://www.mathworks.com/matlabcentral/fileexchange/64221-getlinearindependent-a-ignore-constant-shift-
For cell arrays: https://www.mathworks.com/matlabcentral/fileexchange/64222-getlinearindependentcell-a-ignore-constant-shift-
On your example above:
A = [1,1,1;1,2,3;4,4,4]'
[Abasis, Abasisi, Asub]= getLinearIndependent(A)
Result:
Input:
A =
1 1 4
1 2 4
1 3 4
Output:
Abasis =
1 1
1 2
1 3
Abasisi =
1 2
Asub =
1×2 cell array
[1,3] [2]
Here, Asub{1} contains the indices of all columns linearly dependent with the first basis vector, and Asub{2} contains that for the second.
Dominique Joubert
am 9 Nov. 2018
0 Stimmen
svd , and looking at the number of non-zero singular values
8 Kommentare
Bruno Luong
am 9 Nov. 2018
Bearbeitet: Bruno Luong
am 9 Nov. 2018
Partial satisfied answer. SVD gives the rank but will be unable to tell set of independent rows. Since eveything is mixed together in U and V. QR is the right method as answered above.
Dominique Joubert
am 9 Nov. 2018
Looking at the columns of the right singular vectors, related to the ZERO singular values, numerically, the singular values beyond a gap, the non-zero entries of these columns can tell you which columns are linearly dependant.
In addition SVD is better suited to low rank examples.
Bruno Luong
am 9 Nov. 2018
Bearbeitet: Bruno Luong
am 9 Nov. 2018
Please show us which rows of A are independent if one looks only from U and V and D?
> A=[1 2 3; 1 2 3; 2 3 4; 3 5 7]
A =
1 2 3
1 2 3
2 3 4
3 5 7
>> [U,D,V]=svd(A)
U =
-0.3157 0.5480 0.7631 0.1331
-0.3157 0.5480 -0.4095 -0.6575
-0.4548 -0.6270 0.3536 -0.5244
-0.7706 -0.0790 -0.3536 0.5244
D =
11.8231 0 0
0 0.4633 0
0 0 0.0000
0 0 0
V =
-0.3259 -0.8527 0.4082
-0.5481 -0.1814 -0.8165
-0.7703 0.4898 0.4082
>>
Dominique Joubert
am 9 Nov. 2018
referring to correlated columns ;)
Bruno Luong
am 9 Nov. 2018
Bearbeitet: Bruno Luong
am 9 Nov. 2018
Of which matrix? U and V are orthonormal so theirs columns are not correlated. Or if you like the correlation is actually 0.
I stop here because so far your claim of using SVD doesn't seem to hold on a solid ground.
Dominique Joubert
am 9 Nov. 2018
I hope you agree that the 3 columns of A are linearly dependant. After svd you see that the rank of A is 2 , this the matrix is rank deficient by 1. Now look at the last column of V =[0.4 -0.8 0.4]’ this relates to the single zero valued singular value. These 3 non zero values indicate that the 3 columns of A are linearly dependant. If for example the values in that column were [0.4 0 0.2]’ that would have implied that columns 1 and 3 are linearly dependant.
Bruno Luong
am 9 Nov. 2018
Bearbeitet: Bruno Luong
am 9 Nov. 2018
"If for example the values in that column were [0.4 0 0.2]"
But it's not the case. So you can't conclude anything in the above example.
If you want to convince, write down your algorithm to detect independent columns using SVD, then we can speak.
Puneet
am 9 Nov. 2018
Kategorien
Mehr zu Linear Algebra finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!