10 PRINT "MATRIX INVERSION"
20 PRINT
29 REM - A() AND B() SHOULD BOTH BE SET TO THE DIMENSIONS OF THE MATRIX
30 DIM A(10,10), B(10,10)
39 REM - MATRIX IS SQUARE SO ONLY ONE DIMENSION IS NEEDED
40 PRINT "DIMENSION OF MATRIX";
50 INPUT R
60 PRINT "MATRIX ELEMENTS:"
69 REM - ENTER MATRIX ELEMENTS
70 FOR J=1 TO R
80 PRINT "ROW";J
90 FOR I=1 TO R
100 PRINT "VALUE COLUMN";I;
110 INPUT A(J,I)
120 NEXT I
130 B(J,J)=1
140 NEXT J
149 REM - STATEMENTS 150 TO 420 INVERT MATRIX
150 FOR J=1 TO R
160 FOR I=J TO R
170 IF A(I,J)<>0 THEN 210
180 NEXT I
190 PRINT "SINGULAR MATRIX"
200 GOTO 500
210 FOR K=1 TO R
220 S=A(J,K)
230 A(J,K)=A(I,K)
240 A(I,K)=S
250 S=B(J,K)
260 B(J,K)=B(I,K)
270 B(I,K)=S
280 NEXT K
290 T=1/A(J,J)
300 FOR K=1 TO R
310 A(J,K)=T*A(J,K)
320 B(J,K)=T*B(J,K)
330 NEXT K
340 FOR L=1 TO R
350 IF L=J THEN 410
360 T=-A(L,J)
370 FOR K=1 TO R
380 A(L,K)=A(L,K)+T*A(J,K)
390 B(L,K)=B(L,K)+T*B(J,K)
400 NEXT K
410 NEXT L
420 NEXT J
430 PRINT
439 REM - PRINT RESULTANT MATRIX
440 FOR I=1 TO R
450 FOR J=1 TO R
459 REM - ROUND OFF, PRINT
460 PRINT INT(B(I,J)*1000+.5)/1000;" ";
470 NEXT J
479 REM - ADVANCE OUTPUT DEVICE TO PRINT NEXT LINE
480 PRINT
490 NEXT I
500 END
