How to find every minor determinant of a matrix?

13 Ansichten (letzte 30 Tage)
guy sharon
guy sharon am 23 Apr. 2018
Kommentiert: Alireza Esmaily am 3 Apr. 2019
Hello!
I am searching for a convenient way to calculate every minor determinant of a matrix. For example, given the matrix
2.8722 1.7788 0.2750 0.3751 1.5872
0.9906 1.9001 0.5389 0.1804 0.3458
0.3924 1.2647 2.1009 0.9696 0.3883
0.4222 0.2286 0.3922 2.0427 1.3831
1.5836 0.5931 0.1603 1.1563 3.2576
I want to calculate the determinand of every 2x2, 3x3 and 4x4 minor (5x5 is trivial). For this matrix the 3x3 will be, for example
2.8722 1.7788 0.2750
0.9906 1.9001 0.5389
0.3924 1.2647 2.1009
2.8722 1.7788 0.3751
0.9906 1.9001 0.1804
0.3924 1.2647 0.9696
2.8722 1.7788 1.5872
0.9906 1.9001 0.3458
0.3924 1.2647 0.3883
And so on...
Is there any quick way you can think about?
Many thanks!

Antworten (2)

guy sharon
guy sharon am 23 Apr. 2018
I worked something out. Here is my take on this:
function [det_mat] = detMat(m)
len = length(m);
det_mat{1} = m;
det_mat{len} = det(m);
for order = 2 : len - 1
perms = nchoosek(1:len,order);
for i = 1 : length(perms)
for j = 1 : length(perms)
det_mat{order}(i,j) = det(m(perms(i,1:end),perms(j,1:end)));
end
end
end

Andrew Warr
Andrew Warr am 19 Nov. 2018
Bearbeitet: Andrew Warr am 19 Nov. 2018
Working from Guy Sharon's code start above, I've fixed the errors of Minor placement and matrices larger that 3 x 3 failing on the zero indexes.
I've tested it on matrices up to 5 x 5 and back checked against inv(Original)
This may be useful for a student checking their adjunct method working of a test writer wanting to test their marking guide.
function [det_mat] = detMat(m)
[nr, nc] = size (m);
if (nr == nc)
len = length(m);
det_mat{1} = m; %% Input matrix in first place
det_mat{5} = det(m); %% Determinant in fourth place
for order = len - 1 : len - 1
perms = nchoosek(1:len,order); % Map to skip rows and columns
for i = 1 : length(perms)
for j = 1 : length(perms)
%% The Minors
det_mat{2}(len+1-i,len+1-j) = det(m(perms(i,1:end),perms(j,1:end)));
%% The Masked Minors
if (mod(abs(i-j),2) == 1)
det_mat{3}(len+1-i,len+1-j) = -1 * (det_mat{2}(len+1-i,len+1-j));
else
det_mat{3}(len+1-i,len+1-j) = det_mat{2}(len+1-i,len+1-j);
endif
temp_mat(len+1-i,len+1-j) = det_mat{3}(len+1-i,len+1-j);
end
end
end
%% Make Adjunct by Transpose off-diagonal elements %% Yes, you can use adjoint(A)
for j = 1 : length(perms)
for i = 1 : length(perms)
det_mat{4}(i,j) = temp_mat(j,i);
end
end
%% The final Inverse Yes,you can use inv(m)
det_mat{6} = 1/det_mat{5}*det_mat{4};
det_mat{7} = [' 1)Your matrix ' ' 2)Minors ' ' 3)Masked ' ' 4)Adjunct ' ' 5)Determinant ' ' 6)Inverse'];
elseif ((nr =! nc)) %% double bracket suppresses warning????
disp("Error: Not a square matrix")
endif
  1 Kommentar
Alireza Esmaily
Alireza Esmaily am 3 Apr. 2019
Hi dear Andrew warr
but there is a problem in this code
perms code has a imitation on length of matrices.
MATLAB Help:
perms(v) is practical when length(v) is less than about 10.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by