hrmesp |
Table of contents
ProcedureHRMESP ( Hermite polynomial interpolation, equal spacing ) SUBROUTINE HRMESP ( N, FIRST, STEP, YVALS, X, WORK, F, DF ) AbstractEvaluate, at a specified point, a Hermite interpolating polynomial for a specified set of equally spaced abscissa values and corresponding pairs of function and function derivative values. Required_ReadingNone. KeywordsINTERPOLATION POLYNOMIAL DeclarationsIMPLICIT NONE INTEGER N DOUBLE PRECISION FIRST DOUBLE PRECISION STEP DOUBLE PRECISION YVALS ( 2*N ) DOUBLE PRECISION X DOUBLE PRECISION WORK ( 2*N, 2 ) DOUBLE PRECISION F DOUBLE PRECISION DF Brief_I/OVARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- N I Number of points defining the polynomial. FIRST I First abscissa value. STEP I Step size. YVALS I Ordinate and derivative values. X I Point at which to interpolate the polynomial. WORK I-O Work space array. F O Interpolated function value at X. DF O Interpolated function's derivative at X. Detailed_InputN is the number of points defining the polynomial. The array YVALS contains 2*N elements. FIRST, STEP are, respectively, a starting abscissa value and a step size that define the set of abscissa values FIRST + (I-1) * STEP, I = 1, ..., N STEP must be non-zero. YVALS is an array of length 2*N containing ordinate and derivative values for each point in the domain defined by FIRST, STEP, and N. The elements YVALS( 2*I - 1 ) YVALS( 2*I ) give the value and first derivative of the output polynomial at the abscissa value FIRST + (I-1) * STEP where I ranges from 1 to N. WORK is a work space array. It is used by this routine as a scratch area to hold intermediate results. X is the abscissa value at which the interpolating polynomial and its derivative are to be evaluated. Detailed_OutputF, DF are the value and derivative at X of the unique polynomial of degree 2*N-1 that fits the points and derivatives defined by FIRST, STEP, and YVALS. ParametersNone. Exceptions1) If STEP is zero, the error SPICE(INVALIDSTEPSIZE) is signaled. 2) If N is less than 1, the error SPICE(INVALIDSIZE) is signaled. 3) This routine does not attempt to ward off or diagnose arithmetic overflows. FilesNone. ParticularsUsers of this routine must choose the number of points to use in their interpolation method. The authors of Reference [1] have this to say on the topic: Unless there is solid evidence that the interpolating function is close in form to the true function f, it is a good idea to be cautious about high-order interpolation. We enthusiastically endorse interpolations with 3 or 4 points, we are perhaps tolerant of 5 or 6; but we rarely go higher than that unless there is quite rigorous monitoring of estimated errors. The same authors offer this warning on the use of the interpolating function for extrapolation: ...the dangers of extrapolation cannot be overemphasized: An interpolating function, which is perforce an extrapolating function, will typically go berserk when the argument x is outside the range of tabulated values by more than the typical spacing of tabulated points. ExamplesThe numerical results shown for this example may differ across platforms. The results depend on the SPICE kernels used as input, the compiler and supporting libraries, and the machine specific arithmetic implementation. 1) Fit a 7th degree polynomial through the points ( x, y, y' ) ( -1, 6, 3 ) ( 1, 8, 11 ) ( 3, 2210, 5115 ) ( 5, 78180, 109395 ) and evaluate this polynomial at x = 2. The returned value of ANSWER should be 141.D0, and the returned derivative value should be 456.D0, since the unique 7th degree polynomial that fits these constraints is 7 2 f(x) = x + 2x + 5 Example code begins here. PROGRAM HRMESP_EX1 IMPLICIT NONE DOUBLE PRECISION ANSWER DOUBLE PRECISION DERIV DOUBLE PRECISION FIRST DOUBLE PRECISION STEP DOUBLE PRECISION YVALS (8) DOUBLE PRECISION WORK (8,2) INTEGER N N = 4 YVALS(1) = 6.D0 YVALS(2) = 3.D0 YVALS(3) = 8.D0 YVALS(4) = 11.D0 YVALS(5) = 2210.D0 YVALS(6) = 5115.D0 YVALS(7) = 78180.D0 YVALS(8) = 109395.D0 FIRST = -1.D0 STEP = 2.D0 CALL HRMESP ( N, FIRST, STEP, YVALS, . 2.D0, WORK, ANSWER, DERIV ) WRITE (*,*) 'ANSWER = ', ANSWER WRITE (*,*) 'DERIV = ', DERIV END When this program was executed on a Mac/Intel/gfortran/64-bit platform, the output was: ANSWER = 141.00000000000000 DERIV = 456.00000000000000 RestrictionsNone. Literature_References[1] W. Press, B. Flannery, S. Teukolsky and W. Vetterling, "Numerical Recipes -- The Art of Scientific Computing," chapters 3.0 and 3.1, Cambridge University Press, 1986. [2] S. Conte and C. de Boor, "Elementary Numerical Analysis -- An Algorithmic Approach," 3rd Edition, p 64, McGraw-Hill, 1980. Author_and_InstitutionN.J. Bachman (JPL) J. Diaz del Rio (ODC Space) E.D. Wright (JPL) VersionSPICELIB Version 1.2.2, 01-OCT-2021 (JDR) (NJB) Edited the header to comply with NAIF standard. Added code example's solution. Fixed formula in the description of YVALS argument in $Detailed_Input. SPICELIB Version 1.2.1, 28-JAN-2014 (NJB) Fixed a few comment typos. SPICELIB Version 1.2.0, 31-JAN-2002 (EDW) Added the use of DBLE to convert integer values used in DOUBLE PRECISION calculations. SPICELIB Version 1.1.0, 28-DEC-2001 (NJB) Blanks following final newline were truncated to suppress compilation warnings on the SGI-N32 platform. SPICELIB Version 1.0.0, 01-MAR-2000 (NJB) |
Fri Dec 31 18:36:26 2021