You are in trouble for a variety of reasons.
This is a variation of a classical partitions problem, usually described in terms of integers that sum to a given value. Usually, the problem is in terms of a sum of the integers 1:n.
That the problem is phrased as a mean is not really relevant. We can just look at it as the sum of Q elements from these sets such that they sum to Q*W.
As Q increases, the number of such solutions, increases pretty rapidly. Computing them all will take much time.
Next, the sum of any set of floating point numbers will never be exactly any value. You need to allow a tolerance. Of course, that makes the problem more difficult yet.
How should you solve it? Recursion is the simple solution. Here a loop will suffice. Your target sum must live in the interval
To generate all possible possible combinations that yield the desired sum, just set up a loop. Consider all elements from the CELL array A{1}.
Note that I will not allow you to phrase this in terms of vectors A_1, A_2, etc. Sorry, but that is a foolish thing to do. Use a cell array to contain ALL of your vectors in one array.
If any of those elements are less than Q*W+tol, then they are potential elements of one valid partition. Then consider which elements of A{2} might fall in the sum.
All of these potential combinations will grow rapidly. While computable, it will take time.
Is there a better way? Perhaps.
0 Comments
Sign in to comment.