Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.fr>
Newsgroups: comp.soft-sys.matlab
Subject: Re: linear equation with restrictions
Date: Sat, 19 Jul 2008 11:34:02 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 45
Message-ID: <g5sjfa$fbg$1@fred.mathworks.com>
References: <g5sgla$b7r$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.fr>
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 1216467242 15728 172.30.248.37 (19 Jul 2008 11:34:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 19 Jul 2008 11:34:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:480434


"Leon galushko" <leonid.galushko@rwth-aachen.de> wrote in
message <g5sgla$b7r$1@fred.mathworks.com>...
> Hi,
> i would carry out the following equation
> (figures are as examples):
> 
> A1 * c1 + A2 * c2 = b
> A = [2.30 4.56]
> b = 57.4

OK, in order to avoid work with float, I'll transform your
fisrt equation by multiplying it by 100

Ax100_1 * c1 + Ax100_2 * c2 = bx100  (eqt 1)

Ax100 = [230 456]
bx100 = 5740

Now search for greater common divisor of Ax1000 by MATLAB
function GCD:

[g D1 D2]=gcd(Ax100(1),Ax100(2))
% it is gcd(230,456) % g ==2, D1=-113, D2=57

Which mean
All the numbers generated by the lhs of (eqt 1) is 
+ multiple of 2 (=g), and furthermore
+ g = 2 = -113*230  + 57*456 = 
          -113*Ax100(1)  + 47*Ax100(2) (eqt 2).

Now all you need is to see whereas bx100 is divisible by g.

if mod(bx100 ,g)==0 % yes
  C1 = D1 * bx100/g % -324310
  C2 = D2 * bx100/g % +163590
else
  error('No integer solution exists') 
end

Verification:

C1*2.30+C2*4.56 % 57.4000

Bruno