Finding the columns that contain 1 and 0s(Basic Columns) in MATLAB
3 次查看(过去 30 天)
显示 更早的评论
I am attempting to create a piece of code that can identify the basic and non basic columns from a matrix. 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. I am unsure of the best method to code such a thing that will accurately showcase the basic and non basic columns. Note that there could be 0 basic columns or 0 non basic columns. Please get the indexes starting from 1 to identify the basic and non basic columns. In the outputs for the test cases X1 is the first column of the RREF matrix from the very left whilst X3 is the 3rd column.
Code:
A = [3 2 4;3 3 6];
RREF = rref(A)
RANK = rank(A)
Test Cases
Output:
Basic Columns: {X1, X2}
Non Basic Columns: {X3, X4, X5}
Output:
Basic Columns: {X1}
Non Basic Columns: {X2, X3, X4}
Input:
Output:
Basic Columns: {X1, X2, X3}
Non Basic Columns: {}
0 个评论
采纳的回答
Matt J
2023-3-7
编辑:Matt J
2023-3-7
Well, I definiitely don't think you should be using rref, which is a very primitive command. Instead , you should use this FEX download,
Note that the choice of basic columns will not be unique, in general.
A = [3 2 4;3 3 6]
[X, I]=licols(A);
A_reduced=X\A;
A_reduced(end+1:size(A,1),:)=0
basiccols=A_reduced(:,I)
nonbasiccols=A_reduced(:,setdiff(1:size(A,2),I))
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!