TABLE OF CONTENTS
CsplineUtils/csplineeval [ Functions ]
NAME
csplineeval --- evaluate a B-spline function
FUNCTION
Evaluates a B-spline function at a given value. This is the lowest-level B-spline evaluator in this code. It uses the simple recursive formulation of a B-spline basis function.
Given a set of knots, this routine evaluates at x the basis function of order ord that has support on knots [j-ord,j]. Note that because negative array indices are not allowed, knot -ord is stored in knots[0] here.
SYNOPSIS
127 double csplineeval( double x, int j, int ord, double *knots, int splord, int nj)
INPUTS
x the value at which it should be evaluated j which of the basis functions should be evaluated ord order of the spline knots knots on which the spline is defined splord order of the spline, but remains unchanged throughout evaluation nj number of basis functions defined on the knots (length(knots)-splord)
OUTPUTS
The j-th basis function evaluated at x: B_j(x)
SOURCE
131 { 132 double knotj=knots[j+splord]; 133 double knotjm1=knots[j-1+splord]; 134 // base case for ord=1 135 if(ord==1) { 136 if((x >= knotjm1) & (x < knotj)) return 1.0; 137 if((x==knotj) & (j+splord==nj)) return 1.0; 138 return 0.0; 139 } 140 // recursive formula otherwise 141 double out = 0; 142 double knotjmn=knots[j-ord+splord]; 143 double denom1 = (knotjm1 - knotjmn); 144 if(denom1>0){ 145 double numer1 = (x-knotjmn); 146 double rec1 = csplineeval(x,j-1,ord-1,knots,splord,nj); 147 out += numer1/denom1*rec1; 148 } 149 double knotjmn1=knots[j-ord+1+splord]; 150 double denom2 = (knotj - knotjmn1); 151 if(denom2>0){ 152 double numer2 = (knotj-x); 153 double rec2 = csplineeval(x,j,ord-1,knots,splord,nj); 154 out += numer2/denom2*rec2; 155 } 156 return out; 157 }