Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news1.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!newsfe01.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.17 (Windows/20080914)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: integer solutions for x_1+x_2+...+x_n = k
References: <geku21$eku$1@fred.mathworks.com> <Y6nPk.38885$OT2.684@newsfe01.iad>
In-Reply-To: <Y6nPk.38885$OT2.684@newsfe01.iad>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 26
Message-ID: <j7qPk.5277$cx5.1250@newsfe01.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe01.iad 1225666127 24.79.146.116 (Sun, 02 Nov 2008 22:48:47 UTC)
NNTP-Posting-Date: Sun, 02 Nov 2008 22:48:47 UTC
Date: Sun, 02 Nov 2008 16:49:00 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:498561


Walter Roberson wrote:
> Oriole wrote:

>> I need to write a function for solving

>> x_1+x_2+x_3+ ...+x_n = k

>> where n and k are inputs, k is some small positive integer, for 
>> example, k= 3, or k= 6,
>>  n is rather large positve integer, for example,, n = 20, or n= 60.

>> The unknowns x_1, x_2, ...x_n are non-negative integers.

> Ian posted complete code in

By the way, you only have to compute the solutions for at most k positive (non-zero)
integers with the remaining x_n all zero; the other solutions are merely
permutations of these. Indeed, you could narrow it further to descending
positive integers x_1 >= x_2 >= x_3 and so on; the remainder of the solutions
would be permutation of these.

-- 
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?