6 STATIC double *
d3_np_fs(
long n,
double a[],
const double b[],
double x[] );
78 for( i = 0; i < n; i++ )
88 for( i = 1; i < n; i++ )
90 xmult = a[2+(i-1)*3] / a[1+(i-1)*3];
91 a[1+i*3] = a[1+i*3] - xmult * a[0+i*3];
92 x[i] = b[i] - xmult * x[i-1];
95 x[n-1] = x[n-1] / a[1+(n-1)*3];
96 for( i = n-2; 0 <= i; i-- )
98 x[i] = ( x[i] - a[0+(i+1)*3] * x[i+1] ) / a[1+i*3];
106 int ibcbeg,
double ybcbeg,
int ibcend,
double ybcend )
228 for( i = 0; i < n - 1; i++ )
233 fprintf(
ioQQQ,
" The knots must be strictly increasing\n" );
239 vector<double> a(3*n), b(n);
249 else if( ibcbeg == 1 )
251 b[0] = ( y[1] - y[0] ) / ( t[1] - t[0] ) - ybcbeg;
252 a[1+0*3] = ( t[1] - t[0] ) / 3.0;
253 a[0+1*3] = ( t[1] - t[0] ) / 6.0;
255 else if( ibcbeg == 2 )
264 fprintf(
ioQQQ,
" IBCBEG must be 0, 1 or 2, but I found %d.\n", ibcbeg );
270 for( i = 1; i < n-1; i++ )
272 b[i] = ( y[i+1] - y[i] ) / ( t[i+1] - t[i] )
273 - ( y[i] - y[i-1] ) / ( t[i] - t[i-1] );
274 a[2+(i-1)*3] = ( t[i] - t[i-1] ) / 6.0;
275 a[1+ i *3] = ( t[i+1] - t[i-1] ) / 3.0;
276 a[0+(i+1)*3] = ( t[i+1] - t[i] ) / 6.0;
287 else if( ibcend == 1 )
289 b[n-1] = ybcend - ( y[n-1] - y[n-2] ) / ( t[n-1] - t[n-2] );
290 a[2+(n-2)*3] = ( t[n-1] - t[n-2] ) / 6.0;
291 a[1+(n-1)*3] = ( t[n-1] - t[n-2] ) / 3.0;
293 else if( ibcend == 2 )
302 fprintf(
ioQQQ,
" IBCEND must be 0, 1 or 2, but I found %d.\n", ibcend );
308 if( n == 2 && ibcbeg == 0 && ibcend == 0 )
315 if(
d3_np_fs( n, &a[0], &b[0], ypp ) == NULL )
318 fprintf(
ioQQQ,
" The linear system could not be solved.\n" );
328 void spline_cubic_val(
long n,
const double t[],
double tval,
const double y[],
const double ypp[],
329 double *yval,
double *ypval,
double *yppval )
398 double dt = tval - t[ival];
399 double h = t[ival+1] - t[ival];
404 + dt * ( ( y[ival+1] - y[ival] ) / h
405 - ( ypp[ival+1] / 6.0 + ypp[ival] / 3.0 ) * h
406 + dt * ( 0.5 * ypp[ival]
407 + dt * ( ( ypp[ival+1] - ypp[ival] ) / ( 6.0 * h ) ) ) );
411 *ypval = ( y[ival+1] - y[ival] ) / h
412 - ( ypp[ival+1] / 6.0 + ypp[ival] / 3.0 ) * h
414 + dt * ( 0.5 * ( ypp[ival+1] - ypp[ival] ) / h ) );
418 *yppval = ypp[ival] + dt * ( ypp[ival+1] - ypp[ival] ) / h;
439 for(
long i=0; i < n; i++ )
442 for(
long j=0; j < n; j++ )
445 l *= (xval-x[j])/(x[i]-x[j]);
466 else if( xval >= x[n-1] )
471 double deriv = (y[ilo+1]-y[ilo])/(x[ilo+1]-x[ilo]);
472 yval = y[ilo] + deriv*(xval-x[ilo]);
void spline_cubic_val(long n, const double t[], double tval, const double y[], const double ypp[], double *yval, double *ypval, double *yppval)
void spline_cubic_set(long n, const double t[], const double y[], double ypp[], int ibcbeg, double ybcbeg, int ibcend, double ybcend)
long hunt_bisect(const T x[], long n, T xval)
STATIC double * d3_np_fs(long n, double a[], const double b[], double x[])
double lagrange(const double x[], const double y[], long n, double xval)
#define DEBUG_ENTRY(funcname)
double linint(const double x[], const double y[], long n, double xval)
int fprintf(const Output &stream, const char *format,...)