Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Integer solutions for a_1*x_1+a_2*x_2+a_3*x_3+ ...+a_4*x_n = k
Date: Thu, 20 Nov 2008 20:32:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 40
Message-ID: <gg4hg1$cko$1@fred.mathworks.com>
References: <gfun9a$41t$1@fred.mathworks.com> <gg4h8i$99q$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
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 1227213121 12952 172.30.248.35 (20 Nov 2008 20:32:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Nov 2008 20:32:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:502129


% Test program:

% This example would take more or less a minute to solve
a=[770 105 60 85 50];

b = 9435;

%
% solving
% c1*a1 + ... cn*an = b
% c >=0

c = intlin(a, b);

if isnan(c)    
elseif ~isempty(c)

    fprintf('\nSolutions c:\n\n');
    disp(c);
    fprintf('\nNumber of solutions = %d\n\n', size(c,1));
    
    if exist('cc','var') && ~ismember(cc,c,'rows')
        fprintf('Solver miss the initial solution\n');
        %save test_inlin_debug.mat a cc b
    end
   
    bverif = c*a';
    bverifu = unique(bverif);
    
    if length(bverifu)~=1 || bverifu~=b
        fprintf('Wrong solution(s)\n');
        disp(c(bverif~=b,:));
        %save test_inlin_debug.mat a cc b
    end
    
else % mode(b,g)==0
    fprintf('There is no solution\n');
end

% Bruno