正方行列の掛け算

 投稿者:しばっち  投稿日:2017年 2月26日(日)16時04分21秒
  正方行列の掛け算を求めます

LET NN=5
LET MM=3
DIM A$(MM,NN,NN),X$(NN,NN)
LET S$="abcdefghijklmnopqrstuvwxyz"
FOR M=1 TO MM
   FOR I=1 TO NN
      FOR J=1 TO NN
         LET A$(M,I,J)=S$(M:M)&STR$(I)&STR$(J)
      NEXT J
   NEXT I
NEXT M
FOR I=2 TO NN
   FOR P=2 TO MM
      CALL MATRIX(P+1,I,A$,X$)
      FOR J=1 TO I
         FOR M=1 TO P
            PRINT "(";
            FOR K=1 TO I-1
               PRINT A$(M,J,K);" ";
            NEXT K
            PRINT A$(M,J,I);")";
         NEXT  M
         PRINT
      NEXT   J
      PRINT "="
      CALL DISPLAY(I,X$)
   NEXT P
NEXT I
END

EXTERNAL  SUB MATRIX(M,N,A$(,,),X$(,))
DIM A(0 TO M)
MAT A=CON
DO
   LET K=M
   LET SS$=SS$&"+"&A$(1,A(1),A(3))
   FOR J=2 TO M-2
      LET SS$=SS$&"*"&A$(J,A(J+1),A(J+2))
   NEXT J
   LET SS$=SS$&"*"&A$(M-1,A(M),A(2))
   LET FL=0
   FOR J=3 TO M
      IF A(J)<>N THEN LET FL=1
   NEXT J
   IF FL=0 THEN
      LET SS$(1:1)=""
      LET X$(A(1),A(2))=SS$
      LET SS$=""
   END IF
   DO WHILE A(K)=N
      LET A(K)=1
      LET K=K-1
   LOOP
   LET A(K)=A(K)+1
LOOP UNTIL K=0
END SUB

EXTERNAL  SUB DISPLAY(N,P$(,))
FOR I=1 TO N
   PRINT "(";
   FOR J=1 TO N-1
      PRINT P$(I,J);"   ";
   NEXT J
   PRINT P$(I,N);")"
NEXT I
PRINT
END SUB
 

戻る