XLPack 7.0
Python API Reference Manual
Loading...
Searching...
No Matches

◆ pchse()

def pchse ( ,
,
,
,
incfd  = 1 
)

Piecewise cubic spline interpolation ("not a knot" condition)

Purpose
pchse computes the derivatives needed to determine the Hermite representation of the cubic spline interpolant to given data, with with the default boundary conditions ("not a knot" condition).

The resulting piecewise cubic spline function may be evaluated by pchfe or pchfd.
Returns
info (int)
= 0: Successful exit
= -1: The argument n had an illegal value (n < 2)
= -2: The argument x is invalid (e.g. not strictly increasing)
= -3: The argument f is invalid
= -4: The argument d is invalid
= -5: The argument incfd had an illegal value (incfd < 1)
Parameters
[in]nNumber of data points. (n >= 2)
[in]xNumpy ndarray (1-dimensional, float, length n)
Independent variable values. The elements of x[] must be strictly increasing.
[in]fNumpy ndarray (1-dimensional, float, length incfd*(n - 1) + 1)
Dependent variable values to be interpolated. f[i*incfd] is the value corresponding to x[i] (i = 0 to n - 1).
[out]dNumpy ndarray (1-dimensional, float, length incfd*(n - 1) + 1)
Derivative values at the data points. These values will determine the cubic spline interpolant with the requested boundary conditions. The value corresponding to x[i] is stored in d[i*incfd] (i = 0 to n - 1). No other entries in d are changed.
[in]incfd(Optional)
Increment between successive values in f and d. This argument is provided primarily for 2-D applications. (incfd >= 1) (default = 1)
Reference
SLATEC (PCHIP) (Driver for pchsp)
Example Program
Compute ln(0.115) and ln(0.125) by interpolating the following natural logarithm table with cubic spline.
  x       ln(x)
------ ---------
 0.10   -2.3026
 0.11   -2.2073
 0.12   -2.1203
 0.13   -2.0402
------ ---------
def TestPchse():
n = 4
x = np.array([0.1, 0.11, 0.12, 0.13])
y = np.array([-2.3026, -2.2073, -2.1203, -2.0402])
d = np.empty(n)
info = pchse(n, x, y, d)
print(info)
if info == 0:
ne = 2
xe = np.array([0.115, 0.125])
ye = np.empty(ne)
info = pchfe(n, x, y, d, ne, xe, ye)
print(ye, info)
def pchse(n, x, f, d, incfd=1)
Piecewise cubic spline interpolation ("not a knot" condition)
def pchfe(n, x, f, d, ne, xe, fe, incfd=1, skip=0)
Evaluation of function values for piecewise cubic Hermite (and cubic spline) interpolation
Example Results
>>> TestPchse()
0
[-2.16285 -2.079475] 0