       Re: Simple n-tuple problem - with no simple solution

• To: mathgroup at smc.vnet.net
• Subject: [mg115805] Re: Simple n-tuple problem - with no simple solution
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Fri, 21 Jan 2011 04:31:52 -0500 (EST)

```This may do the trick.

Clear[m]
n = 10;
sum = Total@multipliers;
nonNegative = And @@ Thread[multipliers >= 0];
soln = Sort[
multipliers /.
Solve[{multipliers.addends == 1, nonNegative, sum == n},
multipliers, Integers]];
Length@soln
Total /@ soln // Union

530

{1}

{10}

When 0 is one of the addends, you can also write:

Clear[m]
n = 10;
addends = DeleteCases[Rationalize@Range[0, 1, .05], 0];
sum = Total@multipliers;
nonNegative = And @@ Thread[multipliers >= 0];
soln = Sort[
multipliers /.
Solve[{multipliers.addends == 1, nonNegative, sum <= n},
multipliers, Integers]];
Length@soln
Total /@ soln // Union

530

{1}

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

You may also want to look at IntegerPartitions and FrobeniusSolve.

Bobby

On Thu, 20 Jan 2011 05:33:21 -0600, Don <donabc at comcast.net> wrote:

> Problem: Given an n-tuple  (n >= 1). with each element  able to take
> on the values in
> Range[0, 1.0, .05] , produce all the n-tuples that sum to 1.0.
>
> The most direct way to solve this problem is to generaate all possible
> n-tuples and Select out all those that sum to 1.0.
>
> For example, when n = 2 :
>
> n = 2;
> Select[Tuples[Table[Range[0, 1.0, .05], {n}]], Total[#] == 1 &]
>
> The problem with this solution is that the number of n-tuples that are
> generated before the Select is used grows exponentially fast as a
> function
> of n - causing the system to run out of memory (RAM) very quickly.
>
> Is there a more memory efficient way to solve this problem that
> doesn't
> use so much memory but still is not too slow in terms of processor
> time?
>
> Thank you.
>

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: Style Question: The Functional Way
• Next by Date: Re: Style Question: The Functional Way
• Previous by thread: Re: Simple n-tuple problem - with no simple solution
• Next by thread: Re: Simple n-tuple problem - with no simple solution