Find minors of a rectangular matrix

205 views (last 30 days)
I have a rectangular 3x2 matrix at hand and I need to find the minors in an automated way so that the code can be used for any rectangular/square matrix I may encounter in future. I currently can find the minors manually for the existing matrix at hand but I want to automate the process through some loop. Any suggestions on how I can do it?
  2 Comments
Jan
Jan on 12 Jul 2022
Edited: Jan on 12 Jul 2022
Please explain, what you call "minors". Do you mean the subdeterminants? Aren't they defined for quadratic matrices only? Posting an example would help to avoid guessing.
Akshay Vivek Panchwagh
Akshay Vivek Panchwagh on 12 Jul 2022
Let me rephrase my question, as I can observe that it has led to quite a commotion here. I need to do all this to obtain Smith Form of a matrix. Perhaps using the word 'minor' was wrong here, since it is something that is done for square matrices. So, apologies for all the confusion here.
As I stated above, I need to find Smith Form of a rectangular matrix. I am aware that one can directly find it by typing smithForm(A) in MATLAB. But that works only for square matrices. The problems I have at hand consist of rectangular matrices (MIMO systems in control engineering). Therefore, I cannot use it directly. I also know that there is one function here developed by someone wherein if you implement the function and type MNsmithForm(A), it solves the whole thing. But, that code is too long and I have seen certain solutions where the whole process can be simply executed in 3 lines of code of a 'for loop'.
The Smith Form is obtained from a polynomial matrix(of transfer functions) by having polynomial terms along the diagonal of the matrix, obtained through determinant divisors.
To obtain the Smith Form, I need to obtain the rank of the polynomial matrix I have. After that, I need to find the divisors, which are present along the diagonal of the matrix as stated earlier. Lets call them D_i. Among those, the first divisor, i.e. D_0 is always 1. And the rest are found by obtaining the GCDs.
So for example, if I have a 3x2 matrix, the rank of the matrix is 2. And as a result, my Smith Form looks as follows: [D_1/D_0 0; 0 D_2/D_1; 0 0]. So here, the D_0 is always 1. The D_1 is a GCD of all the terms in the polynomial matrix, which in my case comes to 1. Now comes the bit of a tricky part for me, wherein I need to find D_2. For D_2, I need to consider a 2x2 matrix from the 3x2 matrix and find its determinant. The 2x2 matrix is obtained by eliminating 1 row at a time. So I get finally 3 matrices in total, obtained by eliminating each row once. I need to find the determinants for all these 3 matrices and then the GCD of all these. The GCD value gets stored in D_2. Now, finding D_0 is more than easy, as I can manually set its value to 1. But finding the GCD for D_1 and D_2 is something for which I need help in developing the logic for the loop. I have the mathematical understanding about what I need to do. But I am unable to translate it into a code which will work for me. A couple of codes I found through the answers on MATLAB helped me to obtained only the D_1, i.e. the one with the GCD of all the polynomials. But I am unable to develop the logic for obtaining the D_2 matrix. This is where I need the help from someone, at least in developing the logic.
I would have shared here the actual matrix I have, but then I would get a readymade solution and I dont want that. I want some suggestions, or tips on which I want to write the code by my own. I hope I was clear enough now. If there is something that is still unclear, I would be glad to answer it here.

Sign in to comment.

Answers (2)

