多項式平方根
F(X)=A+B*X+C*X^2+D*X^3+... G(X)=A'+B'*X+C'*X^2+D'*X^3... F(X)=G(X)^2 G(X)を求める
恒等式 (A+B*X+C*X^2+D*X^3+E*X^4+...)=(A'+B'*X+C'*X^2+D'*X^3+E'*X^4+...)^2
A=A'^2 B=2A'B' C=2A'C'+B'^2 D=2A'D'+2B'C' :
A'=SQR(A) B'=B/2A' C'=(C-B'^2)/2A' D'=(D-2B'C')/2A' :
OPTION BASE 0 PUBLIC NUMERIC MAXLEVEL !'1/(1-SIN(X)^2)=1/COS(X)^2=1+SIN(X)^2+SIN(X)^4+SIN(X)^6+... LET MAXLEVEL=40 DIM C(MAXLEVEL),X(MAXLEVEL) !'1+X^2+X^4+X^6+X^8+...=1/(1-X^2) FOR I=0 TO MAXLEVEL/2 STEP 2 LET C(I)=1 NEXT I CALL SINE(X) CALL HORNER(C,X) PRINT "1/(1-SIN(X)^2)" CALL DISPLAY(C) CALL SQRT(C) PRINT "1/COS(X)" CALL DISPLAY(C) END
EXTERNAL SUB SQRT(C()) OPTION BASE 0 DIM XX(MAXLEVEL),X(MAXLEVEL),CC(MAXLEVEL) FOR M=0 TO MAXLEVEL IF C(M)<>0 THEN EXIT FOR NEXT M IF MOD(M,2)=1 OR C(M)<0 THEN PRINT "計算不可" EXIT SUB END IF FOR MM=MAXLEVEL TO M STEP -1 IF C(MM)<>0 THEN EXIT FOR NEXT MM IF MOD(MM,2)=1 THEN PRINT "計算不可" EXIT SUB END IF FOR I=0 TO MAXLEVEL-M LET CC(I)=C(I+M) LET C(I)=0 NEXT I LET X(0)=SQR(CC(0)) FOR K=1 TO MM/2 CALL CLR(XX) FOR I=0 TO MAXLEVEL FOR J=0 TO MAXLEVEL-I LET XX(I+J)=XX(I+J)+X(I)*X(J) NEXT J NEXT I LET X(K)=(CC(K)-XX(K))/(2*X(0)) NEXT K FOR I=0 TO MAXLEVEL-M LET C(I+M/2)=X(I) NEXT I END SUB
EXTERNAL SUB COPY(X(),Y()) FOR I=0 TO MAXLEVEL LET X(I)=Y(I) NEXT I END SUB
EXTERNAL SUB CLR(X()) FOR I=0 TO MAXLEVEL LET X(I)=0 NEXT I END SUB
EXTERNAL SUB DISPLAY(A()) LET N=DIMCHECK(A) IF N>1 THEN IF A(N)<0 THEN PRINT "-"; IF ABS(A(N))<>1 THEN PRINT STR$(ABS(A(N)));"*X^";STR$(N); ELSE PRINT "X^";STR$(N); END IF END IF FOR I=N-1 TO 2 STEP -1 IF A(I)<>0 THEN IF A(I)<0 THEN PRINT "-"; ELSE PRINT "+"; IF ABS(A(I))<>1 THEN PRINT STR$(ABS(A(I)));"*X^";STR$(I); ELSEIF ABS(A(I))=1 THEN PRINT "X^";STR$(I); END IF END IF NEXT I IF A(1)<>0 THEN IF N>1 THEN IF A(1)<0 THEN PRINT "-"; ELSE PRINT "+"; END IF IF ABS(A(1))<>1 THEN PRINT STR$(ABS(A(1)));"*X"; ELSEIF ABS(A(1))=1 THEN PRINT "X"; END IF END IF IF A(0)<>0 THEN IF A(0)<0 THEN PRINT "-"; ELSE PRINT "+"; PRINT STR$(ABS(A(0))); END IF PRINT END SUB
EXTERNAL FUNCTION DIMCHECK(X()) FOR N=MAXLEVEL TO 0 STEP -1 IF X(N)<>0 THEN EXIT FOR NEXT N LET DIMCHECK=N END FUNCTION
EXTERNAL SUB HORNER(F(),X()) !'F(X(XX)) OPTION BASE 0 DIM Y(MAXLEVEL) LET N=DIMCHECK(F) LET Y(0)=F(N) FOR I=N-1 TO 0 STEP -1 CALL MUL(Y,X) LET Y(0)=Y(0)+F(I) NEXT I CALL COPY(F,Y) END SUB
|