Program to solve the Problem of the Week

for the week of April 16, 2001
by Keith Mealy


I use a programming language called MANTIS, which
happens to be a product that I've worked on for a
number of years.  For programs that don't involve a
lot of terminal or file i/o, it resembles BASIC.


 00010 |GAUSS ELIMINATION FOR SIMULTANEOUS LINEAR EQUATIONS
 00011 | GIVEN SQUARE MATRIX A AND VECTOR B, DETERMINE X IN AX=B
 00020 DO OBTAIN_EQUATIONS
 00040 FOR I=1 TO N-1
 00050 .DO PIVOT
 00060 .DO ELIMINATE
 00070 END
 00080 DO SOLUTION
 00090 STOP
 00100 |------------------------------
 00110 ENTRY OBTAIN_EQUATIONS
 00111 .BIG A(5,6):N=5:N1=N+1
 00112 .A(1,1)=2,0,1,1,2,260
 00113 .A(2,1)=1,1,2,2,1,340
 00114 .A(3,1)=1,1,3,0,0,255
 00115 .A(4,1)=2,1,1,4,0,435
 00116 .A(5,1)=1,0,1,1,3,225
 00230 EXIT
 00240 |------------------------------
 00250 ENTRY PIVOT
 00260 .|PERFORM PARTIAL PIVOTING
 00270 .MAX=ABS(A(I,I)):|FIND LARGEST COEF. TO PIVOT ON
 00280 .L=I
 00290 .FOR M=I+1 TO N
 00300 ..IF ABS(A(M,I))>MAX
 00310 ...MAX=ABS(A(M,I))
 00320 ...L=M
 00330 ..END
 00340 .END
 00350 .IF MAX=0
 00360 ..SHOW"NO SOLUTION":WAIT:STOP
 00361 .ELSE
 00362 ..DO SWAP(I,L)
 00370 .END
 00380 EXIT
 00390 |------------------------------
 00400 DO SWAP(I,L)
 00410 ENTRY SWAP(I,L)
 00420 .IF I<>L
 00430 ..FOR SWAPI=I TO N1
 00440 ...TEMP=A(I,SWAPI)
 00450 ...A(I,SWAPI)=A(L,SWAPI)
 00460 ...A(L,SWAPI)=TEMP
 00470 ..END
 00480 .END
 00490 EXIT
 00500 |------------------------------
 00510 ENTRY ELIMINATE
 00520 .FOR K=I+1 TO N
 00530 ..MULTIPLIER=-A(K,I)/A(I,I)
 00540 ..FOR J=I+1 TO N1
 00550 ...A(K,J)=A(K,J)+MULTIPLIER*A(I,J)
 00560 ..END
 00570 .END
 00580 EXIT
 00590 |------------------------------
 00600 ENTRY SOLUTION
 00610 .BIG X(N)
 00620 .FOR I=N TO 1 BY-1
 00630 ..BACKSOL=A(I,N1)
 00640 ..FOR K=I+1 TO N
 00650 ...BACKSOL=BACKSOL-A(I,K)*X(K)
 00660 ..END
 00670 ..X(I)=BACKSOL/A(I,I)
 00680 ..SHOW I;"IS";X(I)
 00690 .END
 00700 .WAIT
 00710 EXIT