John D'Errico
John D'Errico on 12 Jul 2022
Edited: John D'Errico on 12 Jul 2022
Sadly, it is often true that people ask confusing questions, using their own terminology, jargon they have picked up that is often not standard. I'll assume that you know what a minor is for my answer, although it is entirely possible you are thinking something different.
A minor of a matrix is what remains of the matrix when you have removed one row and one column. So the minors of a rectangular matrix will also be rectangular. If the matrix was not square, then so will be the minor you have chosen.
However, you need to recognize there will be MANY such minors, depending on the size of your matrix. That is, for ANY element of the matrix, there will be a corresponding minor, since that element denotes a specific row and column. For an nxm matrix, there will be n*m minors, and each will be an (n-1)x(m-1) matrix.
One could certainly use a simple loop to create all of them. Perhaps storing them in a cell array. Or you could even store them all in the higher order planes of a 4-dimensional array. However, I fail to see a simple solution that would be better than a direct pair of nested loops to create them all. For example, your 3x2 array will have 6 minors, all of which are 2x1 arrays (actually, in this case, vectors).
A = randi(6,[3,2]) % choosing a random 3x2 matrix
A = 3×2
3 3 1 2 4 6
allminors(A)
ans =
ans(:,:,1,1) = 2 6 ans(:,:,2,1) = 3 6 ans(:,:,3,1) = 3 2 ans(:,:,1,2) = 1 4 ans(:,:,2,2) = 3 4 ans(:,:,3,2) = 3 1
The code I wrote is not inefficient at all. It preallocates the array Aminors, so even for larger problems, there will be no problem. So if A is larger, it is still reasonably fast. Loops are not always a bad thing in MATLAB, as long as you understand how to use them properly.
A = randi(9,[50,100]);
B = allminors(A);
size(B)
ans = 1×4
49 99 50 100
timeit(@() allminors(A))
ans = 0.2655
What you will do with them all is your problem. Though in the back of my mind, I still wonder if you do know what is a minor, or if you have good reasons for wanting to do this. Sorry, but when people ask basic questions like this using jargon that students often misuse, that is a distinct possibility. Perhaps you wanted to compute the determinants of the square minors. I cannot know.
function Aminors = allminors(A)
% generate all minors of a matrix
[n,m] = size(A);
Aminors = zeros(n-1,m-1,n,m);
deleteindex = @(ind,p) setdiff(1:p,ind);
for i = 1:n
for j = 1:m
Aminors(:,:,i,j) = A(deleteindex(i,n),deleteindex(j,m));
end
end
end
  3 Comments
John D'Errico
John D'Errico on 12 Jul 2022
True. But if you look at other sources, you can find where the matrix formed by deleting exactly one row and one column is also called a minor, and this was then applied to any rectangular matrix.
I'm wondering who is correct here. Just a guess in the end.
Bjorn Gustavsson
Bjorn Gustavsson on 12 Jul 2022
Yes, this guessing-game actually makes me more curious about who's closer. (We had a world-famous (on a national scale) 19th century poet that got famous for writing: "Det dunkelt sagda är det dunkelt tänkta". Our 19th century culture was rather mouldy, but that line stands the test of time.)

Sign in to comment.


Bjorn Gustavsson
Bjorn Gustavsson on 12 Jul 2022
Edited: Bjorn Gustavsson on 12 Jul 2022
As far as I understand this one definition of generating one k-minor from an arbitrary matrix of size n-by-m is to select k rows and k columns, where k is smaller than both n and m. (There will be a rather large number of minors for larger matrices). One way to calculate that is:
function Minor = Mminor(M,I1,I2)
% Minor - calculate one matrix-minor
% Calling:
% Minor = Mminor(M,I1,I2)
% Input:
% M - double matrix, [n x m]
% I1 - row-index-array, positive integer array [1 x k], or [k x 1]
% I2 - column-index-array, positive integer array [1 x k], or [k x 1]
% Output
% Minor - det(M(I1,I2)), one matrix minor.
% Example:
% I1 = [1 2 4 6];
% I2 = [2 3 4 5];
% M = randn(7,5);
% M1 = Mminor(M,I1,I2)
% det(M(I1,I2))
% The largest element in I1 has to be smaller than or equal to n, the
% largest element in I2 has to be smaller than or equal to m
%
Minor = det(M(I1,I2));
end
You will have to introduce error-checks and other stuff.
HTH
  3 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 12 Jul 2022
@John D'Errico: Well, at least one of us are not exactly correct - and that might be the best we can hope for in this situation.
Akshay Vivek Panchwagh
Akshay Vivek Panchwagh on 12 Jul 2022
Thank you for a lively discussion. I will have to implement these suggestions and check which works best for the problem I have at hand.

Sign in to comment.

Categories

Find more on Polynomials in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!