Mankan,
I have done this (3 equ and 3 unkns) with brute force using Cramer's rule (which is "plug and chug" systematic). However, because we are working with integers, have variable size limits, and no easy way to track negative signs, you need to be careful not to "lose" your answer or get the wrong answer. Beyond Cramer's, you can search online for some form of "Gauss Elimination" for bucket loads of information on numerically solving simultaneous equations.
A quick 2eq and 2unkns example follows using Cramer's Method
Solve:
5x+3y=13
x+y=3
(answer: x = 2, y = 1)
Code:
'declare variables accrodingly - I did not
x1=5
y1=3
a1=13
x2=1
y2=1
a2=3
D = (x1*y2)-(x2*y1)
x = ((a1*y2)-(a2*y1))/D 'x=2 yeah!
y = ((x1*a2)-(x2*a1))/D 'y=1 yeah!
However, negatives and fractions must be dealt with or you will get a surprise answer and not the correct answer - this example had none. (3 equ and 3 unkns is similar but with lots more terms, which would means lots more checking for negative signs.)
Good and lots lots lots of Luck,
Paul Borgmeier
Salt Lake City, UT
USA
__________________
Bookmarks