|
!' 商差法(QD法)
OPTION ARITHMETIC COMPLEX
PUBLIC NUMERIC EPS
OPTION BASE 0
INPUT PROMPT "次数=": N
DIM D(N), A(N), Q(N)
LET EPS=1E-8
!' X^N+A(1)*X^(N-1)+A(2)*X^(N-2)+...A(N-1)*X+A(N)=0
FOR I = 0 TO N
DO
PRINT N - I;"次の複素係数 A+Bi A,B=";
INPUT RR,II
LET A(I)=COMPLEX(RR,II)
LOOP WHILE A(I) = 0 !'各係数は0でない
IF I>0 THEN LET A(I)=A(I)/A(0)
NEXT I
LET A(0)=1
LET Q(1)=-A(1)
FOR I = 1 TO N - 1
LET D(I) = A(I + 1) / A(I)
NEXT I
DO
FOR I = 1 TO N
LET Q(I) = Q(I) + D(I) - D(I - 1)
NEXT I
FOR I = 1 TO N - 1
LET D(I) = D(I) * Q(I + 1) / Q(I)
NEXT I
LET FL=0
FOR I = 1 TO N
IF ABS(D(I)) >= EPS THEN
LET FL=1
EXIT FOR
END IF
NEXT I
LOOP UNTIL FL=0
FOR I=1 TO N
PRINT "X(";STR$(I); ")=";
CALL DISPLAY(Q(I))
NEXT I
END
EXTERNAL SUB DISPLAY(Z)
OPTION ARITHMETIC COMPLEX
IF ABS(RE(Z))>EPS THEN PRINT RE((Z));
IF ABS(IM(Z))>EPS THEN
IF IM(Z)<0 THEN
PRINT "-";
ELSE
IF ABS(RE(Z))>EPS THEN PRINT "+";
END IF
PRINT ABS(IM(Z));"i";
END IF
PRINT
END SUB
|
|