MC01PD

Coefficients of a real polynomial, given its zeros

[Specification] [Arguments] [Method] [References] [Comments] [Example]

Purpose

  To compute the coefficients of a real polynomial P(x) from its
  zeros.

Specification
      SUBROUTINE MC01PD( K, REZ, IMZ, P, DWORK, INFO )
C     .. Scalar Arguments ..
      INTEGER           INFO, K
C     .. Array Arguments ..
      DOUBLE PRECISION  DWORK(*), IMZ(*), P(*), REZ(*)

Arguments

Input/Output Parameters

  K       (input) INTEGER
          The number of zeros (and hence the degree) of P(x).
          K >= 0.

  REZ     (input) DOUBLE PRECISION array, dimension (K)
  IMZ     (input) DOUBLE PRECISION array, dimension (K)
          The real and imaginary parts of the i-th zero of P(x)
          must be stored in REZ(i) and IMZ(i), respectively, where
          i = 1, 2, ..., K. The zeros may be supplied in any order,
          except that complex conjugate zeros must appear
          consecutively.

  P       (output) DOUBLE PRECISION array, dimension (K+1)
          This array contains the coefficients of P(x) in increasing
          powers of x. If K = 0, then P(1) is set to one.

Workspace
  DWORK   DOUBLE PRECISION array, dimension (K+1)
          If K = 0, this array is not referenced.

Error Indicator
  INFO    INTEGER
          = 0:  successful exit;
          < 0:  if INFO = -i, the i-th argument had an illegal
                value;
          > 0:  if INFO = i, (REZ(i),IMZ(i)) is a complex zero but
                (REZ(i-1),IMZ(i-1)) is not its conjugate.

Method
  The routine computes the coefficients of the real K-th degree
  polynomial P(x) as

     P(x) = (x - r(1)) * (x - r(2)) * ... * (x - r(K))

  where r(i) = (REZ(i),IMZ(i)).

  Note that REZ(i) = REZ(j) and IMZ(i) = -IMZ(j) if r(i) and r(j)
  form a complex conjugate pair (where i <> j), and that IMZ(i) = 0
  if r(i) is real.

Numerical Aspects
  None.

Further Comments
  None
Example

Program Text

*     MC01PD EXAMPLE PROGRAM TEXT
*     Copyright (c) 2002-2017 NICONET e.V.
*
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        ( NIN = 5, NOUT = 6 )
      INTEGER          KMAX
      PARAMETER        ( KMAX = 10 )
*     .. Local Scalars ..
      INTEGER          I, INFO, K
*     .. Local Arrays ..
      DOUBLE PRECISION DWORK(KMAX+1), IMZ(KMAX), P(KMAX+1), REZ(KMAX)
*     .. External Subroutines ..
      EXTERNAL         MC01PD
*     .. Executable Statements ..
*
      WRITE ( NOUT, FMT = 99999 )
*     Skip the heading in the data file and read the data.
      READ ( NIN, FMT = '()' )
      READ ( NIN, FMT = * ) K
      IF ( K.LT.0 .OR. K.GT.KMAX ) THEN
         WRITE ( NOUT, FMT = 99995 ) K
      ELSE
         READ ( NIN, FMT = * ) ( REZ(I), IMZ(I), I = 1,K )
*        Compute the coefficients of P(x) from the given zeros.
         CALL MC01PD( K, REZ, IMZ, P, DWORK, INFO )
*
         IF ( INFO.NE.0 ) THEN
            WRITE ( NOUT, FMT = 99998 ) INFO
         ELSE
            WRITE ( NOUT, FMT = 99997 )
            WRITE ( NOUT, FMT = 99996 ) ( I, P(I+1), I = 0,K )
         END IF
      END IF
      STOP
*
99999 FORMAT (' MC01PD EXAMPLE PROGRAM RESULTS',/1X)
99998 FORMAT (' INFO on exit from MC01PD = ',I2)
99997 FORMAT (' The coefficients of the polynomial P(x) are ',//' powe',
     $       'r of x     coefficient ')
99996 FORMAT (2X,I5,9X,F9.4)
99995 FORMAT (' K is out of range.',/' K = ',I5)
      END
Program Data
 MC01PD EXAMPLE PROGRAM DATA
   5
   0.0   1.0
   0.0  -1.0
   2.0   0.0
   1.0   3.0
   1.0  -3.0
Program Results
 MC01PD EXAMPLE PROGRAM RESULTS

 The coefficients of the polynomial P(x) are 

 power of x     coefficient 
      0          -20.0000
      1           14.0000
      2          -24.0000
      3           15.0000
      4           -4.0000
      5            1.0000

Return to index