'******************************************************** '* Program to demonstrate synthetic division * '* of polynomials subroutine * '* ---------------------------------------------------- * '* Reference: BASIC Scientific Subroutines, Vol. II * '* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1]. * '* ---------------------------------------------------- * '* SAMPLE RUN: * '* ( Example: Divide (x+1)^5 by (x+1) ) * '* * '* DIVISION OF POLYNOMIALS * '* * '* What is the degree of the first polynomial: 5 * '* * '* Input the first polynomial coefficients as prompted: * '* * '* C( 0) = ? 1 * '* C( 1) = ? 5 * '* C( 2) = ? 10 * '* C( 3) = ? 10 * '* C( 4) = ? 5 * '* C( 5) = ? 1 * '* * '* Input the second polynomial coefficients as prompted:* '* * '* B( 0) = ? 1 * '* B( 1) = ? 1 * '* * '* The coefficients of the resulting polynomial are: * '* * '* A( 0) = 1 * '* A( 1) = 4 * '* A( 2) = 6 * '* A( 3) = 4 * '* A( 4) = 1 * '* * '******************************************************** DEFINT I-N DEFDBL A-H, O-Z CLS PRINT PRINT " DIVISION OF POLYNOMIALS" PRINT INPUT " What is the degree of the first polynomial: ", n1 DIM C(n1) PRINT PRINT " Input the first polynomial coefficients as prompted:" PRINT FOR i = 0 TO n1 PRINT " C("; i; ") = "; : INPUT C(i) NEXT PRINT INPUT " What is the degree of the second polynomial: ", n2 DIM A(n1 - n2), B(n2) PRINT PRINT " Input the second polynomial coefficients as prompted:" PRINT FOR i = 0 TO n2 PRINT " B("; i; ") = "; : INPUT B(i) NEXT PRINT GOSUB 1000 PRINT PRINT " The coefficients of the resulting polynomial are:" PRINT FOR i = 0 TO n1 - n2 PRINT " A("; i; ") = "; A(i) NEXT PRINT PRINT END '************************************************ '* Synthetic Division of polynomials Subroutine * '* -------------------------------------------- * '* It is assumed that polynomial coefficients * '* are real. Calculates A(x)=C(x)/B(x). * '* C(x) is of order n1, B(x) is of order n2, * '* A(x) is at most of order n1-n2 (n1>n2). * '************************************************ 1000 FOR i = n1 TO n2 STEP -1 A(i - n2) = C(i) / B(n2) IF i = n2 THEN GOTO 1100 FOR j = 0 TO n2 C(i - j) = C(i - j) - A(i - n2) * B(n2 - j) NEXT j 1100 NEXT i RETURN 'End of file rsyndiv.bas