home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
fortran
/
library
/
ssp
/
polyops
/
pgcd.for
< prev
next >
Wrap
Text File
|
1985-11-29
|
2KB
|
65 lines
C
C ..................................................................
C
C SUBROUTINE PGCD
C
C PURPOSE
C DETERMINE GREATEST COMMON DIVISOR OF TWO POLYNOMIALS
C
C USAGE
C CALL PGCD(X,IDIMX,Y,IDIMY,WORK,EPS,IER)
C
C DESCRIPTION OF PARAMETERS
C X - VECTOR OF COEFFICIENTS FOR FIRST POLYNOMIAL,
C ORDERED FROM SMALLEST TO LARGEST POWER
C IDIMX - DIMENSION OF X
C Y - VECTOR OF COEFFICIENTS FOR SECOND POLYNOMIAL,
C ORDERED FROM SMALLEST TO LARGEST POWER.
C THIS IS REPLACED BY GREATEST COMMON DIVISOR
C IDIMY - DIMENSION OF Y
C WORK - WORKING STORAGE ARRAY
C EPS - TOLERANCE VALUE BELOW WHICH COEFFICIENT IS
C ELIMINATED DURING NORMALIZATION
C IER - RESULTANT ERROR CODE WHERE
C IER=0 NO ERROR
C IER=1 X OR Y IS ZERO POLYNOMIAL
C
C REMARKS
C IDIMX MUST BE GREATER THAN IDIMY
C IDIMY=1 ON RETURN MEANS X AND Y ARE PRIME, THE GCD IS A
C CONSTANT. IDIMX IS DESTROYED DURING COMPUTATION.
C
C SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C PDIV
C PNORM
C
C METHOD
C GREATEST COMMON DIVISOR OF TWO POLYNOMIALS X AND Y IS
C DETERMINED BY MEANS OF EUCLIDEAN ALGORITHM. COEFFICIENT
C VECTORS X AND Y ARE DESTROYED AND GREATEST COMMON
C DIVISOR IS GENERATED IN Y.
C
C ..................................................................
C
SUBROUTINE PGCD(X,IDIMX,Y,IDIMY,WORK,EPS,IER)
DIMENSION X(1),Y(1),WORK(1)
C
C DIMENSION REQUIRED FOR VECTOR NAMED WORK IS IDIMX-IDIMY+1
C
1 CALL PDIV(WORK,NDIM,X,IDIMX,Y,IDIMY,EPS,IER)
IF(IER) 5,2,5
2 IF(IDIMX) 5,5,3
C
C INTERCHANGE X AND Y
C
3 DO 4 J=1,IDIMY
WORK(1)=X(J)
X(J)=Y(J)
4 Y(J)=WORK(1)
NDIM=IDIMX
IDIMX=IDIMY
IDIMY=NDIM
GO TO 1
5 RETURN
END