33 inline double f3(
const double x,
const double y,
const double z)
35 return fx(x) * fy(y) * fz(z);
38 template<
class JKey_t,
class JValue_t,
class JDistance_t>
40 public JPolintMap<N, JKey_t, JValue_t, JGridMap,
41 JResultHesse<typename JResultType<JValue_t>::result_type>,
53 int main(
int argc,
char **argv)
65 JParser<> zap(
"Example program to test multi-dimensional interpolation.");
77 catch(
const exception &error) {
78 FATAL(error.what() << endl);
82 const double xmin = -1.0;
83 const double xmax = +1.0;
84 const double dx = (xmax - xmin) / (numberOfBins - 1);
91 JMap_t>::maplist JMaplist_t;
94 typedef JMultiFunction_t::result_type result_type;
99 for (
double x = xmin; x < xmax + 0.5*dx; x += dx) {
100 for (
double y = xmin; y < xmax + 0.5*dx; y += dx) {
101 for (
double z = xmin; z < xmax + 0.5*dx; z += dx) {
102 g3[x][y][z] =
f3(x,y,z);
111 if (numberOfEvents > 0) {
116 for (
int i = 0; i != numberOfEvents; ++i) {
118 const double x = gRandom->Uniform(xmin, xmax);
119 const double y = gRandom->Uniform(xmin, xmax);
120 const double z = gRandom->Uniform(xmin, xmax);
122 const result_type
result = g3(x,y,z);
124 const double v =
f3(x,y,z);
129 H[0][0].put(fx.getDerivative().getDerivative(x) * fy(y) * fz(z) -
result.fpp.f.f);
130 H[1][0].put(fx.getDerivative(x) * fy.getDerivative(y) * fz(z) -
result.fp.fp.f);
131 H[2][0].put(fx.getDerivative(x) * fy(y) * fz.getDerivative(z) -
result.fp.f.fp);
133 H[1][1].put(fx(x) * fy.getDerivative().getDerivative(y) * fz(z) -
result.f.fpp.f);
134 H[2][1].put(fx(x) * fy.getDerivative(y) * fz.getDerivative(z) -
result.f.fp.fp);
136 H[2][2].put(fx(x) * fy(y) * fz.getDerivative().getDerivative(z) -
result.f.f.fpp);
143 cout <<
"Hessian matrix" << endl;
145 for (
int i = 0; i != N; ++i) {
146 for (
int j = 0;
j <= i; ++
j) {
152 for (
int i = 0; i != N; ++i) {
153 for (
int j = 0;
j <= i; ++
j) {
163 for (
int i = 0; i != N; ++i) {
164 for (
int j = 0;
j <= i; ++
j) {
166 ASSERT(
H[i][
j].getSTDev() <= precision);
174 cout <<
"> " << flush;
178 if (
getline(cin, buffer) && !buffer.empty()) {
182 istringstream(buffer) >> x >> y >> z;
185 cout <<
f3(x,y,z) <<
' ' <<
get_value(g3(x,y,z)) << endl;
188 cout << exception << endl;