行列の掛け算

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

LET MM=3
DIM N(0 TO MM+1)
FOR I=1 TO MM+1
   READ N(I)     !'N(1)行N(2)列 , N(2)行N(3)列 , N(3)行N(4)列 , N(4)行N(5)列...
NEXT I
DATA 2,3,4,5,6,7
DIM A$(MM,MAX1(N),MAX2(N)),X$(N(1),N(MM+1))
LET S$="abcdefghijklmnopqrstuvwxyz"
FOR M=1 TO MM
   FOR I=1 TO N(M)
      FOR J=1 TO N(M+1)
         LET A$(M,I,J)=S$(M:M)&STR$(I)&STR$(J)
      NEXT J
   NEXT I
NEXT M
CALL MATRIX(MM+1,N,A$,X$)
FOR J=1 TO MAX1(N)
   FOR M=1 TO MM
      IF J<=N(M) THEN
         PRINT "(";
         FOR K=1 TO N(M+1)-1
            PRINT A$(M,J,K);" ";
         NEXT K
         PRINT A$(M,J,N(M+1));")";
      ELSE
         FOR K=1 TO N(M+1)
            PRINT "    ";
         NEXT K
         PRINT " ";
      END IF
   NEXT  M
   PRINT
NEXT   J
PRINT "="
CALL DISPLAY(N(1),N(MM+1),X$)
END

EXTERNAL  SUB MATRIX(M,N(),A$(,,),X$(,))
DIM A(0 TO M),L(0 TO M)
MAT A=CON
LET L(1)=1
LET L(2)=M
FOR I=3 TO M
   LET L(I)=I-1
NEXT I
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(L(J)) 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(L(K))
      LET A(K)=1
      LET K=K-1
   LOOP
   LET A(K)=A(K)+1
LOOP UNTIL K=0
END SUB

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

EXTERNAL  FUNCTION MAX1(N())
FOR I=1 TO UBOUND(N)-1
   LET X=MAX(X,N(I))
NEXT I
LET MAX1=X
END FUNCTION

EXTERNAL  FUNCTION MAX2(N())
FOR I=2 TO UBOUND(N)
   LET X=MAX(X,N(I))
NEXT I
LET MAX2=X
END FUNCTION
 

戻る