ocmath_1d_spline_evaluate
Description
Evaluates a cubic spline from its B-spline representation.
Syntax
int ocmath_1d_spline_evaluate( double dX, double * pY, ocmath_Spline * spline )
Parameters
- dX
- [input]the value of the independent variable (abscissa) x
- pY
- [output]pointer to the value of the dependent variable (ordinate) y
- 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_ABSCI_OUTSIDE_KNOT_INTVL (error code 247) --- dX not satisfy spline->lamda[3] <= dX <= spline->lamda[spline->n - 4]
Examples
EX1
//Evaluate at 9 equally-spaced points in the interval [1.0, 9.0] the cubic spline with
//(augmented) knots 1.0, 1.0, 1.0, 1.0, 3.0, 6.0, 8.0, 9.0, 9.0, 9.0, 9.0 and normalised
//cubic B-spline coefficients 1.0, 2.0, 4.0, 7.0, 6.0, 4.0, 3.0.
void ocmath_1d_spline_evaluate_ex1()
{
double a, b,ncap7;
int m =9;
int ncap = 4;
int r;
double lamda[11] = {1.00, 1.00, 1.00, 1.00, 3.00, 6.00, 8.00, 9.00, 9.00, 9.00, 9.00};
double c[11] = {1.00, 2.00, 4.00, 7.00, 6.00, 4.00, 3.00};
double s;
double x;
int i, j;
ocmath_Spline spline;
ncap7 = ncap +7;
spline.n = ncap7;
spline.lamda = lamda;
spline.c = c;
a = spline.lamda[3];
printf("a = %f\n",a);
b = spline.lamda[ncap+3];
printf("b = %f\n",b);
printf("Augmented set of knots stored in spline.lamda:\n");
for(j = 0; j < ncap7-1; j++)
printf("%10.4f",lamda[j]);
printf("\nB-spline coefficients stored in spline.c\n\n");
for(j = 0; j< ncap+3; j++)
printf("%10.4f",c[j]);
printf("\n x Value of cubic spline\n\n");
for (r=1; r<=m; ++r)
{
x = 1.0*((m-r) * a + (r-1) * b) /(m-1);
s= 0;
ocmath_1d_spline_evaluate(x, &s, &spline);
printf("%10.4f%15.4f\n",x,s);
}
}
//The output:
//a = 1.000000
//b = 9.000000
//Augmented set of knots stored in spline.lamda:
// 1.0000 1.0000 1.0000 1.0000 3.0000 6.0000 8.0000 9.0000 9.0000 9.0000
//B-spline coefficients stored in spline.c
// 1.0000 2.0000 4.0000 7.0000 6.0000 4.0000 3.0000
//x Value of cubic spline
// 1.0000 1.0000
// 2.0000 2.3779
// 3.0000 3.6229
// 4.0000 4.8327
// 5.0000 5.8273
// 6.0000 6.3571
// 7.0000 6.1905
// 8.0000 5.1667
// 9.0000 3.0000
Remark
See Also
ocmath_2d_spline_eval
header to Include
origin.h
Reference
nag_1d_spline_evaluate(e02bbc)nag_1d_spline_evaluate(e02bbc), NAG Manual
|