矩阵/向量的线性组合

0x0*_*0x0 5 matlab matrix

B是[1x8]矩阵,也可以认为是两半如下:

B = -1 -1 0 0   0 0 1 1
Run Code Online (Sandbox Code Playgroud)

这里-1上半场可以有一个,两个,三个或四个,下半场应该有相同数量的1.它应该以线性组合完成.

例如,如果-1上半场有两个,那么它们可以被放置4 choose 2 = 6,并且对于每一个,将有6种方式将两个放置在1下半场.因此系统总共有6*6 = 36种方式.即如果-1上半场有两个,那么B的36个不同的值.

我怎样才能做到这一点?

Jon*_*nas 5

你可以先生成1和0的所有可能的排列,然后扔掉多余的排列.

%# make permutations using dec2bin (start from 17 since it's the first solution)
allB = str2double(num2cell(dec2bin(17:255)));

%# change sign in the first half, then check that the total is ok
allB(:,1:4) = - allB(:,1:4);
allB = allB(sum(allB,2)==0,:);
Run Code Online (Sandbox Code Playgroud)

每一行allB都是可能的值B