-
Notifications
You must be signed in to change notification settings - Fork 29
/
CompoundMatrix.m
34 lines (32 loc) · 934 Bytes
/
CompoundMatrix.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%% COMPOUNDMATRIX Computes the rth compound matrix of a given matrix
% This function has two required arguments:
% A: an arbitrary matrix
% r: a nonnegative integer
%
% comp = CompoundMatrix(A, r) returns the rth compound matrix of A
%
% If r > min{m, n}, then the rth compound matrix of A is the 0x0 matrix.
% Otherwise, the size of the result is (m choose r) x (n choose r).
%
% URL: https://qetlab.com/CompoundMatrix
%
% author: Benjamin Talbot
% package: QETLAB
% last updated: August 8, 2024
function comp = CompoundMatrix(A, r)
m = size(A, 1);
n = size(A, 2);
if r > min(m, n)
comp = [];
return
end
rows = nchoosek(1:m, r);
cols = nchoosek(1:n, r);
dims = [size(rows, 1), size(cols, 1)];
comp = zeros(dims);
for i = 1:dims(1)
for j = 1:dims(2)
comp(i, j) = det(A(rows(i, :), cols(j, :)));
end
end
end