Basic program for simultaneous equations

This program solves n equations with n unknowns. Use "Save As" in your browser menu to capture this page. Give it some name ending in .BAS. Then you can go straight into Basic and delete these lines and some at the bottom to get a workable program.

10 REM GAUSS ELIM
20 PRINT "WRITE EQN AS 2X + 3Y + 4Z = 9"
30 PRINT "ENTER GOING ACROSS. EG. 2  3  4  9"
40 PRINT
50 PRINT "THIS ALGORITHM OCCASSIONALLY FAILS BY /0."
60 PRINT
100 DIM A(15, 16), X(15)
110 INPUT "NO. OF EQUATIONS "; N
115 PRINT "TYPE COEFF."
120 FOR I = 1 TO N
130 FOR J = 1 TO N + 1
140 INPUT A(I, J)
150 NEXT J
155 PRINT "------------------"
160 NEXT I
169 PRINT
170 GOSUB 1000
180 FOR I = 1 TO N
200 PRINT "X("; I; ") = "; X(I)
210 NEXT
220 END
1000 FOR K = 1 TO N - 1
1010 JJ = K
1020 FOR I = K + 1 TO N
1030 QT = A(I, K) / A(K, K)
1040 FOR J = K + 1 TO N + 1
1050 A(I, J) = A(I, J) - QT * A(K, J)
1060 NEXT J
1070 NEXT I
1080 FOR I = K + 1 TO N
1090 A(I, K) = 0
1100 NEXT I
1110 NEXT K
1120 X(N) = A(N, N + 1) / A(N, N)
1130 FOR NX = 1 TO N - 1
1140 SUM = 0
1150 I = N - NX
1160 FOR J = I + 1 TO N
1170 SUM = SUM + A(I, J) * X(J)
1180 NEXT J
1190 X(I) = (A(I, N + 1) - SUM) / A(I, I)
1200 NEXT NX
1210 RETURN
HTML conversion by bungah@rpi.edu, 24-Nov-97