MC01ND

Value of a real polynomial at a given complex point

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

Purpose

  To compute the value of the real polynomial P(x) at a given
  complex point x = x0 using Horner's algorithm.

Specification
      SUBROUTINE MC01ND( DP, XR, XI, P, VR, VI, INFO )
C     .. Scalar Arguments ..
      INTEGER           DP, INFO
      DOUBLE PRECISION  VI, VR, XI, XR
C     .. Array Arguments ..
      DOUBLE PRECISION  P(*)

Arguments

Input/Output Parameters

  DP      (input) INTEGER
          The degree of the polynomial P(x).  DP >= 0.

  XR      (input) DOUBLE PRECISION
  XI      (input) DOUBLE PRECISION
          The real and imaginary parts, respectively, of x0.

  P       (input) DOUBLE PRECISION array, dimension (DP+1)
          This array must contain the coefficients of the polynomial
          P(x) in increasing powers of x.

  VR      (output) DOUBLE PRECISION
  VI      (output) DOUBLE PRECISION
          The real and imaginary parts, respectively, of P(x0).

Error Indicator
  INFO    INTEGER
          = 0:  successful exit;
          < 0:  if INFO = -i, the i-th argument had an illegal
                value.

Method
  Given the real polynomial
                                      2                   DP
     P(x) = p(1) + p(2) * x + p(3) * x + ... + p(DP+1) * x  ,

  the routine computes the value of P(x0) using the recursion

     q(DP+1) = p(DP+1),
     q(i) = x0*q(i+1) + p(i) for i = DP, DP-1, ..., 1,

  which is known as Horner's algorithm (see [1]). Then q(1) = P(x0).

References
  [1] STOER, J and BULIRSCH, R.
      Introduction to Numerical Analysis.
      Springer-Verlag. 1980.

Numerical Aspects
  The algorithm requires DP operations for real arguments and 4*DP
  for complex arguments.

Further Comments
  None
Example

Program Text

*     MC01ND EXAMPLE PROGRAM TEXT
*     Copyright (c) 2002-2017 NICONET e.V.
*
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        ( NIN = 5, NOUT = 6 )
      INTEGER          DPMAX
      PARAMETER        ( DPMAX = 20 )
*     .. Local Scalars ..
      DOUBLE PRECISION VI, VR, XI, XR
      INTEGER          DP, I, INFO
*     .. Local Arrays ..
      DOUBLE PRECISION P(DPMAX+1)
*     .. External Subroutines ..
      EXTERNAL         MC01ND
*     .. Executable Statements ..
*
      WRITE ( NOUT, FMT = 99999 )
*     Skip the heading in the data file and read the data.
      READ ( NIN, FMT = '()' )
      READ ( NIN, FMT = * ) DP, XR, XI
      IF ( DP.LE.-1 .OR. DP.GT.DPMAX ) THEN
         WRITE ( NOUT, FMT = 99995 ) DP
      ELSE
         READ ( NIN, FMT = * ) ( P(I), I = 1,DP+1 )
*        Evaluate the polynomial at the given (complex) point.
         CALL MC01ND( DP, XR, XI, P, VR, VI, INFO )
*
         IF ( INFO.NE.0 ) THEN
            WRITE ( NOUT, FMT = 99998 ) INFO
         ELSE
            WRITE ( NOUT, FMT = 99997 ) XR, XI, VR
            WRITE ( NOUT, FMT = 99996 ) XR, XI, VI
         END IF
      END IF
*
      STOP
*
99999 FORMAT (' MC01ND EXAMPLE PROGRAM RESULTS',/1X)
99998 FORMAT (' INFO on exit from MC01ND = ',I2)
99997 FORMAT (' Real      part of P(',F6.2,SP,F6.2,'*j ) = ',SS,F8.4)
99996 FORMAT (/' Imaginary part of P(',F6.2,SP,F6.2,'*j ) = ',SS,F8.4)
99995 FORMAT (/' DP is out of range.',/' DP = ',I5)
      END
Program Data
 MC01ND EXAMPLE PROGRAM DATA
   4     -1.56     0.29
   5.0  3.0  -1.0  2.0  1.0
Program Results
 MC01ND EXAMPLE PROGRAM RESULTS

 Real      part of P( -1.56 +0.29*j ) =  -4.1337

 Imaginary part of P( -1.56 +0.29*j ) =   1.7088

Return to index