#include <TRadSpline.h>
Inheritance diagram for TRadSpline3:
Public Member Functions | |
TRadSpline3 () | |
TRadSpline3 (const char *title, double x[], double y[], int n, const char *opt=0, double valbeg=0, double valend=0) | |
TRadSpline3 (const char *title, double xmin, double xmax, double y[], int n, const char *opt=0, double valbeg=0, double valend=0) | |
TRadSpline3 (const char *title, double xmin, double xmax, double(*func)(const double &), int n, const char *opt=0, double valbeg=0, double valend=0) | |
int | FindX (double x) const |
double | Eval (double x) const |
double | Derivative (double x) const |
virtual | ~TRadSpline3 () |
void | GetCoeff (int i, double &x, double &y, double &b, double &c, double &d) |
void | GetKnot (int i, double &x, double &y) const |
virtual void | SaveAs (const char *filename) const |
virtual int | GetNpx () const |
void | SetNpx (int n) |
Static Public Member Functions | |
static void | Test () |
Protected Attributes | |
double | fDelta |
double | fXmin |
double | fXmax |
int | fNp |
bool | fKstep |
int | fNpx |
Private Member Functions | |
void | BuildCoeff () |
void | SetCond (const char *opt) |
Private Attributes | |
TRadSplinePoly3 * | fPoly |
double | fValBeg |
double | fValEnd |
int | fBegCond |
int | fEndCond |
Definition at line 113 of file TRadSpline.h.
TRadSpline3::TRadSpline3 | ( | ) | [inline] |
TRadSpline3::TRadSpline3 | ( | const char * | title, | |
double | x[], | |||
double | y[], | |||
int | n, | |||
const char * | opt = 0 , |
|||
double | valbeg = 0 , |
|||
double | valend = 0 | |||
) |
Definition at line 24 of file TRadSpline.C.
References BuildCoeff(), fPoly, genRecEmupikp::i, SetCond(), and TRadSplinePoly::Y().
00026 : 00027 TRadSpline(title,-1,x[0],x[n-1],n,false), 00028 fValBeg(valbeg), fValEnd(valend), fBegCond(0), fEndCond(0) 00029 { 00030 // 00031 // Third spline creator given an array of 00032 // arbitrary knots in increasing abscissa order and 00033 // possibly end point conditions 00034 // 00035 00036 // 00037 // Set endpoint conditions 00038 if(opt) SetCond(opt); 00039 // 00040 // Create the plynomial terms and fill 00041 // them with node information 00042 fPoly = new TRadSplinePoly3[n]; 00043 for (int i=0; i<n; ++i) { 00044 fPoly[i].X() = x[i]; 00045 fPoly[i].Y() = y[i]; 00046 } 00047 // 00048 // Build the spline coefficients 00049 BuildCoeff(); 00050 }
TRadSpline3::TRadSpline3 | ( | const char * | title, | |
double | xmin, | |||
double | xmax, | |||
double | y[], | |||
int | n, | |||
const char * | opt = 0 , |
|||
double | valbeg = 0 , |
|||
double | valend = 0 | |||
) |
Definition at line 53 of file TRadSpline.C.
References BuildCoeff(), TRadSpline::fDelta, fPoly, TRadSpline::fXmin, genRecEmupikp::i, SetCond(), and TRadSplinePoly::Y().
00056 : 00057 TRadSpline(title,(xmax-xmin)/(n-1), xmin, xmax, n, true), 00058 fValBeg(valbeg), fValEnd(valend), 00059 fBegCond(0), fEndCond(0) 00060 { 00061 // 00062 // Third spline creator given an array of 00063 // arbitrary function values on equidistant n abscissa 00064 // values from xmin to xmax and possibly end point conditions 00065 // 00066 00067 // 00068 // Set endpoint conditions 00069 if(opt) SetCond(opt); 00070 // 00071 // Create the plynomial terms and fill 00072 // them with node information 00073 fPoly = new TRadSplinePoly3[n]; 00074 for (int i=0; i<n; ++i) { 00075 fPoly[i].X() = fXmin+i*fDelta; 00076 fPoly[i].Y() = y[i]; 00077 } 00078 // 00079 // Build the spline coefficients 00080 BuildCoeff(); 00081 }
TRadSpline3::TRadSpline3 | ( | const char * | title, | |
double | xmin, | |||
double | xmax, | |||
double(*)(const double &) | func, | |||
int | n, | |||
const char * | opt = 0 , |
|||
double | valbeg = 0 , |
|||
double | valend = 0 | |||
) |
Definition at line 83 of file TRadSpline.C.
References BuildCoeff(), TRadSpline::fDelta, fPoly, TRadSpline::fXmin, genRecEmupikp::i, SetCond(), TRadSplinePoly::X(), x, and TRadSplinePoly::Y().
00086 : 00087 TRadSpline(title,(xmax-xmin)/(n-1), xmin, xmax, n, true), 00088 fValBeg(valbeg), fValEnd(valend), 00089 fBegCond(0), fEndCond(0) 00090 { 00091 // 00092 // Third spline creator given a function to be 00093 // evaluated on n equidistand abscissa points between xmin 00094 // and xmax and possibly end point conditions 00095 // 00096 00097 // 00098 // Set endpoint conditions 00099 if(opt) SetCond(opt); 00100 // Create the plynomial terms and fill 00101 // them with node information 00102 fPoly = new TRadSplinePoly3[n]; 00103 for (int i=0; i<n; ++i) { 00104 double x=fXmin+i*fDelta; 00105 fPoly[i].X() = x; 00106 fPoly[i].Y() = func(x); 00107 } 00108 // Build the spline coefficients 00109 BuildCoeff(); 00110 }
virtual TRadSpline3::~TRadSpline3 | ( | ) | [inline, virtual] |
void TRadSpline3::BuildCoeff | ( | ) | [private, virtual] |
Implements TRadSpline.
Definition at line 492 of file TRadSpline.C.
References TRadSplinePoly3::B(), TRadSplinePoly3::C(), EvtCyclic3::C, TRadSplinePoly3::D(), fBegCond, fEndCond, TRadSpline::fNp, fPoly, fValBeg, fValEnd, genRecEmupikp::i, ganga-rec::j, and TRadSplinePoly::Y().
Referenced by TRadSpline3().
00493 { 00494 // subroutine cubspl ( tau, c, n, ibcbeg, ibcend ) 00495 // from * a practical guide to splines * by c. de boor 00496 // ************************ input *************************** 00497 // n = number of data points. assumed to be .ge. 2. 00498 // (tau(i), c(1,i), i=1,...,n) = abscissae and ordinates of the 00499 // data points. tau is assumed to be strictly increasing. 00500 // ibcbeg, ibcend = boundary condition indicators, and 00501 // c(2,1), c(2,n) = boundary condition information. specifically, 00502 // ibcbeg = 0 means no boundary condition at tau(1) is given. 00503 // in this case, the not-a-knot condition is used, i.e. the 00504 // jump in the third derivative across tau(2) is forced to 00505 // zero, thus the first and the second cubic polynomial pieces 00506 // are made to coincide.) 00507 // ibcbeg = 1 means that the slope at tau(1) is made to equal 00508 // c(2,1), supplied by input. 00509 // ibcbeg = 2 means that the second derivative at tau(1) is 00510 // made to equal c(2,1), supplied by input. 00511 // ibcend = 0, 1, or 2 has analogous meaning concerning the 00512 // boundary condition at tau(n), with the additional infor- 00513 // mation taken from c(2,n). 00514 // *********************** output ************************** 00515 // c(j,i), j=1,...,4; i=1,...,l (= n-1) = the polynomial coefficients 00516 // of the cubic interpolating spline with interior knots (or 00517 // joints) tau(2), ..., tau(n-1). precisely, in the interval 00518 // (tau(i), tau(i+1)), the spline f is given by 00519 // f(x) = c(1,i)+h*(c(2,i)+h*(c(3,i)+h*c(4,i)/3.)/2.) 00520 // where h = x - tau(i). the function program *ppvalu* may be 00521 // used to evaluate f or its derivatives from tau,c, l = n-1, 00522 // and k=4. 00523 00524 int i, j, l, m; 00525 double divdf1,divdf3,dtau,g=0; 00526 //***** a tridiagonal linear system for the unknown slopes s(i) of 00527 // f at tau(i), i=1,...,n, is generated and then solved by gauss elim- 00528 // ination, with s(i) ending up in c(2,i), all i. 00529 // c(3,.) and c(4,.) are used initially for temporary storage. 00530 l = fNp-1; 00531 // compute first differences of x sequence and store in C also, 00532 // compute first divided difference of data and store in D. 00533 for (m=1; m<fNp ; ++m) { 00534 fPoly[m].C() = fPoly[m].X() - fPoly[m-1].X(); 00535 fPoly[m].D() = (fPoly[m].Y() - fPoly[m-1].Y())/fPoly[m].C(); 00536 } 00537 // construct first equation from the boundary condition, of the form 00538 // D[0]*s[0] + C[0]*s[1] = B[0] 00539 if(fBegCond==0) { 00540 if(fNp == 2) { 00541 // no condition at left end and n = 2. 00542 fPoly[0].D() = 1.; 00543 fPoly[0].C() = 1.; 00544 fPoly[0].B() = 2.*fPoly[1].D(); 00545 } else { 00546 // not-a-knot condition at left end and n .gt. 2. 00547 fPoly[0].D() = fPoly[2].C(); 00548 fPoly[0].C() = fPoly[1].C() + fPoly[2].C(); 00549 fPoly[0].B() =((fPoly[1].C()+2.*fPoly[0].C())*fPoly[1].D()*fPoly[2].C()+fPoly[1].C()*fPoly[1].C()*fPoly[2].D())/fPoly[0].C(); 00550 } 00551 } else if (fBegCond==1) { 00552 // slope prescribed at left end. 00553 fPoly[0].B() = fValBeg; 00554 fPoly[0].D() = 1.; 00555 fPoly[0].C() = 0.; 00556 } else if (fBegCond==2) { 00557 // second derivative prescribed at left end. 00558 fPoly[0].D() = 2.; 00559 fPoly[0].C() = 1.; 00560 fPoly[0].B() = 3.*fPoly[1].D() - fPoly[1].C()/2.*fValBeg; 00561 } 00562 if(fNp > 2) { 00563 // if there are interior knots, generate the corresp. equations and car- 00564 // ry out the forward pass of gauss elimination, after which the m-th 00565 // equation reads D[m]*s[m] + C[m]*s[m+1] = B[m]. 00566 for (m=1; m<l; ++m) { 00567 g = -fPoly[m+1].C()/fPoly[m-1].D(); 00568 fPoly[m].B() = g*fPoly[m-1].B() + 3.*(fPoly[m].C()*fPoly[m+1].D()+fPoly[m+1].C()*fPoly[m].D()); 00569 fPoly[m].D() = g*fPoly[m-1].C() + 2.*(fPoly[m].C() + fPoly[m+1].C()); 00570 } 00571 // construct last equation from the second boundary condition, of the form 00572 // (-g*D[n-2])*s[n-2] + D[n-1]*s[n-1] = B[n-1] 00573 // if slope is prescribed at right end, one can go directly to back- 00574 // substitution, since c array happens to be set up just right for it 00575 // at this point. 00576 if(fEndCond == 0) { 00577 if (fNp > 3 || fBegCond != 0) { 00578 // not-a-knot and n .ge. 3, and either n.gt.3 or also not-a-knot at 00579 // left end point. 00580 g = fPoly[fNp-2].C() + fPoly[fNp-1].C(); 00581 fPoly[fNp-1].B() = ((fPoly[fNp-1].C()+2.*g)*fPoly[fNp-1].D()*fPoly[fNp-2].C() 00582 + fPoly[fNp-1].C()*fPoly[fNp-1].C()*(fPoly[fNp-2].Y()-fPoly[fNp-3].Y())/fPoly[fNp-2].C())/g; 00583 g = -g/fPoly[fNp-2].D(); 00584 fPoly[fNp-1].D() = fPoly[fNp-2].C(); 00585 } else { 00586 // either (n=3 and not-a-knot also at left) or (n=2 and not not-a- 00587 // knot at left end point). 00588 fPoly[fNp-1].B() = 2.*fPoly[fNp-1].D(); 00589 fPoly[fNp-1].D() = 1.; 00590 g = -1./fPoly[fNp-2].D(); 00591 } 00592 } else if (fEndCond == 1) { 00593 fPoly[fNp-1].B() = fValEnd; 00594 goto L30; 00595 } else if (fEndCond == 2) { 00596 // second derivative prescribed at right endpoint. 00597 fPoly[fNp-1].B() = 3.*fPoly[fNp-1].D() + fPoly[fNp-1].C()/2.*fValEnd; 00598 fPoly[fNp-1].D() = 2.; 00599 g = -1./fPoly[fNp-2].D(); 00600 } 00601 } else { 00602 if(fEndCond == 0) { 00603 if (fBegCond > 0) { 00604 // either (n=3 and not-a-knot also at left) or (n=2 and not not-a- 00605 // knot at left end point). 00606 fPoly[fNp-1].B() = 2.*fPoly[fNp-1].D(); 00607 fPoly[fNp-1].D() = 1.; 00608 g = -1./fPoly[fNp-2].D(); 00609 } else { 00610 // not-a-knot at right endpoint and at left endpoint and n = 2. 00611 fPoly[fNp-1].B() = fPoly[fNp-1].D(); 00612 goto L30; 00613 } 00614 } else if(fEndCond == 1) { 00615 fPoly[fNp-1].B() = fValEnd; 00616 goto L30; 00617 } else if(fEndCond == 2) { 00618 // second derivative prescribed at right endpoint. 00619 fPoly[fNp-1].B() = 3.*fPoly[fNp-1].D() + fPoly[fNp-1].C()/2.*fValEnd; 00620 fPoly[fNp-1].D() = 2.; 00621 g = -1./fPoly[fNp-2].D(); 00622 } 00623 } 00624 // complete forward pass of gauss elimination. 00625 fPoly[fNp-1].D() = g*fPoly[fNp-2].C() + fPoly[fNp-1].D(); 00626 fPoly[fNp-1].B() = (g*fPoly[fNp-2].B() + fPoly[fNp-1].B())/fPoly[fNp-1].D(); 00627 // carry out back substitution 00628 L30: j = l-1; 00629 do { 00630 fPoly[j].B() = (fPoly[j].B() - fPoly[j].C()*fPoly[j+1].B())/fPoly[j].D(); 00631 --j; 00632 } while (j>=0); 00633 //****** generate cubic coefficients in each interval, i.e., the deriv.s 00634 // at its left endpoint, from value and slope at its endpoints. 00635 for (i=1; i<fNp; ++i) { 00636 dtau = fPoly[i].C(); 00637 divdf1 = (fPoly[i].Y() - fPoly[i-1].Y())/dtau; 00638 divdf3 = fPoly[i-1].B() + fPoly[i].B() - 2.*divdf1; 00639 fPoly[i-1].C() = (divdf1 - fPoly[i-1].B() - divdf3)/dtau; 00640 fPoly[i-1].D() = (divdf3/dtau)/dtau; 00641 } 00642 }
double TRadSpline3::Derivative | ( | double | x | ) | const |
Definition at line 325 of file TRadSpline.C.
References TRadSplinePoly3::Derivative(), FindX(), and fPoly.
00326 { 00327 int klow=FindX(x); 00328 return fPoly[klow].Derivative(x); 00329 }
double TRadSpline3::Eval | ( | double | x | ) | const [virtual] |
Implements TRadSpline.
Definition at line 318 of file TRadSpline.C.
References TRadSplinePoly3::Eval(), FindX(), and fPoly.
Referenced by TDFun::EvalSpline().
int TRadSpline3::FindX | ( | double | x | ) | const |
Definition at line 285 of file TRadSpline.C.
References TRadSpline::fDelta, TRadSpline::fKstep, TRadSpline::fNp, fPoly, TRadSpline::fXmax, and TRadSpline::fXmin.
Referenced by Derivative(), and Eval().
00286 { 00287 int klow=0; 00288 // 00289 // If out of boundaries, extrapolate 00290 // It may be badly wrong 00291 if(x<=fXmin) klow=0; 00292 else if(x>=fXmax) klow=fNp-1; 00293 else { 00294 if(fKstep) { 00295 // 00296 // Equidistant knots, use histogramming 00297 klow = (int((x-fXmin)/fDelta)<fNp-1)?int((x-fXmin)/fDelta):fNp-1; 00298 } else { 00299 int khig=fNp-1, khalf; 00300 // 00301 // Non equidistant knots, binary search 00302 while(khig-klow>1) 00303 if(x>fPoly[khalf=(klow+khig)/2].X()) 00304 klow=khalf; 00305 else 00306 khig=khalf; 00307 } 00308 // 00309 // This could be removed, sanity check 00310 if(!(fPoly[klow].X()<=x && x<=fPoly[klow+1].X())) 00311 printf("Binary search failed x(%d) = %f < %f < x(%d) = %f\n", 00312 klow, fPoly[klow].X(), x, klow+1, fPoly[klow+1].X()); 00313 } 00314 return klow; 00315 }
void TRadSpline3::GetCoeff | ( | int | i, | |
double & | x, | |||
double & | y, | |||
double & | b, | |||
double & | c, | |||
double & | d | |||
) | [inline] |
Definition at line 142 of file TRadSpline.h.
References TRadSplinePoly3::B(), TRadSplinePoly3::C(), TRadSplinePoly3::D(), fPoly, TRadSplinePoly::X(), and TRadSplinePoly::Y().
Referenced by Test().
void TRadSpline3::GetKnot | ( | int | i, | |
double & | x, | |||
double & | y | |||
) | const [inline, virtual] |
Implements TRadSpline.
Definition at line 145 of file TRadSpline.h.
References fPoly, TRadSplinePoly::X(), and TRadSplinePoly::Y().
virtual int TRadSpline::GetNpx | ( | ) | const [inline, virtual, inherited] |
void TRadSpline3::SaveAs | ( | const char * | filename | ) | const [virtual] |
Reimplemented from TRadSpline.
Definition at line 332 of file TRadSpline.C.
References EvtCyclic3::B, EvtCyclic3::C, TRadSpline::fDelta, TRadSpline::fKstep, TRadSpline::fNp, fPoly, TRadSpline::fXmax, TRadSpline::fXmin, and genRecEmupikp::i.
00333 { 00334 // write this spline as a C++ function that can be executed without ROOT 00335 // the name of the function is the name of the file up to the "." if any 00336 00337 //open the file 00338 ofstream *f = new ofstream(filename,ios::out); 00339 if (f == 0) { 00340 printf("Cannot open file:%s\n",filename); 00341 return; 00342 } 00343 00344 //write the function name and the spline constants 00345 char buffer[512]; 00346 int nch = strlen(filename); 00347 sprintf(buffer,"double %s",filename); 00348 char *dot = strstr(buffer,"."); 00349 if (dot) *dot = 0; 00350 strcat(buffer,"(double x) {\n"); 00351 nch = strlen(buffer); f->write(buffer,nch); 00352 sprintf(buffer," const int fNp = %d, fKstep = %d;\n",fNp,fKstep); 00353 nch = strlen(buffer); f->write(buffer,nch); 00354 sprintf(buffer," const double fDelta = %g, fXmin = %g, fXmax = %g;\n",fDelta,fXmin,fXmax); 00355 nch = strlen(buffer); f->write(buffer,nch); 00356 00357 //write the spline coefficients 00358 //array fX 00359 sprintf(buffer," const double fX[%d] = {",fNp); 00360 nch = strlen(buffer); f->write(buffer,nch); 00361 buffer[0] = 0; 00362 int i; 00363 char numb[20]; 00364 for (i=0;i<fNp;i++) { 00365 sprintf(numb," %g,",fPoly[i].X()); 00366 nch = strlen(numb); 00367 if (i == fNp-1) numb[nch-1]=0; 00368 strcat(buffer,numb); 00369 if (i%5 == 4 || i == fNp-1) { 00370 nch = strlen(buffer); f->write(buffer,nch); 00371 if (i != fNp-1) sprintf(buffer,"\n "); 00372 } 00373 } 00374 sprintf(buffer," };\n"); 00375 nch = strlen(buffer); f->write(buffer,nch); 00376 //array fY 00377 sprintf(buffer," const double fY[%d] = {",fNp); 00378 nch = strlen(buffer); f->write(buffer,nch); 00379 buffer[0] = 0; 00380 for (i=0;i<fNp;i++) { 00381 sprintf(numb," %g,",fPoly[i].Y()); 00382 nch = strlen(numb); 00383 if (i == fNp-1) numb[nch-1]=0; 00384 strcat(buffer,numb); 00385 if (i%5 == 4 || i == fNp-1) { 00386 nch = strlen(buffer); f->write(buffer,nch); 00387 if (i != fNp-1) sprintf(buffer,"\n "); 00388 } 00389 } 00390 sprintf(buffer," };\n"); 00391 nch = strlen(buffer); f->write(buffer,nch); 00392 //array fB 00393 sprintf(buffer," const double fB[%d] = {",fNp); 00394 nch = strlen(buffer); f->write(buffer,nch); 00395 buffer[0] = 0; 00396 for (i=0;i<fNp;i++) { 00397 sprintf(numb," %g,",fPoly[i].B()); 00398 nch = strlen(numb); 00399 if (i == fNp-1) numb[nch-1]=0; 00400 strcat(buffer,numb); 00401 if (i%5 == 4 || i == fNp-1) { 00402 nch = strlen(buffer); f->write(buffer,nch); 00403 if (i != fNp-1) sprintf(buffer,"\n "); 00404 } 00405 } 00406 sprintf(buffer," };\n"); 00407 nch = strlen(buffer); f->write(buffer,nch); 00408 //array fC 00409 sprintf(buffer," const double fC[%d] = {",fNp); 00410 nch = strlen(buffer); f->write(buffer,nch); 00411 buffer[0] = 0; 00412 for (i=0;i<fNp;i++) { 00413 sprintf(numb," %g,",fPoly[i].C()); 00414 nch = strlen(numb); 00415 if (i == fNp-1) numb[nch-1]=0; 00416 strcat(buffer,numb); 00417 if (i%5 == 4 || i == fNp-1) { 00418 nch = strlen(buffer); f->write(buffer,nch); 00419 if (i != fNp-1) sprintf(buffer,"\n "); 00420 } 00421 } 00422 sprintf(buffer," };\n"); 00423 nch = strlen(buffer); f->write(buffer,nch); 00424 //array fD 00425 sprintf(buffer," const double fD[%d] = {",fNp); 00426 nch = strlen(buffer); f->write(buffer,nch); 00427 buffer[0] = 0; 00428 for (i=0;i<fNp;i++) { 00429 sprintf(numb," %g,",fPoly[i].D()); 00430 nch = strlen(numb); 00431 if (i == fNp-1) numb[nch-1]=0; 00432 strcat(buffer,numb); 00433 if (i%5 == 4 || i == fNp-1) { 00434 nch = strlen(buffer); f->write(buffer,nch); 00435 if (i != fNp-1) sprintf(buffer,"\n "); 00436 } 00437 } 00438 sprintf(buffer," };\n"); 00439 nch = strlen(buffer); f->write(buffer,nch); 00440 00441 //generate code for the spline evaluation 00442 sprintf(buffer," int klow=0;\n"); 00443 nch = strlen(buffer); f->write(buffer,nch); 00444 00445 sprintf(buffer," // If out of boundaries, extrapolate. It may be badly wrong\n"); 00446 sprintf(buffer," if(x<=fXmin) klow=0;\n"); 00447 nch = strlen(buffer); f->write(buffer,nch); 00448 sprintf(buffer," else if(x>=fXmax) klow=fNp-1;\n"); 00449 nch = strlen(buffer); f->write(buffer,nch); 00450 sprintf(buffer," else {\n"); 00451 nch = strlen(buffer); f->write(buffer,nch); 00452 sprintf(buffer," if(fKstep) {\n"); 00453 nch = strlen(buffer); f->write(buffer,nch); 00454 00455 sprintf(buffer," // Equidistant knots, use histogramming\n"); 00456 nch = strlen(buffer); f->write(buffer,nch); 00457 sprintf(buffer," klow = int((x-fXmin)/fDelta);\n"); 00458 nch = strlen(buffer); f->write(buffer,nch); 00459 sprintf(buffer," if (klow < fNp-1) klow = fNp-1;\n"); 00460 nch = strlen(buffer); f->write(buffer,nch); 00461 sprintf(buffer," } else {\n"); 00462 nch = strlen(buffer); f->write(buffer,nch); 00463 sprintf(buffer," int khig=fNp-1, khalf;\n"); 00464 nch = strlen(buffer); f->write(buffer,nch); 00465 00466 sprintf(buffer," // Non equidistant knots, binary search\n"); 00467 nch = strlen(buffer); f->write(buffer,nch); 00468 sprintf(buffer," while(khig-klow>1)\n"); 00469 nch = strlen(buffer); f->write(buffer,nch); 00470 sprintf(buffer," if(x>fX[khalf=(klow+khig)/2]) klow=khalf;\n"); 00471 nch = strlen(buffer); f->write(buffer,nch); 00472 sprintf(buffer," else khig=khalf;\n"); 00473 nch = strlen(buffer); f->write(buffer,nch); 00474 sprintf(buffer," }\n"); 00475 nch = strlen(buffer); f->write(buffer,nch); 00476 sprintf(buffer," }\n"); 00477 nch = strlen(buffer); f->write(buffer,nch); 00478 sprintf(buffer," // Evaluate now\n"); 00479 nch = strlen(buffer); f->write(buffer,nch); 00480 sprintf(buffer," double dx=x-fX[klow];\n"); 00481 nch = strlen(buffer); f->write(buffer,nch); 00482 sprintf(buffer," return (fY[klow]+dx*(fB[klow]+dx*(fC[klow]+dx*fD[klow])));\n"); 00483 nch = strlen(buffer); f->write(buffer,nch); 00484 00485 //close file 00486 f->write("}\n",2); 00487 00488 if (f) { f->close(); delete f;} 00489 }
void TRadSpline3::SetCond | ( | const char * | opt | ) | [private] |
Definition at line 112 of file TRadSpline.C.
References fBegCond, and fEndCond.
Referenced by TRadSpline3().
00113 { 00114 // 00115 // Check the boundary conditions 00116 // 00117 const char *b1 = strstr(opt,"b1"); 00118 const char *e1 = strstr(opt,"e1"); 00119 const char *b2 = strstr(opt,"b2"); 00120 const char *e2 = strstr(opt,"e2"); 00121 if (b1 && b2) 00122 printf("%s %s\n","SetCond","Cannot specify first and second derivative at first point"); 00123 if (e1 && e2) 00124 printf("%s %s\n","SetCond","Cannot specify first and second derivative at last point"); 00125 if (b1) fBegCond=1; 00126 else if (b2) fBegCond=2; 00127 if (e1) fEndCond=1; 00128 else if (e2) fEndCond=2; 00129 }
void TRadSpline::SetNpx | ( | int | n | ) | [inline, inherited] |
void TRadSpline3::Test | ( | ) | [static] |
Definition at line 132 of file TRadSpline.C.
References GetCoeff(), genRecEmupikp::i, ganga-rec::j, TRadSpline3(), and x.
00133 { 00134 // 00135 // Test method for TRadSpline5 00136 // 00137 // n number of data points. 00138 // m 2*m-1 is order of spline. 00139 // m = 2 always for third spline. 00140 // nn,nm1,mm, 00141 // mm1,i,k, 00142 // j,jj temporary integer variables. 00143 // z,p temporary double precision variables. 00144 // x[n] the sequence of knots. 00145 // y[n] the prescribed function values at the knots. 00146 // a[200][4] two dimensional array whose columns are 00147 // the computed spline coefficients 00148 // diff[3] maximum values of differences of values and 00149 // derivatives to right and left of knots. 00150 // com[3] maximum values of coefficients. 00151 // 00152 // 00153 // test of TRadSpline3 with nonequidistant knots and 00154 // equidistant knots follows. 00155 // 00156 // 00157 double hx; 00158 double diff[3]; 00159 double a[800], c[4]; 00160 int i, j, k, m, n; 00161 double x[200], y[200], z; 00162 int jj, mm; 00163 int mm1, nm1; 00164 double com[3]; 00165 printf("1 TEST OF TRadSpline3 WITH NONEQUIDISTANT KNOTS\n"); 00166 n = 5; 00167 x[0] = -3; 00168 x[1] = -1; 00169 x[2] = 0; 00170 x[3] = 3; 00171 x[4] = 4; 00172 y[0] = 7; 00173 y[1] = 11; 00174 y[2] = 26; 00175 y[3] = 56; 00176 y[4] = 29; 00177 m = 2; 00178 mm = m << 1; 00179 mm1 = mm-1; 00180 printf("\n-N = %3d M =%2d\n",n,m); 00181 TRadSpline3 *spline = new TRadSpline3("Test",x,y,n); 00182 for (i = 0; i < n; ++i) 00183 spline->GetCoeff(i,hx, a[i],a[i+200],a[i+400],a[i+600]); 00184 delete spline; 00185 for (i = 0; i < mm1; ++i) diff[i] = com[i] = 0; 00186 for (k = 0; k < n; ++k) { 00187 for (i = 0; i < mm; ++i) c[i] = a[k+i*200]; 00188 printf(" ---------------------------------------%3d --------------------------------------------\n",k+1); 00189 printf("%12.8f\n",x[k]); 00190 if (k == n-1) { 00191 printf("%16.8f\n",c[0]); 00192 } else { 00193 for (i = 0; i < mm; ++i) printf("%16.8f",c[i]); 00194 printf("\n"); 00195 for (i = 0; i < mm1; ++i) 00196 if ((z=fabs(a[k+i*200])) > com[i]) com[i] = z; 00197 z = x[k+1]-x[k]; 00198 for (i = 1; i < mm; ++i) 00199 for (jj = i; jj < mm; ++jj) { 00200 j = mm+i-jj; 00201 c[j-2] = c[j-1]*z+c[j-2]; 00202 } 00203 for (i = 0; i < mm; ++i) printf("%16.8f",c[i]); 00204 printf("\n"); 00205 for (i = 0; i < mm1; ++i) 00206 if (!(k >= n-2 && i != 0)) 00207 if((z = fabs(c[i]-a[k+1+i*200])) 00208 > diff[i]) diff[i] = z; 00209 } 00210 } 00211 printf(" MAXIMUM ABSOLUTE VALUES OF DIFFERENCES \n"); 00212 for (i = 0; i < mm1; ++i) printf("%18.9E",diff[i]); 00213 printf("\n"); 00214 printf(" MAXIMUM ABSOLUTE VALUES OF COEFFICIENTS \n"); 00215 if (fabs(c[0]) > com[0]) 00216 com[0] = fabs(c[0]); 00217 for (i = 0; i < mm1; ++i) printf("%16.8f",com[i]); 00218 printf("\n"); 00219 m = 2; 00220 for (n = 10; n <= 100; n += 10) { 00221 mm = m << 1; 00222 mm1 = mm-1; 00223 nm1 = n-1; 00224 for (i = 0; i < nm1; i += 2) { 00225 x[i] = i+1; 00226 x[i+1] = i+2; 00227 y[i] = 1; 00228 y[i+1] = 0; 00229 } 00230 if (n % 2 != 0) { 00231 x[n-1] = n; 00232 y[n-1] = 1; 00233 } 00234 printf("\n-N = %3d M =%2d\n",n,m); 00235 spline = new TRadSpline3("Test",x,y,n); 00236 for (i = 0; i < n; ++i) 00237 spline->GetCoeff(i,hx,a[i],a[i+200],a[i+400],a[i+600]); 00238 delete spline; 00239 for (i = 0; i < mm1; ++i) 00240 diff[i] = com[i] = 0; 00241 for (k = 0; k < n; ++k) { 00242 for (i = 0; i < mm; ++i) 00243 c[i] = a[k+i*200]; 00244 if (n < 11) { 00245 printf(" ---------------------------------------%3d --------------------------------------------\n",k+1); 00246 printf("%12.8f\n",x[k]); 00247 if (k == n-1) printf("%16.8f\n",c[0]); 00248 } 00249 if (k == n-1) break; 00250 if (n <= 10) { 00251 for (i = 0; i < mm; ++i) printf("%16.8f",c[i]); 00252 printf("\n"); 00253 } 00254 for (i = 0; i < mm1; ++i) 00255 if ((z=fabs(a[k+i*200])) > com[i]) 00256 com[i] = z; 00257 z = x[k+1]-x[k]; 00258 for (i = 1; i < mm; ++i) 00259 for (jj = i; jj < mm; ++jj) { 00260 j = mm+i-jj; 00261 c[j-2] = c[j-1]*z+c[j-2]; 00262 } 00263 if (n <= 10) { 00264 for (i = 0; i < mm; ++i) printf("%16.8f",c[i]); 00265 printf("\n"); 00266 } 00267 for (i = 0; i < mm1; ++i) 00268 if (!(k >= n-2 && i != 0)) 00269 if ((z = fabs(c[i]-a[k+1+i*200])) 00270 > diff[i]) diff[i] = z; 00271 } 00272 printf(" MAXIMUM ABSOLUTE VALUES OF DIFFERENCES \n"); 00273 for (i = 0; i < mm1; ++i) printf("%18.9E",diff[i]); 00274 printf("\n"); 00275 printf(" MAXIMUM ABSOLUTE VALUES OF COEFFICIENTS \n"); 00276 if (fabs(c[0]) > com[0]) 00277 com[0] = fabs(c[0]); 00278 for (i = 0; i < mm1; ++i) printf("%16.8E",com[i]); 00279 printf("\n"); 00280 } 00281 }
int TRadSpline3::fBegCond [private] |
double TRadSpline::fDelta [protected, inherited] |
Definition at line 6 of file TRadSpline.h.
Referenced by TRadSpline5::FindX(), FindX(), TRadSpline5::SaveAs(), SaveAs(), TRadSpline3(), and TRadSpline5::TRadSpline5().
int TRadSpline3::fEndCond [private] |
bool TRadSpline::fKstep [protected, inherited] |
Definition at line 10 of file TRadSpline.h.
Referenced by TRadSpline5::FindX(), FindX(), TRadSpline5::SaveAs(), and SaveAs().
int TRadSpline::fNp [protected, inherited] |
Definition at line 9 of file TRadSpline.h.
Referenced by TRadSpline5::BoundaryConditions(), TRadSpline5::BuildCoeff(), BuildCoeff(), TRadSpline5::FindX(), FindX(), TRadSpline5::SaveAs(), SaveAs(), TRadSpline5::SetBoundaries(), and TRadSpline5::TRadSpline5().
int TRadSpline::fNpx [protected, inherited] |
Definition at line 11 of file TRadSpline.h.
Referenced by TRadSpline::GetNpx(), and TRadSpline::SetNpx().
TRadSplinePoly3* TRadSpline3::fPoly [private] |
Definition at line 115 of file TRadSpline.h.
Referenced by BuildCoeff(), Derivative(), Eval(), FindX(), GetCoeff(), GetKnot(), SaveAs(), TRadSpline3(), and ~TRadSpline3().
double TRadSpline3::fValBeg [private] |
double TRadSpline3::fValEnd [private] |
double TRadSpline::fXmax [protected, inherited] |
Definition at line 8 of file TRadSpline.h.
Referenced by TRadSpline5::FindX(), FindX(), TRadSpline5::SaveAs(), and SaveAs().
double TRadSpline::fXmin [protected, inherited] |
Definition at line 7 of file TRadSpline.h.
Referenced by TRadSpline5::FindX(), FindX(), TRadSpline5::SaveAs(), SaveAs(), TRadSpline3(), and TRadSpline5::TRadSpline5().