How to remove dependent rows in a matrix?

조회 수: 19 (최근 30일)
Kees Roos
Kees Roos 2012년 10월 5일
댓글: Arash Rabbani 2019년 8월 24일
Let A be an m by n matrix whose rows are linearly dependent. I want to remove rows from A such that the rank does not decrease. How can I find such rows of A?

채택된 답변

Matt J
Matt J 2012년 10월 5일
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);
  댓글 수: 11
mohsen
mohsen 2014년 6월 28일
I calculate rank with Matlab rank() function. it says the rank is 225
I must decrease raws from 398 to 261 without decreasing rnak,and you said the licols function removes raws ,but it removes columns.
Matt J
Matt J 2014년 6월 28일
편집: Matt J 2014년 6월 28일
Matlab's rank() function is not to be trusted blindly (as you can see from my previous plot). If nothing else, rank is subjectively dependent on the tolerance parameter that you use, just like I showed you that licols is. You chose to use the default tolerance, but a different choice would give you a different result, e.g.,
>> rank(docoeff,2)
ans =
203
I did not say that licols() removes rows. The help text clearly says that it removes columns. However, you can certainly use it to remove rows by transposing:
>> X=licols(docoeff.').'; whos X
Name Size Bytes Class Attributes
X 160x225 288000 double

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jos (10584)
Jos (10584) 2014년 1월 24일
Another, very straightforward, approach is to include them one by one and observe the changes in rank … (I agree that this is not so elegant!).
N = size(A,1) ; % number of rows
IncludeTF = false(N,1) ; % by default, exclude all rows, except ...
IncludeTF(1) = true ; % first row which can always be included
R0 = rank(A) ; % the original rank
for k = 2:N, % loop over all rows
B = A(IncludeTF,:) ; % select the currently included rows of A
IncludeTF(k) = rank(B) < R0 ; % include in B when the rank is less
end
isequal(rank(B), R0) % check!
  댓글 수: 1
Jeel Bhavsar
Jeel Bhavsar 2018년 11월 24일
I have the same question with gf matrix.Does this code work for gf(galois field) matrix?

댓글을 달려면 로그인하십시오.


Arash Rabbani
Arash Rabbani 2019년 8월 24일
This is a shorter version of Jos solution if you needed:
R1=1;
for I=1:size(A,1)
R2=rank(A(1:I,:));
if R2~=R1; disp(I); end
R1=R2+1;
end
  댓글 수: 1
Arash Rabbani
Arash Rabbani 2019년 8월 24일
It displays the rows with linear dependany to other rows.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by