MUQ  0.4.3
GaussQuadrature.cpp
Go to the documentation of this file.
2 
3 using namespace muq::Approximation;
4 
6 
7 GaussQuadrature::GaussQuadrature(std::shared_ptr<OrthogonalPolynomial> polyIn) : Quadrature(1),
8  poly(polyIn), polyOrder(-1)
9 {
10 }
11 
12 GaussQuadrature::GaussQuadrature(std::shared_ptr<OrthogonalPolynomial> polyIn,
13  int polyOrderIn) : Quadrature(1),
14  poly(polyIn), polyOrder(polyOrderIn)
15 {
16  Compute(polyOrderIn);
17 }
18 
19 void GaussQuadrature::Compute(unsigned int order) {
20 
21  polyOrder = order+1;
22 
23  // Create diagonal and subdiagonal vectors
24  Eigen::VectorXd diag = Eigen::VectorXd::Zero(polyOrder);
25  Eigen::VectorXd subdiag = Eigen::VectorXd::Zero(polyOrder);
26 
27  for (unsigned int i=1; i<polyOrder+1; i++) {
28 
29  // Calling ak, bk, ad ck correctly?
30  double alpha_i = -poly->bk(i)/poly->ak(i);
31  double beta_i = std::sqrt(poly->ck(i+1)/(poly->ak(i)*poly->ak(i+1)));
32 
33  // Diagonal entry of J
34  diag(i-1) = alpha_i;
35 
36  // Off diagonal entries of J
37  if (i < polyOrder)
38  subdiag(i-1) = beta_i;
39 
40  }
41 
42  Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es;
43  es.computeFromTridiagonal(diag, subdiag);
44 
45  // Set gauss points
46  pts = es.eigenvalues().transpose();
47 
48  // Get mu_0 value (integral of weighting function)
49  double mu0 = poly->Normalization(0);
50 
51  // Set gauss weights
52  wts = mu0*es.eigenvectors().row(0).array().square();
53 
54 }
virtual void Compute(unsigned int quadOrder) override
std::shared_ptr< OrthogonalPolynomial > poly
Base class for multivariate quadrature rules. @detail An abstract class for computing nodes and weigh...
Definition: Quadrature.h:124