Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.1K Views
|
1 Reply
|
1 Total Like
View groups...
Share
Share this post:

Tuples that sum to 1 (for large n)

Posted 11 years ago

Hi! I am trying to find all the possible weights that sum to one:

weights = Table[0.05*i,{i,0,20}] (* list of weights *)
n= 2
alltuples =Tuples[weights,n]; (*generate all tuples *)
Length[alltuples] (* number of tuples there are *)
Select[alltuples, Plus@@#==1&] (*list of all the tuples that sum to one *)

So this works and I get all the permutations that add to 1. However I want this done with n = 9 and n=10. This is not possible as it crashes (due to memory issues). You can try setting n=9 and the code won't work.

Is there a more elegant way to approach this problem? I guess I am using a brute force method which is not appropriate given the size of the problem.

Thanks! Priyan.

POSTED BY: Priyan Fernando
Posted 11 years ago
POSTED BY: tad
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard