42 result_type(
const double __f,
58 operator double()
const
95 inline result_type operator()(
const double x,
99 return result_type(f (x) * f (y) * f (z),
100 fp(x) * f (y) * f (z),
101 f (x) * fp(y) * f (z),
102 f (x) * f (y) * fp(z));
113 inline double f(
const double x)
const
115 return __f1.getValue(x);
125 inline double fp(
const double x)
const
127 return __f1.getDerivative(x);
137 template<
class JMultiFunction_t>
138 int do_main(
int argc,
char **argv,
const char* title)
149 JParser<> zap(
"Example program to test multi-dimensional interpolation with derivatives.");
158 catch(
const exception &error) {
159 FATAL(error.what() << endl);
163 if (numberOfEvents <= 0) {
FATAL(
"Number of events " << numberOfEvents << endl); }
164 if (numberOfBins <= 2) {
FATAL(
"Number of bins " << numberOfBins << endl); }
169 const JFunction3D
f3(f1);
171 const double xmin = -1.0;
172 const double xmax = +1.0;
173 const double dx = (xmax - xmin) / (numberOfBins - 1);
178 for (
double x = xmin; x < xmax + 0.5*dx; x += dx) {
179 for (
double y = xmin; y < xmax + 0.5*dx; y += dx) {
180 for (
double z = xmin; z < xmax + 0.5*dx; z += dx) {
181 g3[x][y][z] =
f3(x,y,z);
195 for (
int i = 0; i != numberOfEvents; ++i) {
197 const double x = gRandom->Uniform(xmin, xmax);
198 const double y = gRandom->Uniform(xmin, xmax);
199 const double z = gRandom->Uniform(xmin, xmax);
201 const JFunction3D ::result_type
u =
f3(x,y,z);
202 const typename JMultiFunction_t::result_type
v = g3(x,y,z);
204 f .put(
u.f -
v.f .f .f);
205 fx.put(
u.fx -
v.fp.f .f);
206 fy.put(
u.fy -
v.f .fp.f);
207 fz.put(
u.fz -
v.f .f .fp);
210 cout << endl << title <<
":" << endl;
212 for (
const JQuantile* buffer[] = { &f, &fx, &fy, &fz, NULL }, **p = buffer; *p != NULL; ++p) {
213 (*p)->print(cout, *p == &f);
226 int main(
int argc,
char **argv)
237 if (do_main<JMultiFunction_t>(argc, argv,
"Polint") != 0)
return 1;
246 if (do_main<JMultiFunction_t>(argc, argv,
"Spline") != 0)
return 1;