Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: integer solutions for x_1+x_2+...+x_n = k
Date: Thu, 6 Nov 2008 15:14:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <gev1jq$51m$1@fred.mathworks.com>
References: <geku21$eku$1@fred.mathworks.com> <gel0b6$3li$1@fred.mathworks.com> <geqe85$chp$1@fred.mathworks.com> <geqgdi$crb$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1225984442 5174 172.30.248.37 (6 Nov 2008 15:14:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 6 Nov 2008 15:14:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1582760
Xref: news.mathworks.com comp.soft-sys.matlab:499316

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <geqgdi$crb$1@fred.mathworks.com>...
> 
> Oh there is nothing very mysterious about it
> 
> Assume we want to look for the all combinations of (1) 
> x1 + x2 + ... + xn = k (eqt1)
> 
> Then what are the possible values for x1 ? Answer: It can take any value from 0, 1, 2, ... to k.
> 
> Now pick a fix value j for x1 : x1 = j. 
> 
> For (eqt1) to be true; we need the rest to verifies:
> 
> x2 + x3 + .... + xn = k-j (eqt2)
> 
> (eqt2) is the same type as (eqt1) with one less variable. That gives the recursive relation,  and it can goes down to the case with a single variable: the very last recursion reduces to
> xn = somevalue. (eqt3)
> The solution of that is  trivial.
> 
> When you look at the engine "allVL1eq", you will see the first test "if n==1" treats (eqt3).
> 
> The second "else" branch loops over j=1... k and calls recursively to solve (eqt2), then add the head column "j" in front of the array of solutions ("if nargin>=3"). Finally all the array are concatenated using cell2mat(...).
> 
> Bruno

Thank you Bruno, elegant explaination,  I got it now. 
/Oriole