80 HOME : VTAB 9: INVERSE : POKE 32,9: PRINT : PRINT " SYSTEM SOLVER "
90 PRINT " BY BILL DAVIS "
100 POKE 32,0: PRINT : NORMAL
110 VTAB 20: HTAB 10: PRINT "PRESS ANY KEY TO BEGIN": VTAB 22: PRINT "** COPYRIGHT 1985 BY MICROSPARC, INC. **": WAIT -16384,128: POKE -16368,0
120 REM
130 REM GLOSSARY OF VARIABLES
140 REM
150 REM M(M,N+1) WILL BE AN ARGUMENT MATRIX FOR A SYSTEM OF LINEAR EQUATIONS
160 REM K$ IS A QUESTION RESPONSE
170 REM B,I,J,KR,S,T,U, AND V ARE COUNTERS
180 REM L IS A CONSTANT
190 REM TEMP(N+1) WILL BE A TEMPORARY STORAGE ARRAY FOR SWITCHING EQUATIONS
200 REM M IS THE # OF ROWS OR EQUATIONS
210 REM N IS THE # OF VARIABLES IN THE EQUATIONS (N+1= # OF COLUMNS)
220 REM FLAG IS USED TO CHECK CONDITIONS
230 REM A IS THE # OF ZERO ROWS
240 REM
250 DIM M(71,72): DIM TEM(72)
260 REM
270 REM MAIN PROGRAM
280 REM
290 HOME
300 PRINT "WOULD YOU LIKE THE RESULTS PRINTED (Y OR N)?";: GET P$
310 IF P$ < >"Y" THEN 360
320 PRINT : PRINT
330 PRINT "WHAT SLOT# IS THE PRINTER IN?";: INPUT " ";SLN$
340 SLN = INT( VAL(SLN$))
350 IF SLN >6 OR SLN <1 THEN 330
360 HOME
370 PRINT "EQUATIONS MUST BY IN THE FORM A1*X1 + A2*X2 +...+ AN*XN =B"
380 PRINT
390 PRINT "HOW MANY EQUATIONS ARE THERE?"
400 INPUT "M= ";M
410 PRINT : PRINT "HOW MANY VARIABLES ARE THERE?"
420 INPUT "N= ";N
430 M = INT(M):N = INT(N)
440 IF M >70 OR N >70 THEN HOME : PRINT "THE LARGEST POSSIBLE VALUE FOR M AND N IS 70. TRY AGAIN.": FOR K = 1 TO 4000: NEXT K: HOME : GOTO 390
450 IF M < = 0 OR N < = 0 THEN HOME : PRINT "M AND N MUST BOTH BE LARGER THE ZERO. TRY AGAIN.": FOR K = 1 TO 4000: NEXT K: HOME : GOTO 390
460 PRINT
470 PRINT "INPUT THE COEFFICIENTS AND CONSTANTS BY ROW (EQUATIONS)."
480 FOR I = 1 TO M
490 PRINT
500 PRINT "INPUT THE COEFFICIENTS AND CONSTANTS FOREQUATION #";I;"."
510 FOR J = 1 TO N +1
520 INPUT M(I,J)
530 NEXT J
540 NEXT I
550 D$ = CHR$(4)
560 K$ = "N"
570 IF P$ = "Y" AND K$ = "Y" THEN PRINT : PRINT D$;"PR#"SLN: GOTO 590
580 HOME
590 PRINT "THE SYSTEM OF EQUATIONS IS:": PRINT
600 FOR U = 1 TO M
610 IF P$ = "Y" AND K$ = "Y" THEN 640
620 CV = PEEK(37): REM PEEK(37) IS THE VALUE OF THE CURSOR'S CURRENT VERTICAL POSITION
630 IF CV >20 THEN GOSUB 2120
640 PRINT "EQU. #";U
650 PRINT
660 FOR V = 1 TO N +1
670 IF P$ = "Y" AND K$ = "Y" THEN 700
680 CV = PEEK(37)
690 IF CV >20 THEN GOSUB 2120
700 IF V = N +1 THEN PRINT " =";M(U,N +1)
710 IF V = 1 THEN PRINT M(U,V);"*X1";
720 IF V >1 AND V < >N +1 THEN PRINT "+";M(U,V);"*X";V;
730 NEXT V
740 PRINT
750 NEXT U
760 IF P$ = "Y" AND K$ = "Y" THEN PRINT : PRINT D$;"PR#0"
770 IF K$ = "Y" THEN 870
780 PRINT "ARE THESE THE CORRECT EQUATIONS (Y OR N)? ";: GET K$: IF K$ = "Y" AND P$ = "Y" THEN GOTO 570
790 IF K$ = "Y" THEN 870
800 PRINT
810 PRINT : PRINT "WHICH ENTRY IS INCORRECT? INPUT (EQU. # AND VAR. #).";: INPUT "";U,V
820 IF U >M OR V >N +1 OR U <1 OR V <1 THEN PRINT "TRY AGAIN.": FOR T = 1 TO 4000: NEXT T: GOTO 580
830 PRINT
840 PRINT "M(";U;",";V;") IS CURRENTLY ";M(U,V)
850 PRINT
860 PRINT "WHAT IS THE CORRECT VALUE FOR M(";U;","V;")?";: INPUT " ";M(U,V): GOTO 580
870 HOME : PRINT " COMPUTING....":A = 0
880 GOSUB 1570
890 I = 0:J = 0
900 I = I +1
910 J = J +1
920 GOSUB 1850
930 IF FLAG = 0 THEN I = I -1: GOTO 1070
940 L = M(I,J)
950 FOR S = 1 TO N +1
960 M(I,S) = M(I,S)/L
970 NEXT S
980 FOR R = 1 TO M
990 IF R = I OR M(R,J) = 0 THEN 1060
1000 FOR S = 1 TO N +1
1010 TEMP(S) = M(R,S) -M(R,J) *M(I,S)
1020 NEXT S
1030 FOR V = 1 TO N +1
1040 M(R,V) = TEMP(V)
1050 NEXT V
1060 NEXT R
1070 IF M > = I +1 AND N > = J +1 THEN 900
1080 A = 0
1090 GOSUB 1570
1100 HOME
1110 PRINT "THE ARGUMENT MATRIX IN ROW ECHELON FORM IS:": PRINT
1120 GOSUB 2010
1130 IF P$ = "Y" THEN PRINT : PRINT D$;"PR#"SLN
1140 IF M -A < >N THEN 1240
1150 PRINT "THE SOLUTION TO THE SYSTEM OF EQUATIONS IS:"
1160 FOR T = 1 TO N
1170 IF P$ = "Y" THEN 1200
1180 CV = PEEK(37)
1190 IF CV >20 THEN GOSUB 2120
1200 PRINT
1210 PRINT "X";T;"= ";M(T,N +1)/M(T,T)
1220 NEXT T
1230 GOTO 1500
1240 PRINT "THE SOLUTION OF THE SYSTEM OF EQUATIONS IS:"
1250 PRINT
1260 B = 0
1270 FOR T = 1 TO N
1280 IF P$ = "Y" THEN 1310
1290 CV = PEEK(37)
1300 IF CV >20 THEN GOSUB 2120
1310 B = B +1
1320 IF B >N THEN 1500
1330 IF M(T,B) = 0 THEN 1420
1340 PRINT "X";B;"= ";M(T,N +1)/M(T,B);
1350 FOR S = B +1 TO N
1360 IF P$ = "Y" THEN 1390
1370 CV = PEEK(37)
1380 IF CV >20 THEN GOSUB 2120
1390 IF S >N THEN 1500
1400 PRINT " -";M(T,S)/M(T,B);"*X";S;
1410 GOTO 1460
1420 IF B >N THEN 1500
1430 PRINT "X";B;"= X";B
1440 T = T -1
1450 GOTO 1480
1460 NEXT S
1470 PRINT
1480 PRINT
1490 NEXT T
1500 IF P$ = "Y" THEN PRINT : PRINT D$;"PR#0"
1510 IF P$ < >"Y" THEN PRINT : PRINT : PRINT "WOULD YOU LIKE THE ANSWER DISPLAYED AGAIN (Y OR N)? ";: GET K$: IF K$ = "Y" THEN 1100
1520 PRINT : PRINT : PRINT "WOULD YOU LIKE TO SOLVE ANOTHER SYSTEM OF EQUATIONS (Y OR N)? ";: GET K$: IF K$ = "Y" THEN CLEAR : GOTO 250
1530 END
1540 REM
1550 REM **** END OF MAIN PROGRAM
1560 REM
1570 REM ZERO ROW CHECKING SUBROUTINE
1580 REM
1590 FOR I = 1 TO M
1600 FLAG = 0
1610 FOR J = 1 TO N +1
1620 IF M(I,J) < >0 AND FLAG = 0 THEN FLAG = 1
1630 NEXT J
1640 IF FLAG = 1 THEN 1710
1650 FOR S = 1 TO N +1
1660 TEMP(S) = M(M -A,S)
1670 M(M -A,S) = 0
1680 M(I,S) = TEMP(S)
1690 NEXT S
1700 A = A +1
1710 NEXT I
1720 REM
1730 REM OVER-DETERMINED SYSTEM SUBROUTINE
1740 REM
1750 FOR I = 1 TO M
1760 FLAG = 0
1770 FOR J = 1 TO N
1780 IF M(I,J) < >0 AND FLAG = 0 THEN FLAG = 1
1790 NEXT J
1800 IF FLAG = 0 AND M(I,N +1) < >0 AND P$ = "Y" THEN PRINT : PRINT D$;"PR#"SLN: PRINT : PRINT "THIS SYSTEM OF EQUATIONS IS OVER-DETERMINED.": PRINT : PRINT D$;"PR#0": GOTO 1520
1810 IF FLAG = 0 AND M(I,N +1) < >0 THEN PRINT : PRINT "THIS SYSTEM OF EQUATIONS IS OVER- DETERMINED.": GOTO 1520
1820 NEXT I
1830 RETURN
1840 REM
1850 REM EQUATIONS SWITCHING SUBROUTINE
1860 REM
1870 IF M(I,J) < >0 THEN 1950
1880 FOR T = I +1 TO M
1890 IF M(T,J) = 0 THEN 1970
1900 FOR R = 1 TO N +1
1910 TEMP(R) = M(I,R)
1920 M(I,R) = M(T,R)
1930 M(T,R) = TEMP(R)
1940 NEXT R
1950 FLAG = 1
1960 GOTO 1990
1970 FLAG = 0
1980 NEXT T
1990 RETURN
2000 REM
2010 REM ARGUMENT MATRIX PRINTING SUBROUTINE
2020 REM
2030 FOR U = 1 TO M
2040 FOR V = 1 TO N +1
2050 CV = PEEK(37)
2060 IF CV >20 THEN GOSUB 2120
2070 PRINT M(U,V),
2080 NEXT V
2090 PRINT
2100 PRINT
2110 NEXT U
2120 PRINT "PRESS ANY KEY TO CONTINUE. ";: GET K$: HOME