矩阵/向量的线性组合 [英] Linear combination of a matrix/vector
问题描述
B是[1x8]矩阵,也可以看作是两半,如下所示:
B is a [1x8] matrix which can also be considered as two halves as follows:
B = -1 -1 0 0 0 0 1 1
在上半部可以有一个,两个,三个或四个-1
,在下半部应有相等数量的1
.应该线性组合完成.
Here there can be either one, two, three or four -1
's in the first half, and there should be equal number of 1
's in the second half. It should be done in linear combinations.
例如,如果上半部有两个-1
,则可以将它们放置为4 choose 2 = 6
方式,对于每种方式,将有6种方式将两个1
放置在其中下半场.因此,系统共有6 * 6 = 36路.即,如果上半部有两个-1
,则B的36个不同值.
For example, if there are two -1
's in the first half, they can be placed in 4 choose 2 = 6
ways, and for each of them there will be 6 ways to place the two 1
's in the second half. So the system has a total of 6*6 = 36 ways. i.e. 36 different values for B's if there are two -1
's in the first half.
我该怎么做?
推荐答案
您可以首先生成所有可能的1和0排列,然后丢弃多余的1.
You can first generate all possible permutations of ones and zeros, and then throw away the superfluous ones.
%# 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,:);
allB
的每一行都是B
这篇关于矩阵/向量的线性组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!