CS1GD
Evaluates the derivative of a cubic spline on a grid.
Required Arguments
IDERIV — Order of the derivative to be evaluated. (Input)
In particular, IDERIV = 0 returns the values of the cubic spline.
XVEC — Array of length N containing the points at which the cubic spline is to be evaluated. (Input)
The points in XVEC should be strictly increasing.
BREAK — Array of length NINTV + 1 containing the breakpoints for the piecewise cubic representation. (Input)
BREAK must be strictly increasing.
CSCOEF — Matrix of size 4 by NINTV + 1 containing the local coefficients of the cubic pieces. (Input)
VALUE — Array of length N containing the values of the IDERIV-th derivative of the cubic spline at the points in XVEC. (Output)
Optional Arguments
N — Length of vector XVEC. (Input)
Default: N = size (XVEC,1).
NINTV — Number of polynomial pieces. (Input)
Default: NINTV = size (BREAK,1) -1.
FORTRAN 90 Interface
Generic: CALL CS1GD (IDERIV, XVEC, BREAK, CSCOEF, VALUE [, …])
Specific: The specific interface names are S_CS1GD and D_CS1GD.
FORTRAN 77 Interface
Single: CALL CS1GD (IDERIV, N, XVEC, NINTV, BREAK, CSCOEF, VALUE)
Double: The double precision name is DCS1GD.
Description
The routine CS1GD evaluates a cubic spline (or its derivative) at a vector of points. That is, given a vector x of length n satisfying xi < xi + 1 for i = 1, …, n − 1, a derivative value j, and a cubic spline s that is represented by a breakpoint sequence and coefficient matrix this routine returns the values
s(j)(xi) i = 1, …, n
in the array
VALUE. The functionality of this routine is the same as that of
CSDER called in a loop, however
CS1GD should be much more efficient.
Comments
1. Workspace may be explicitly provided, if desired, by use of C21GD/DC21GD. The reference is:
CALL C21GD (IDERIV, N, XVEC, NINTV, BREAK, CSCOEF, VALUE, IWK, WORK1, WORK2)
The additional arguments are as follows:
IWK — Array of length N.
WORK1 — Array of length N.
WORK2 — Array of length N.
2. Informational error
Type | Code | Description |
---|
4 | 4 | The points in XVEC must be strictly increasing. |
Example
To illustrate the use of
CS1GD, we modify the example program for
CSINT. In this example, a cubic spline interpolant to
F is computed. The values of this spline are then compared with the exact function values. The routine
CS1GD is based on the routine
PPVALU in de Boor (1978, page 89).
USE CS1GD_INT
USE CSINT_INT
USE UMACH_INT
USE CSVAL_INT
IMPLICIT NONE
! Specifications
INTEGER NDATA, N, IDERIV, J
PARAMETER (NDATA=11, N=2*NDATA-1)
!
INTEGER I, NINTV, NOUT
REAL BREAK(NDATA), CSCOEF(4,NDATA), F,&
FDATA(NDATA), FLOAT, SIN, X, XDATA(NDATA),&
FVALUE(N), VALUE(N), XVEC(N)
INTRINSIC FLOAT, SIN
! Define function
F(X) = SIN(15.0*X)
! Set up a grid
DO 10 I=1, NDATA
XDATA(I) = FLOAT(I-1)/FLOAT(NDATA-1)
FDATA(I) = F(XDATA(I))
10 CONTINUE
! Compute cubic spline interpolant
CALL CSINT (XDATA, FDATA, BREAK, CSCOEF)
DO 20 I=1, N
XVEC(I) = FLOAT(I-1)/FLOAT(2*NDATA-2)
FVALUE(I) = F(XVEC(I))
20 CONTINUE
IDERIV = 0
NINTV = NDATA - 1
CALL CS1GD (IDERIV, XVEC, BREAK, CSCOEF, VALUE)
! Get output unit number.
CALL UMACH (2, NOUT)
! Write heading
WRITE (NOUT,99999)
99999 FORMAT (13X, 'X', 9X, 'Interpolant', 5X, 'Error')
! Print the interpolant and the error
! on a finer grid
DO 30 J=1, N
WRITE (NOUT,'(2F15.3,F15.6)') XVEC(J), VALUE(J),&
FVALUE(J)-VALUE(J)
30 CONTINUE
END
Output
X Interpolant Error
0.000 0.000 0.000000
0.050 0.809 -0.127025
0.100 0.997 0.000000
0.150 0.723 0.055214
0.200 0.141 0.000000
0.250 -0.549 -0.022789
0.300 -0.978 0.000000
0.350 -0.843 -0.016246
0.400 -0.279 0.000000
0.450 0.441 0.009348
0.500 0.938 0.000000
0.550 0.903 0.019947
0.600 0.412 0.000000
0.650 -0.315 -0.004895
0.700 -0.880 0.000000
0.750 -0.938 -0.029541
0.800 -0.537 0.000000
0.850 0.148 0.034693
0.900 0.804 0.000000
0.950 1.086 -0.092559
1.000 0.650 0.000000