To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

main.cpp 663 Bytes
Newer Older
Erick Turricelli's avatar
Erick Turricelli committed
1
2
3
4
5
#include <iostream>
#include <cmath>
#include "integration.hpp"
#define _USE_MATH_DEFINES

6
const double my_sin(double x) {
Erick Turricelli's avatar
Erick Turricelli committed
7
8
9
    return sin(x);
}

10
11
12
13
const double test_func(double x) {
    return x*(1-x);
}

Erick Turricelli's avatar
Erick Turricelli committed
14
15
16
17
18
19
20
21
22
int main() {

    std::cout << "Integral of sin(x) in [0,pi] is " << integration(0.0, M_PI, 100, my_sin) << "\n";
    int max_bins = 10;
    std::cout << "Different bins\n";
    for ( int i = 1; i < max_bins; i++) {
        std::cout << i << "   " << integration(0.0, M_PI, i, my_sin) << "\n";
    }

23
24
25
    std::cout << "Test simpson rule \n";
    std::cout << "Integral of x*(1-x) in [0, 1] is " << integration(0.0, 1.0, 55, test_func) << "\n";

Erick Turricelli's avatar
Erick Turricelli committed
26
27
    return 0;
}