Re: Archimedes' Cattle Problem?



"Nick Cramer" <n_cramerSPAM@xxxxxxxxxxx> wrote in message news:20080926034943.227$mN@xxxxxxxxxxxxxxxxx
Does anyone know of or have a Basic program that would solve 9 simultaneous
linear equations with 8 unknowns?

If your BASIC has MAT statements, it's trivial. (PowerBASIC, Decimal BASIC and True BASIC are three that do)
In the following ! is used for REMarks

DIM A(20, 20), X(20, 1), B(20, 1), C(20, 20), D(1, 20)
LET M = 8 ! NO OF EQUATIONS (up to 20)
MAT READ A(M, M), B(M, 1) ! READ COEFFICIENT MATRIX AND CONSTANT VECTOR
LET DETER = DET(A) ! FIND THE DETERMINANT OF A. IF IT'S 0 OR VERY CLOSE
! RESULT WILL NOT BE MEANINGFUL
MAT C = INV(A)
MAT X = C * B
MAT D = TRN(X)
PRINT "THE SOLUTION IS:"
MAT PRINT X

DATA put the eight coefficients of equation one here
DATA put coefficients of equation two here
DATA put coefficients of equation three here
DATA put coefficients of equation four here
DATA put coefficients of equation five here
DATA put coefficients of equation six here
DATA put coefficients of equation seven here
DATA put coefficients of equation eight here

DATA put the eight answers here

For example: In these two equations:

4m + 3n - 7g + 5p + q - 2t +5x - 7y = 6
2m + n + 5g + p + 9q +6t - 3x+ 4y = 9

the first two data lines would be

DATA 4, 3 ,-7, 5, 1, -2, 5, -7
DATA 2, 1, 5, 1, 9, 6, -3, 4, 5

and the last data line would be

DATA 6, 9

Tom Lake

.