필터 지우기
필터 지우기

Getting the Non Basic and Basic Rows of a Matrix in MATLAB

조회 수: 1 (최근 30일)
Teoman
Teoman 2023년 3월 13일
편집: Varun 2023년 5월 18일
I want to add a bit to the basic_nonbasic.m code below where it also prints the basic and non basic rows of A. The basic columns are going to be the ones that contain only 1s and 0s, and the arrangement of the 1s must be different according to the rank of the matrix. For example, if the matrix has a rank of 2 (variable RANK), then there will be a column with a 1 in the 0th index and another column with a 1 at the 1st index. The rest of the values other than 1 will be full of 0s. Hence the number of basic columns must be equivalent to the RANK variable. The columns that are not basic will just be the non basic columns. The same principle also applies for the rows for the making of the nonbasic and basic rows. I do not know how I can get that to work. The code below gives out the basic(basiccols) and non basic columns(nonbasiccols) of A. Please add a bit where it gives the basic rows(basicrows) and non basic columns(nonbasicrows) of A. Look at the expected intput and output below:
Input:
A = [9 18 11 51;-7 -14 -7 -35;3 6 3 15;3 6 2 12]
Output:
non basic rows:
basic rows:
3 3
6 6
3 2
15 12
basic_nonbasic.m:
format rational
A = [9 18 11 51;-7 -14 -7 -35;3 6 3 15;3 6 2 12]
RANK = rank(A);
[X, I]=licols(A);
A_reduced=X\A;
A_reduced(end+1:size(A,1),:)=0
basiccols=A(:,I);
nonbasiccols=A(:,setdiff(1:size(A,2),I)) % <- Basis for the Column Space of A
licols.m
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 = abs(R(1));
end
%Rank estimation
r = find(diagr >= tol*diagr(1), 1, 'last'); %rank estimation
idx=sort(E(1:r));
Xsub=X(:,idx);
  댓글 수: 3
Teoman
Teoman 2023년 3월 13일
편집: Teoman 2023년 3월 13일
Updated the the description sorry for the missing info.
Varun
Varun 2023년 5월 18일
편집: Varun 2023년 5월 18일
Hi! I am still unclear about the exact definition of basic and nonbasic rows. When I ran your code for basic columns, there were two columns- [1;0;0;0;] and [0;1;0;0;], and the basic columns are returned based on the corresponding position of these reduced columns. So, would basic rows get reduced to [1,0,0,0;] and [0,1,0,0;]? Is that the aim?
Also, what if the transpose of the matrix is passed in the same function for columns? Would that not work?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by