Commit b21fb00edc874a12fe6a9376337509107dcd5104

Authored by Olivier Mullier
1 parent 42f4baff

ajout d'exemples

Showing 3 changed files with 58 additions and 6 deletions   Show diff stats
src/integralii.cpp
... ... @@ -51,16 +51,25 @@ std::list<ibex::Interval *>& IntegralII::compute_list_of_zeros(ibex::Interval se
51 51 return *res;
52 52 }
53 53  
  54 +bool p_interval_compare(const ibex::Interval* a, const ibex::Interval* b)
  55 +{
  56 + return a->ub() < b->lb();
  57 +}
  58 +
54 59 std::list<ibex::Interval *>& IntegralII::compute_list_of_zeros_inf()
55 60 {
56 61 std::list<ibex::Interval *>& res = compute_list_of_zeros(_inf_endpoint);
57   - res.sort();
  62 + res.sort(p_interval_compare);
58 63 return res;
59 64 }
60 65  
61 66 std::list<ibex::Interval *>& IntegralII::compute_list_of_zeros_sup()
62 67 {
63   - return compute_list_of_zeros(_sup_endpoint);
  68 + std::list<ibex::Interval *>& res = compute_list_of_zeros(_sup_endpoint);
  69 +// for (auto * elem : res){
  70 +// cout << *elem << endl;
  71 +// }
  72 + return res;
64 73 }
65 74  
66 75  
... ...
src/integralrr.h
... ... @@ -21,7 +21,7 @@
21 21  
22 22 #include <ibex.h>
23 23  
24   -#define __EPS__ (1e-4)
  24 +#define __EPS__ (1e-5)
25 25  
26 26 /**
27 27 * @todo write docs
... ...
src/main.cpp
... ... @@ -2,15 +2,58 @@
2 2  
3 3 #include "integralii.h"
4 4  
5   -int main(){
6   - cout << setprecision(15);
  5 +void example1(){
7 6 ibex::Variable x(1);
8   - ibex::Function f(x, ibex::cos(x));
  7 + ibex::Function f(x, x*ibex::cos(x));
9 8 ibex::Interval inf_inter(0, 5);
10 9 ibex::Interval sup_inter(7, 15);
11 10  
12 11 IntegralII integ_inter(inf_inter, sup_inter, &f);
13 12 cout << "Result: " << endl;
14 13 cout << integ_inter << endl;
  14 +
  15 +
  16 + ibex::Function g(x, x*ibex::sin(x) + ibex::cos(x));
  17 + cout << "Calcul avec la solution analytique : " << g << endl;
  18 + ibex::IntervalVector x_vec(1), y_vec(1);
  19 + x_vec[0] = integ_inter.get_solution().first.get_inf_endpoint();
  20 + y_vec[0] = integ_inter.get_solution().first.get_sup_endpoint();
  21 +
  22 + cout << "\tmin : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
  23 +
  24 + x_vec[0] = integ_inter.get_solution().second.get_inf_endpoint();
  25 + y_vec[0] = integ_inter.get_solution().second.get_sup_endpoint();
  26 +
  27 + cout << "\tmax : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
  28 +}
  29 +
  30 +void example2(){
  31 + ibex::Variable x(1);
  32 + ibex::Function f(x, x*ibex::sin(x));
  33 + ibex::Interval inf_inter(0, 5);
  34 + ibex::Interval sup_inter(7, 15);
  35 +
  36 + IntegralII integ_inter(inf_inter, sup_inter, &f);
  37 + cout << "Result: " << endl;
  38 + cout << integ_inter << endl;
  39 +
  40 +
  41 + ibex::Function g(x, -x*ibex::cos(x) + ibex::sin(x));
  42 + cout << "Calcul avec la solution analytique : " << g << endl;
  43 + ibex::IntervalVector x_vec(1), y_vec(1);
  44 + x_vec[0] = integ_inter.get_solution().first.get_inf_endpoint();
  45 + y_vec[0] = integ_inter.get_solution().first.get_sup_endpoint();
  46 +
  47 + cout << "\tmin : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
  48 +
  49 + x_vec[0] = integ_inter.get_solution().second.get_inf_endpoint();
  50 + y_vec[0] = integ_inter.get_solution().second.get_sup_endpoint();
  51 +
  52 + cout << "\tmax : (" << x_vec << ", " << y_vec << ") : " << g.eval_vector(y_vec) - g.eval_vector(x_vec) << endl;
  53 +}
  54 +
  55 +int main(){
  56 + cout << setprecision(15);
  57 + example2();
15 58 return EXIT_SUCCESS;
16 59 }
... ...