MUQ  0.4.3
HermiteFunction.cpp
Go to the documentation of this file.
2 
3 #include <cmath>
4 
5 using namespace muq::Approximation;
6 
7 unsigned HermiteFunction::nChoosek( unsigned n, unsigned k )
8 {
9  if (k > n) return 0;
10  if (k * 2 > n) k = n-k;
11  if (k == 0) return 1;
12 
13  int result = n;
14  for( int i = 2; i <= k; ++i ) {
15  result *= (n-i+1);
16  result /= i;
17  }
18  return result;
19 }
20 
21 double HermiteFunction::BasisEvaluate(int const order, double const x) const
22 {
23  double scaling = std::pow( std::pow(2, order) *
24  std::tgamma(order+1) *
25  std::sqrt(M_PI), -0.5) * std::exp(-0.5*x*x);
26 
27  return scaling * polyBase->BasisEvaluate(order, x);
28 }
29 
30 
31 double HermiteFunction::DerivativeEvaluate(int const polyOrder,
32  int const derivOrder,
33  double const x) const
34 {
35  if(derivOrder>polyOrder)
36  return 0.0;
37 
38  if(derivOrder==1){
39  return std::sqrt(0.5*polyOrder) * BasisEvaluate(polyOrder-1,x) +
40  std::sqrt(0.5*(polyOrder+1)) * BasisEvaluate(polyOrder+1,x);
41  }
42 
43  double result = 0.0;
44 
45  double nfact = std::tgamma(polyOrder + 1);
46 
47  for(int i=0; i<=derivOrder; ++i){
48  result += nChoosek(derivOrder, i) * std::pow(2, 0.5*(derivOrder-i)) *
49  std::sqrt(nfact / std::tgamma(polyOrder - derivOrder + i + 1)) *
50  BasisEvaluate(polyOrder-derivOrder+i, x) * polyBase->BasisEvaluate(i, x);
51  }
52 
53  return result;
54 }
virtual double BasisEvaluate(int const order, double const x) const override
Evaluate the hermite function.
std::shared_ptr< PhysicistHermite > polyBase
static unsigned nChoosek(unsigned n, unsigned k)
virtual double DerivativeEvaluate(int const polyOrder, int const derivOrder, double const x) const override