File: GaussHermite_Demo.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (30 lines) | stat: -rw-r--r-- 794 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Demonstrates usage of the Gauss-Hermite nodes and weights
// generated by our program GaussHermite_NodesWeights.cpp.
//
// Joachim Wuttke, 2023, public domain

#include "GaussHermiteConstants.cpp"
#include <cmath>
#include <iostream>
#include <iomanip>

// With f(x)=cos(x), analytical integration yields exp(-1/4).
// See https://www.chebfun.org/examples/quad/HermiteQuad.html, with different normalization.
double f(double x)
{
    return cos(x);
}

int main(int argc, char* argv[])
{
    std::cout << std::setprecision(15);
    for (int n=0; n<12; ++n) {

        double sum = 0;
        for (int i = 0; i<n; ++i) {
            int k = n * (n-1) + 2*i;
            sum += GaussHermiteNodesWeights[k+1] * f(GaussHermiteNodesWeights[k]);
        }
        std::cout << sum << "\n";
    }
}