# 2.1.17.5.2 ocmath_1d_spline_deriv

## Description

Evaluates a cubic spline and its first three derivatives from its B-spline representation.

## Syntax

int ocmath_1d_spline_deriv( OCMATH_DERIVTYPE derivs, double dX, double * pDeriv, ocmath_Spline * spline )

## Parameters

derivs
[input]if derivs = DERIVTYPE_LEFTDERIVS, calculates right derivatives or right limiting values;if derivs = DERIVTYPE_RIGHTDERIVS, calculates left derivatives or left limiting values
dX
[input]the variable x, its derivatives are to be evaluated
pDeriv
[output]pointer to the derivative.
pDeriv[j] is the jth derivative of the spline at the argument dX, for j = 0,1,2,3.
spline
[input] pointer to the structure ocmath_Spline, usually returned by function ocmath_1d_spline_fit

## Return

NE_NOERROR (code 0) --- success

NE_INT_ARG_LT (error code 11) --- spline->n < 8

NE_BAD_PARAM (error code 70) --- value of derivs is invalid

NE_SPLINE_RANGE_INVALID (error code 278) --- spline->lamda >= spline->lamda[spline->n - 4]

NE_ABSCI_OUTSIDE_KNOT_INTVL (error code 247) --- dX not satisfy spline->lamda <= dX <= spline->lamda[spline->n - 4]

## Examples

EX1

//Compute, at the 7 arguments x = 0, 1, 2, 3, 4, 5, 6, the left- and right-hand values
//and first 3 derivatives of the cubic spline defined over the interval 0 ?? x ?? 6 having
//the 6 interior knots x = 1, 3, 3, 3, 4, 4, the 8 additional knots 0, 0, 0, 0, 6, 6, 6, 6,
//and the 10 B-spline coefficients 10, 12, 13, 15, 22, 26, 24, 18, 14, 12.

//The example program is written in a general form that will enable the values and derivatives of a
//cubic spline having an arbitrary number of knots to be evaluated at a set of arbitrary points. Any
//number of data sets may be supplied.
void    ocmath_1d_spline_deriv_ex1()
{
int i, j, l, m, ncap, ncap7;
double s;
double lamd = {0.0, 0.0, 0.0, 0.0, 1.0, 3.0, 3.0, 3.0, 4.0, 4.0, 6.0, 6.0, 6.0, 6.0};
double c1 = {10.0, 12.0, 13.0, 15.0, 22.0, 26.0, 24.0, 18.0, 14.0, 12.0};
double x = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
ocmath_Spline spline;
OCMATH_DERIVTYPE derivs;

printf("Example Program Results\n");
ncap = 7;
m = 7;
ncap7 = ncap+7;
spline.n = ncap7;
spline.lamda = lamd;
spline.c = c1;

for( i = 0; i < 11; i++)
printf("%f    ",spline.lamda[i]);

printf(" x Spline 1st deriv 2nd deriv 3rd deriv");
for (i= 0; i< m; i++)
{
derivs = DERIVTYPE_LEFTDERIVS;
for (j=1; j<=2; j++)
{
ocmath_1d_spline_deriv(derivs, x[i], s, &spline);

if(derivs ==DERIVTYPE_LEFTDERIVS)
{
printf("\n\n%11.4f Left",x[i]);
for (l=0; l<4; l++)
printf("%11.4f",s[l]);
}
else
{
printf("\n%11.4f Right",x[i]);
for (l=0; l<4; l++)
printf("%11.4f",s[l]);
}
derivs = DERIVTYPE_RIGHTDERIVS;
}
}
}