QNANO
Integrable_Function.h
1 #ifndef QNANO_NEW_INTEGRABLE_FUNCTION_DEFINED_H
2 #define QNANO_NEW_INTEGRABLE_FUNCTION_DEFINED_H
3 
4 #include <cstdlib>
5 #include <cmath>
6 #include <vector>
7 #include <iostream>
8 
11 public:
13  double (*fct)(double *d, size_t dim, void *params);
14  size_t dim;
15  void *params;
16 
17  double evaluate(const std::vector<double> &vec) const{
18  return fct((double*) &vec[0], vec.size(), params);
19  }
20  double evaluate(double d) const{
21  return fct(&d, 1, params);
22  }
23 
24  Integrable_Function( double (*fct_)(double *d, size_t dim, void *params), size_t dim_, void *params_)
25  : fct(fct_), dim(dim_), params(params_){
26  }
27 };
28 
29 
32 public:
33  double a;
34 
35  static double f(double *x, size_t dim, void *params){
36  const IntFunc_exp *cl = (const IntFunc_exp*)params;
37  return exp(cl->a * x[0]);
38  }
39 
40  IntFunc_exp(double a_) : Integrable_Function(f, 1, this), a(a_){ }
41 
42 };
43 
44 
47 public:
48  const Integrable_Function * if1;
49  const Integrable_Function * if2;
50 
51  static double f(double *x, size_t dim, void *params){
53  return cl->if1->fct(x, dim, (void*)cl->if1)*cl->if2->fct(x, dim, (void*) cl->if2);
54 // return cl->if1->fct(x, dim, cl->if1->params)*cl->if2->fct(x, dim, cl->if2->params);
55  }
56 
58  : Integrable_Function(f, if1_->dim, this), if1(if1_), if2(if2_) {
59  if(if1->dim!=if2->dim){
60  std::cerr<<"Integrable_Function_Product: mismatch of dimension: "<<if1->dim<<" vs. "<<if2->dim<<std::endl;
61  exit(1);
62  }
63  }
64 };
65 
66 /*
67 Integrable_Function_Product operator*(const Integrable_Function *f1, const Integrable_Function *f2){
68  return Integrable_Function_Product(f1, f2);
69 }*/
70 
71 
72 #endif
double(* fct)(double *d, size_t dim, void *params)
Integrable Function compatible with GSL Vegas algorithm.
Definition: Integrable_Function.h:13
Example for integrable function with parameter exp(a*x):
Definition: Integrable_Function.h:31
Interface for integrable functions.
Definition: Integrable_Function.h:10
Build Integrable_Function from product of other Integrable_Functions:
Definition: Integrable_Function.h:46