NESSi  v1.0.2
The NonEquilibrium Systems Simulation Library

◆ integrate()

template<typename T = double>
template<class M >
M integration::Integrator< T >::integrate ( const std::vector< M > &  f,
int  n 
)
inline

Integrates a function using Gregory quadrature.

Purpose

Computes the integral

\begin{align*} \int^{x_n}_0 dx \, f(x) = h\sum^{\mathrm{max}(k,m)}_{l=0} w_{n,l}\, f(x_l) \end{align*}

The function \(f\) represents any class M for which M=0 is defined.

Parameters
f

A standard vector of class M with at least lenght n+1.

n

The index of the upper integral bound.

Definition at line 474 of file integration.hpp.

474  {
475  int k1=k_+1,i,k2=2*k1,n1=n-k_;
476  T *w;
477  M sum=f[0];
478  sum=0;
479 
480  n1=(n<=k_ ? k_ : n);
481  assert( int(f.size()) >= n1);
482 
483  if( n>=k2 ){
484  n1=n-k_;
485  for(i=0;i<=k_;i++) sum += f[i]*gregory_omega_[i];
486  for(i=k1;i<n1;i++) sum += f[i];
487  for(i=n1;i<=n;i++) sum += f[i]*gregory_omega_[n-i];
488 }else if(n>0){
489  w=gregory_weights_ + n*k2;
490  for(i=0;i<=n1;i++) sum += f[i]*w[i];
491 }
492  return sum;
493 }