4

I am looking to find all possible linear combinations of a set of matrices over GF(2). I know the number of matrices, k, and they are all the same dimension, stored in a 3D array, C(:,:,i) for the ith matrix. Because I'm working over GF(2), all the coefficients of the linear combination must be in {0,1}. I would like to generate each of the 2^k possible sums so that I may test the resulting matrix for a required property. There are many posts about generating all combinations of elements of matrices or vectors, but I am looking to generate all linear combinations of the matrices as a whole.

Many Thanks!

Amro
  • 123,847
  • 25
  • 243
  • 454
user1371024
  • 41
  • 1
  • 2

1 Answers1

2

Here is an example:

%# some data to work with
sz = [4 3];
k = 6;
C = rand([sz k]);

%# coefficients [0,0,0,0,0,0] to [1,1,1,1,1,1]
p = (dec2bin(0:2^k-1) == '1');

%# generate all linear combinations with the above coefficients
for i=1:size(p,1)
    %# C(:,:,1)*p(i,1) + C(:,:,2)*p(i,2) + ... + C(:,:,k)*p(i,k)
    linComb = sum(bsxfun(@times, permute(p(i,:),[1 3 2]), C),3);

    %# do something interesting with it ...
end
Amro
  • 123,847
  • 25
  • 243
  • 454