Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


patrick
Posts:
14
Registered:
1/25/05


permutations
Posted:
Aug 13, 2014 1:41 PM


I wrote a function which gives you all possibles sums of the entities of a vector. This is done for two summands only. However, I would need to do this for 3, 4, 5, n summands of a vector. Maybe it is possible to change the code (below!) accordingly???
Any help on that is highly appreciated!
A minimal example for 2 summands is given here:
A=rand(20,1) function [val1]=sum_perm_poss(A)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [val1]=sum_perm_poss(vector) %
%% vector(vector==0)=[NaN]; x=1;
len_vec=numel(vector); len_vec_red=len_vec1; siz1=factorial(len_vec)/(factorial(2)*factorial(len_vec2));
for ii=1:len_vec_red a=1; for i=1:len_vecx sum_permi(i,ii)=vector(i,1)+vector(i+x,1); val2(i,ii)=a; val3(i,ii)=x; a=a+1; end
x=x+1;
end
val1(:,1)=sum_permi(:); val1(:,2)=val2(:); val1(:,3)=val3(:); val1(val1(:,1:3)==0)=[]; val1=reshape(val1,[siz1,3]);
return



