20#ifndef GAUSSIAN_QUADRATUR_H_
21#define GAUSSIAN_QUADRATUR_H_
23#include <fmatvec/fmatvec.h>
24#include <mbsim/functions/function.h>
26#include <mbsim/mbsim_event.h>
30 static double transformVariablePosition(
double x,
double l,
double u) {
31 return (u - l) / 2. * x + (l + u) / 2.;
39 static double pW[15][2] = {{0., 2.}, {-0.57735026919, 1.}, {0.57735026919, 1}, {-0.774596669241, 5. / 9.}, {0., 8. / 9}, {0.774596669241, 5. / 9.}, {-0.861136311594053, 0.347854845137454}, {-0.339981043584856, 0.652145154862546}, {0.339981043584856, 0.652145154862546}, {0.861136311594053, 0.347854845137454}, {-0.906179845938664, 0.236926885056189}, {-0.538469310105683, 0.478628670499366}, {0, 0.568888888888889}, {0.538469310105683, 0.478628670499366}, {0.906179845938664, 0.236926885056189}};
60 Ret result(
dim, fmatvec::INIT, 0.);
63 result += integrateSingle(currLow, currLow + step);
71 void setSubIntegrals(
int subInts_) {
96 const Ret integrateSingle(
double l,
double u) {
98 throw std::runtime_error(
"It is not possible to use more than 5 Gauss-Points atm!");
102 for (
unsigned int i = 1; i <
Nb; i++) {
106 Ret result(
dim, fmatvec::INIT, 0.);
107 for (
unsigned int i = 0; i <
Nb; i++) {
108 int index = i + posInpW;
109 double p = transformVariablePosition(pW[index][0], l, u);
110 double w = pW[index][1];
111 result += w * (*function)(p);
114 return (u - l) / 2. * result;
118 namespace GaussTschebyschowQuadrature {
129 const Ret integrate(fmatvec::Function<Ret(
double)> * function,
double l,
double u,
size_t Nb = 3) {
130 Ret result((*function)(l).size(), fmatvec::INIT, 0.);
131 for (
size_t i = 0; i < Nb; i++) {
132 double x = cos((2. * i - 1) / (2. * Nb) * M_PI);
133 double p = transformVariablePosition(x, l, u);
134 result += sqrt(1 - x * x) * (*function)(p);
137 return (u - l) / 2. * M_PI / Nb * result;
Definition: gaussian_quadratur.h:42
const Ret integrate(double l, double u)
function to integrate a MBSim-Function numerically using the gaussian quadrature
Definition: gaussian_quadratur.h:56
int dim
dimension of the result
Definition: gaussian_quadratur.h:83
size_t Nb
number of gauss points that should be used
Definition: gaussian_quadratur.h:93
fmatvec::Function< Ret(double)> * function
function to integrate
Definition: gaussian_quadratur.h:78
size_t subIntegrals
number of integrals the original one should be split to
Definition: gaussian_quadratur.h:88
namespace MBSim
Definition: bilateral_constraint.cc:30