Getting the Non Basic and Basic Rows of a Matrix in MATLAB
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Varun
am 18 Mai 2023
Bearbeitet: Varun
am 18 Mai 2023
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?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Least Squares finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!