|
!'高次収束式
!'Gm+1(X)=X-(X^2-A)/(X+Gm(X))
!'Fm+1(X)/Gm+1(X)=[X*{J(X)*Gm(X)+Fm(X)}-H(X)*Gm(X)] / [J(X)*Gm(X)+Fm(X)]
!'H(X)=X^K-A
!'J(X)=(K-1)*X^(K-1)
OPTION BASE 0
PUBLIC NUMERIC MAXLEVEL
LET MAXLEVEL=15
DIM J(MAXLEVEL,MAXLEVEL),G(MAXLEVEL,MAXLEVEL),F(MAXLEVEL,MAXLEVEL),H(MAXLEVEL,MAXLEVEL)
DIM FF(MAXLEVEL,MAXLEVEL),GG(MAXLEVEL,MAXLEVEL),TMP(MAXLEVEL,MAXLEVEL)
FOR K=2 TO 4
CALL CLR(G)
CALL CLR(J)
CALL CLR(H)
CALL CLR(FF)
CALL CLR(GG)
CALL CLR(F)
LET H(K,0)=1
LET H(0,1)=-1
LET J(K-1,0)=K-1
LET F(K-1,0)=1
LET G(0,0)=1
CALL DISPLAY(H,"x","a")
PRINT " = 0 の収束式"
FOR M=2 TO 5
CALL MUL(GG,J,G)
CALL ADD(GG,F)
CALL COPY(TMP,GG)
CALL SHIFT(TMP,1,1)
CALL COPY(FF,TMP)
CALL MUL(TMP,H,G)
CALL SUBST(FF,TMP)
PRINT M;"次 収束式"
PRINT "X = (";
CALL DISPLAY(FF,"X","A")
PRINT ") / (";
CALL DISPLAY(GG,"X","A")
PRINT ")"
CALL COPY(F,FF)
CALL COPY(G,GG)
NEXT M
PRINT
NEXT K
END
EXTERNAL SUB SHIFT(X(,),N,M)
OPTION BASE 0
DIM Y(MAXLEVEL,MAXLEVEL)
FOR I=0 TO MAXLEVEL-N
FOR J=0 TO MAXLEVEL
IF M=1 THEN
LET Y(I+N,J)=X(I,J)
ELSE
LET Y(J,I+N)=X(J,I)
END IF
NEXT J
NEXT I
CALL COPY(X,Y)
END SUB
EXTERNAL SUB ADD(A(,),B(,))
MAT A=A+B
END SUB
EXTERNAL SUB SUBST(A(,),B(,))
MAT A=A-B
END SUB
EXTERNAL SUB MUL(C(,),A(,),B(,))
CALL CLR(C)
LET N1=DIMCHECK1(A)
LET N2=DIMCHECK2(A)
LET M1=DIMCHECK1(B)
LET M2=DIMCHECK2(B)
FOR L=0 TO M2
FOR K=0 TO N2
FOR J=0 TO M1
FOR I=0 TO N1
IF I+J<=MAXLEVEL AND K+L<=MAXLEVEL THEN
LET C(I+J,K+L)=C(I+J,K+L)+A(I,K)*B(J,L)
ELSE
PRINT "OVER FLOW !"
EXIT SUB
END IF
NEXT I
NEXT J
NEXT K
NEXT L
END SUB
EXTERNAL SUB DISPLAY(A(,),XX$,YY$)
FOR I=MAXLEVEL TO 0 STEP -1
FOR J=MAXLEVEL TO 0 STEP -1
IF A(I,J)<>0 THEN
LET FL=FL+1
IF I=0 AND J=0 THEN
PRINT SIGN$(A(I,J));
ELSE
IF ABS(A(I,J))<>1 THEN
IF FL=1 AND A(I,J)>0 THEN
PRINT STR$(A(I,J));"*";
ELSE
PRINT SIGN$(A(I,J));"*";
END IF
ELSE
IF A(I,J)=-1 THEN
PRINT " - ";
ELSE
IF FL>1 THEN PRINT " + ";
END IF
END IF
IF I>0 THEN PRINT XX$;
IF I>1 THEN PRINT "^";STR$(I);
IF J>0 THEN
IF I>0 THEN PRINT "*";
PRINT YY$;
IF J>1 THEN PRINT "^";STR$(J);
END IF
END IF
END IF
NEXT J
NEXT I
END SUB
EXTERNAL SUB COPY(X(,),Y(,))
MAT X=Y
END SUB
EXTERNAL SUB CLR(A(,))
MAT A=ZER
END SUB
EXTERNAL FUNCTION SIGN$(X)
IF X<0 THEN LET SIGN$=" - "&STR$(-X) ELSE LET SIGN$=" + "&STR$(X)
END FUNCTION
EXTERNAL FUNCTION DIMCHECK1(A(,))
FOR I=MAXLEVEL TO 0 STEP -1
FOR J=MAXLEVEL TO 0 STEP -1
IF A(I,J)<>0 THEN
LET DIMCHECK1=I
EXIT FUNCTION
END IF
NEXT J
NEXT I
END FUNCTION
EXTERNAL FUNCTION DIMCHECK2(A(,))
FOR J=MAXLEVEL TO 0 STEP -1
FOR I=MAXLEVEL TO 0 STEP -1
IF A(I,J)<>0 THEN
LET DIMCHECK2=J
EXIT FUNCTION
END IF
NEXT I
NEXT J
END FUNCTION
|
|