フィルターのクリア

How to get only linearly independent rows in a matrix or to remove linear dependency b/w rows in a matrix?

112 ビュー (過去 30 日間)
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?
  2 件のコメント
sixwwwwww
sixwwwwww 2013 年 12 月 5 日
what is meaning of linear independent in your case? A_new is linearly independent and A is not linearly dependent?
Puneet
Puneet 2013 年 12 月 5 日
Linear dependence in the matrix makes it singular. In this case A, row 3 can be obtained 4*row 1. This means that the third row is redundant. Making the matrix singular(det(A)=0).I expect if there is some built in function in matlab that could give me A_new or someone has already written a code for such problem.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2013 年 12 月 5 日
This extracts linearly independent columns, but you can just pre-transpose the matrix to effectively work on the rows.
function [Xsub,idx]=licols(X,tol)
%Extract a linearly independent set of columns of a given matrix X
%
% [Xsub,idx]=licols(X)
%
%in:
%
% X: The given input matrix
% tol: A rank estimation tolerance. Default=1e-10
%
%out:
%
% Xsub: The extracted columns of X
% idx: The indices (into X) of the extracted columns
if ~nnz(X) %X has no non-zeros and hence no independent columns
Xsub=[]; idx=[];
return
end
if nargin<2, tol=1e-10; end
[Q, R, E] = qr(X,0);
if ~isvector(R)
diagr = abs(diag(R));
else
diagr = R(1);
end
%Rank estimation
r = find(diagr >= tol*diagr(1), 1, 'last'); %rank estimation
idx=sort(E(1:r));
Xsub=X(:,idx);
  21 件のコメント
Matt J
Matt J 2020 年 9 月 21 日
編集済み: Matt J 2020 年 9 月 21 日
MICHAEL MONT-ETON's comment moved here.
Matt J.:
Thanks for the code. I'd like to provide a reference for your work in my upcoming paper that would benefit from removal of dependent equations in the system I am studying.
Please indicate how you would like that to read.
Very Respectfully,
Mike Mont-Eton
Matt J
Matt J 2020 年 9 月 21 日
@Michael,
You can just reference the File Exchange link.
The algorithm is not really mine. I just posted it as a FAQ.

サインインしてコメントする。

その他の回答 (4 件)

Wayne King
Wayne King 2013 年 12 月 5 日
編集済み: Wayne King 2013 年 12 月 5 日
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 件のコメント
Matt J
Matt J 2013 年 12 月 5 日
編集済み: Matt J 2013 年 12 月 5 日
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
Wayne King 2013 年 12 月 5 日
As Matt advises below just transpose to work on rows.
B = A';
[R,basiccol] = rref(B);
B = B(:,basiccol)'

サインインしてコメントする。


Lem
Lem 2015 年 11 月 27 日
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 件のコメント
Matt J
Matt J 2015 年 11 月 27 日
編集済み: Matt J 2015 年 11 月 27 日
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
Dave Stanley 2017 年 8 月 24 日
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.
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
Dominique Joubert 2018 年 11 月 9 日
svd , and looking at the number of non-zero singular values
  8 件のコメント
Bruno Luong
Bruno Luong 2018 年 11 月 9 日
編集済み: Bruno Luong 2018 年 11 月 9 日
"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
Puneet 2018 年 11 月 9 日
The algorithm written above by Matt works pretty good. I have tested that algorithm for quite a large matrix (1M+x1M+). However, I tried the svd route too when I posted this question, as said above I was not able to get results I am looking for.
Thanks, Puneet

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by