Geomi
GaussLegendre.hpp
1 #ifndef DEF_INTERPOLATION_GAUSSLEGENDRE
2 #define DEF_INTERPOLATION_GAUSSLEGENDRE
3 
4 #include <vector>
5 #include <cmath>
6 
8 {
9 private:
10  /* coeffs given for [-1,1] interpolation */
11  static const double GL_WEIGHTS[];
12  static const double GL_DATES[];
13  static const int MAX_DEGREE = 5;
14 
15 public:
16  static std::vector<double>
17  weights (int degree)
18  {
19  if (degree>MAX_DEGREE)
20  return std::vector<double>();
21  std::vector<double> ret;
22  // translate from [-1,1] to [0,1] interpolation
23  for (int i=0; i<degree; i++) {
24  ret.push_back(GL_WEIGHTS[((degree*(degree-1))/2)+i]/2.0);
25  }
26  return ret;
27  }
28 
29  static std::vector<double>
30  dates (int degree)
31  {
32  if (degree>MAX_DEGREE)
33  return std::vector<double>();
34  std::vector<double> ret;
35  // translate from [-1,1] to [0,1] interpolation
36  for (int i=0; i<degree; i++) {
37  ret.push_back((GL_DATES[((degree*(degree-1))/2)+i]/2.0)+0.5);
38  }
39  return ret;
40  }
41 };
42 
43 const double GaussLegendre::GL_WEIGHTS[] = {
44  2.0,
45  1.0,1.0,
46  5.0/9.0,8.0/9.0,5.0/9.0,
47  (18.0-sqrt(30.0))/36.0,(18.0+sqrt(30.0))/36.0,(18.0+sqrt(30.0))/36.0,(18.0-sqrt(30.0))/36.0,
48  (322.0-13.0*sqrt(70.0))/900.0,(322.0+13.0*sqrt(70.0))/900.0,128.0/225.0,(322.0+13.0*sqrt(70.0))/900.0,(322.0-13.0*sqrt(70.0))/900.0 };
49 const double GaussLegendre::GL_DATES[] = {
50  0.0,
51  -1.0/sqrt(3),1.0/sqrt(3),
52  -sqrt(3.0/5.0),0.0,sqrt(3.0/5.0),
53  -sqrt((3.0/7.0)+(2.0/7.0)*sqrt(6.0/5.0)),-sqrt((3.0/7.0)-(2.0/7.0)*sqrt(6.0/5.0)),sqrt((3.0/7.0)-(2.0/7.0)*sqrt(6.0/5.0)),sqrt((3.0/7.0)+(2.0/7.0)*sqrt(6.0/5.0)),
54  -(1.0/3.0)*sqrt(5.0+2.0*sqrt(10.0/7.0)),-(1.0/3.0)*sqrt(5.0-2.0*sqrt(10.0/7.0)),0.0,(1.0/3.0)*sqrt(5.0-2.0*sqrt(10.0/7.0)),(1.0/3.0)*sqrt(5.0+2.0*sqrt(10.0/7.0))};
55 
56 #endif
Definition: GaussLegendre.hpp:7