main.cpp 2.04 KB
Newer Older
Olivier Mullier's avatar
Olivier Mullier committed
1
#include <iostream>
Olivier Mullier's avatar
Olivier Mullier committed
2

Olivier Mullier's avatar
Olivier Mullier committed
3
#include "integralii.h"
Olivier Mullier's avatar
Olivier Mullier committed
4

Olivier Mullier's avatar
Olivier Mullier committed
5
void example1(){
Olivier Mullier's avatar
Olivier Mullier committed
6
    ibex::Variable x(1);
Olivier Mullier's avatar
Olivier Mullier committed
7
    ibex::Function f(x, x*ibex::cos(x));
Olivier Mullier's avatar
Olivier Mullier committed
8
    ibex::Interval inf_inter(0, 5);
9
    ibex::Interval sup_inter(7, 15);
Olivier Mullier's avatar
Olivier Mullier committed
10
    
Olivier Mullier's avatar
Olivier Mullier committed
11
12
13
    IntegralII integ_inter(inf_inter, sup_inter, &f);
    cout << "Result: " << endl;
    cout << integ_inter << endl;
Olivier Mullier's avatar
Olivier Mullier committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    
    
    ibex::Function g(x, x*ibex::sin(x) + ibex::cos(x));
    cout << "Calcul avec la solution analytique : " << g << endl;
    ibex::IntervalVector x_vec(1), y_vec(1);
    x_vec[0] = integ_inter.get_solution().first.get_inf_endpoint();
    y_vec[0] = integ_inter.get_solution().first.get_sup_endpoint();
    
    cout << "\tmin : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
    
    x_vec[0] = integ_inter.get_solution().second.get_inf_endpoint();
    y_vec[0] = integ_inter.get_solution().second.get_sup_endpoint();
    
    cout << "\tmax : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
}

void example2(){
    ibex::Variable x(1);
    ibex::Function f(x, x*ibex::sin(x));
    ibex::Interval inf_inter(0, 5);
    ibex::Interval sup_inter(7, 15);
    
    IntegralII integ_inter(inf_inter, sup_inter, &f);
    cout << "Result: " << endl;
    cout << integ_inter << endl;
    
    
    ibex::Function g(x, -x*ibex::cos(x) + ibex::sin(x));
    cout << "Calcul avec la solution analytique : " << g << endl;
    ibex::IntervalVector x_vec(1), y_vec(1);
    x_vec[0] = integ_inter.get_solution().first.get_inf_endpoint();
    y_vec[0] = integ_inter.get_solution().first.get_sup_endpoint();
    
    cout << "\tmin : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
    
    x_vec[0] = integ_inter.get_solution().second.get_inf_endpoint();
    y_vec[0] = integ_inter.get_solution().second.get_sup_endpoint();
    
    cout << "\tmax : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
}

int main(){
    cout << setprecision(15);
    example2();
Olivier Mullier's avatar
Olivier Mullier committed
58
59
    return EXIT_SUCCESS;
}