Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: integer solutions for x_1+x_2+...+x_n = k Date: Sun, 2 Nov 2008 19:12:01 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 25 Message-ID: <geku21$eku$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1225653121 15006 172.30.248.35 (2 Nov 2008 19:12:01 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 2 Nov 2008 19:12:01 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1582760 Xref: news.mathworks.com comp.soft-sys.matlab:498534 Help.. please.. 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. I wrote a complicated loop to list out lexicographically all (x_1, x_2, ..., x_n) such that x_1+x_2+x_3+ ...+x_n <= k, then select out the ones that satisfy the desired equality. It works well when n is small, like n= 20, but when n is bigger, it does not work out at all, Matlab is busy for many many hours without giving any result... Are there any smarter ways to do it? Thank you!!