Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: permutations
Replies: 1   Last Post: Aug 14, 2014 9:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
patrick

Posts: 14
Registered: 1/25/05
permutations
Posted: Aug 13, 2014 1:41 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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_vec-1;
siz1=factorial(len_vec)/(factorial(2)*factorial(len_vec-2));

for ii=1:len_vec_red
a=1;
for i=1:len_vec-x
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


Date Subject Author
8/13/14
Read permutations
patrick
8/14/14
Read Re: permutations
patrick

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.