Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Olivier Mullier
interval_integrals
Commits
aed1ef30
Commit
aed1ef30
authored
Apr 03, 2019
by
Olivier Mullier
Browse files
version qui marche
parent
0c06be4a
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/integrale.cpp
View file @
aed1ef30
#include "integrale.h"
integrale
::
integrale
(
const
ibex
::
Interval
&
inf
,
const
ibex
::
Interval
&
sup
,
ibex
::
Function
*
f
,
ibex
::
Variable
*
var
)
:
_inf_bound
(
inf
),
_sup_bound
(
sup
),
_f
(
f
)
integrale
::
integrale
(
const
ibex
::
Interval
&
inf
,
const
ibex
::
Interval
&
sup
,
ibex
::
Function
*
f
)
:
_inf_bound
(
inf
),
_sup_bound
(
sup
),
_f
(
f
)
{
_zeros_inf
=
nullptr
;
_zeros_sup
=
nullptr
;
_result
=
nullptr
;
}
integrale
::~
integrale
()
{
if
(
_zeros_inf
)
delete
_zeros_inf
;
if
(
_zeros_sup
)
delete
_zeros_sup
;
if
(
_result
)
delete
_result
;
// if (_f)
// delete _f;
}
std
::
list
<
zero
*>
*
integrale
::
construct_zeros_intern
(
const
ibex
::
Interval
&
inf_bound
)
{
#ifdef __DEBUG__
__SHOW_FCT_NAME__
#endif
//ATTENTION pas de preuve d'unicité
//ATTENTION pas de
cout << elem << endl;
preuve d'unicité
std
::
list
<
zero
*>
*
res
=
new
std
::
list
<
zero
*>
();
ibex
::
CtcNewton
newton
(
*
_f
);
...
...
@@ -104,36 +117,45 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_inf(const ib
if
(
!
_zeros_inf
){
construct_zeros_inf
();
}
std
::
list
<
zero
*>::
iterator
it
=
_zeros_inf
->
begin
();
zero
*
bound_inf
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
integrale_sol
integ0
=
compute_integral
(
bound_inf
,
*
(
it
));
res_tmp
.
push_back
(
integ0
);
while
(
it
!=
_zeros_inf
->
end
()){
if
(
*
it
!=
_zeros_inf
->
back
()){
std
::
list
<
zero
*>::
iterator
it_first
=
it
;
it
++
;
std
::
list
<
zero
*>::
iterator
it_second
=
it
;
integrale_sol
integ
=
compute_integral
(
*
it_first
,
*
it_second
);
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_tmp
.
begin
();
while
(
it_tmp
!=
res_tmp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
if
(
_zeros_inf
->
size
()){
std
::
list
<
zero
*>::
iterator
it
=
_zeros_inf
->
begin
();
zero
*
bound_inf
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
integrale_sol
integ0
=
compute_integral
(
bound_inf
,
*
(
it
));
res_tmp
.
push_back
(
integ0
);
while
(
it
!=
_zeros_inf
->
end
()){
if
(
*
it
!=
_zeros_inf
->
back
()){
std
::
list
<
zero
*>::
iterator
it_first
=
it
;
it
++
;
std
::
list
<
zero
*>::
iterator
it_second
=
it
;
integrale_sol
integ
=
compute_integral
(
*
it_first
,
*
it_second
);
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_tmp
.
begin
();
while
(
it_tmp
!=
res_tmp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
}
res_tmp
.
push_back
(
integ
);
}
else
{
zero
*
bound
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
integrale_sol
integ
=
compute_integral
(
*
it
,
bound
);
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_tmp
.
begin
();
while
(
it_tmp
!=
res_tmp
.
end
()){
(
*
it_tmp
)
=
(
*
it_tmp
)
+
integ
;
it_tmp
++
;
}
it
++
;
res_tmp
.
push_back
(
integ
);
}
res_tmp
.
push_back
(
integ
);
}
else
{
zero
*
bound
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
integrale_sol
integ
=
compute_integral
(
*
it
,
bound
);
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_tmp
.
begin
();
while
(
it_tmp
!=
res_tmp
.
end
()){
(
*
it_tmp
)
=
(
*
it_tmp
)
+
integ
;
it_tmp
++
;
}
it
++
;
res_tmp
.
push_back
(
integ
);
}
}
else
{
zero
*
bound_sup
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
zero
*
bound_inf
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
integrale_sol
integ
=
compute_integral
(
bound_inf
,
bound_sup
);
res_tmp
.
push_back
(
integ
);
ibex
::
Interval
nul_inter
(
0.
);
integrale_sol
nul
(
bound_sup
,
bound_sup
,
nul_inter
);
res_tmp
.
push_back
(
nul
);
}
if
(
res_tmp
.
size
()
==
0
){
cout
<<
"Erreur, il devrait y avoir au moins une solution"
<<
endl
;
...
...
@@ -149,6 +171,14 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_inf(const ib
max
=
elem
;
}
}
for
(
auto
elem
:
res_tmp
){
if
(
elem
!=
min
||
elem
!=
max
){
if
(
elem
.
get_inf_bound
()
&&
!
elem
.
get_inf_bound
()
->
is_non_zero
())
delete
elem
.
get_inf_bound
();
if
(
elem
.
get_sup_bound
()
&&
!
elem
.
get_sup_bound
()
->
is_non_zero
())
delete
elem
.
get_sup_bound
();
}
}
return
pair
<
integrale_sol
,
integrale_sol
>
(
min
,
max
);
}
...
...
@@ -159,44 +189,45 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_sup(const ib
if
(
!
_zeros_sup
){
construct_zeros_sup
();
}
std
::
list
<
zero
*>::
iterator
it
=
_zeros_sup
->
begin
();
zero
*
bound_sup
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
// std::cout << "inf bound: " << *it << endl;
// std::cout << "sup bound: " << bound_sup << endl;
integrale_sol
integ0
=
compute_integral
((
*
it
),
bound_sup
);
res_temp
.
push_back
(
integ0
);
while
(
it
!=
_zeros_sup
->
end
()){
if
(
*
it
!=
_zeros_sup
->
back
()){
std
::
list
<
zero
*>::
iterator
it_second
=
it
;
it
++
;
std
::
list
<
zero
*>::
iterator
it_first
=
it
;
// std::cout << "inf bound: " << *it_first << endl;
// std::cout << "sup bound: " << *it_second << endl;
integrale_sol
integ
=
compute_integral
(
*
it_first
,
*
it_second
);
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_temp
.
begin
();
while
(
it_tmp
!=
res_temp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
if
(
_zeros_sup
->
size
()
>
0
){
std
::
list
<
zero
*>::
iterator
it
=
_zeros_sup
->
begin
();
zero
*
bound_sup
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
integrale_sol
integ0
=
compute_integral
((
*
it
),
bound_sup
);
res_temp
.
push_back
(
integ0
);
while
(
it
!=
_zeros_sup
->
end
()){
if
(
*
it
!=
_zeros_sup
->
back
()){
std
::
list
<
zero
*>::
iterator
it_second
=
it
;
it
++
;
std
::
list
<
zero
*>::
iterator
it_first
=
it
;
integrale_sol
integ
=
compute_integral
(
*
it_first
,
*
it_second
);
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_temp
.
begin
();
while
(
it_tmp
!=
res_temp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
}
res_temp
.
push_back
(
integ
);
}
else
{
zero
*
bound
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
integrale_sol
integ
=
compute_integral
(
bound
,
*
it
);
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_temp
.
begin
();
while
(
it_tmp
!=
res_temp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
}
it
++
;
res_temp
.
push_back
(
integ
);
}
res_temp
.
push_back
(
integ
);
}
else
{
// cout << "on passe ici" << endl;
zero
*
bound
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
// std::cout << "inf bound: " << bound << endl;
// std::cout << "sup bound: " << *it << endl;
integrale_sol
integ
=
compute_integral
(
bound
,
*
it
);
// cout << integ << endl;
std
::
list
<
integrale_sol
>::
iterator
it_tmp
=
res_temp
.
begin
();
while
(
it_tmp
!=
res_temp
.
end
()){
*
it_tmp
=
*
it_tmp
+
integ
;
it_tmp
++
;
}
it
++
;
res_temp
.
push_back
(
integ
);
}
}
else
{
zero
*
bound_sup
=
new
zero
(
ibex
::
Interval
(
range
.
ub
()),
0
);
zero
*
bound_inf
=
new
zero
(
ibex
::
Interval
(
range
.
lb
()),
0
);
integrale_sol
integ
=
compute_integral
(
bound_inf
,
bound_sup
);
res_temp
.
push_back
(
integ
);
ibex
::
Interval
nul_inter
(
0.
);
integrale_sol
nul
(
bound_inf
,
bound_inf
,
nul_inter
);
res_temp
.
push_back
(
nul
);
}
if
(
res_temp
.
size
()
==
0
){
cout
<<
"Erreur, il devrait y avoir au moins une solution"
<<
endl
;
...
...
@@ -205,7 +236,6 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_sup(const ib
integrale_sol
min
=
*
(
res_temp
.
begin
());
integrale_sol
max
=
*
(
res_temp
.
begin
());
for
(
auto
elem
:
res_temp
){
// cout << "\tcandidate : " << elem << endl;
if
(
elem
.
get_res_integrale
().
lb
()
<
min
.
get_res_integrale
().
lb
()){
min
=
elem
;
}
...
...
@@ -213,32 +243,29 @@ std::pair<integrale_sol, integrale_sol> integrale::compute_integral_sup(const ib
max
=
elem
;
}
}
for
(
auto
elem
:
res_temp
){
if
(
elem
!=
min
||
elem
!=
max
){
if
(
elem
.
get_inf_bound
()
&&
!
elem
.
get_inf_bound
()
->
is_non_zero
())
delete
elem
.
get_inf_bound
();
if
(
elem
.
get_sup_bound
()
&&
!
elem
.
get_sup_bound
()
->
is_non_zero
())
delete
elem
.
get_sup_bound
();
}
}
return
pair
<
integrale_sol
,
integrale_sol
>
(
min
,
max
);
}
std
::
pair
<
integrale_sol
,
integrale_sol
>
integrale
::
compute_integral
()
{
std
::
pair
<
integrale_sol
,
integrale_sol
>
res
=
compute_integral_inf
(
_inf_bound
);
// std::cout << "in inf : " << endl;
// std::cout << "\tmin : " << res.first << endl;
// std::cout << "\tmax : " << res.second << endl;
zero
*
inf
=
res
.
first
.
get_sup_bound
();
std
::
pair
<
integrale_sol
,
integrale_sol
>
res_sup
=
compute_integral_sup
(
_sup_bound
);
// std::cout << "in sup : " << endl;
// std::cout << "\tmin : " << res_sup.first << endl;
// std::cout << "\tmax : " << res_sup.second << endl;
zero
*
sup
=
res_sup
.
first
.
get_inf_bound
();
ibex
::
Interval
mid
=
compute_integral
(
_inf_bound
.
ub
(),
_sup_bound
.
lb
());
cout
<<
*
inf
<<
endl
;
cout
<<
*
sup
<<
endl
;
integrale_sol
integ_mid
(
inf
,
sup
,
mid
);
//
cout << "integrale mid : " << integ_mid << endl;
res
.
first
+=
integ_mid
;
res
.
second
+=
integ_mid
;
// std::cout << "mid : " << mid << endl;
res
.
first
+=
res_sup
.
first
;
res
.
second
+=
res_sup
.
second
;
if
(
_result
==
nullptr
){
...
...
src/integrale.h
View file @
aed1ef30
...
...
@@ -9,7 +9,7 @@
#define __PREC__ (1e-
3
)
#define __PREC__ (1e-
5
)
#define __EPS__ (1e-1)
#define __SHOW_FCT_NAME__ {std::cout << __func__ << std::endl;}
...
...
@@ -22,7 +22,7 @@ private:
ibex
::
Interval
_sup_bound
;
ibex
::
Function
*
_f
;
ibex
::
Variable
*
_x_var
;
//
ibex::Variable * _x_var;
std
::
list
<
zero
*>
*
_zeros_inf
;
std
::
list
<
zero
*>
*
_zeros_sup
;
...
...
@@ -43,13 +43,14 @@ private:
public:
//CONSTRUCTORS
integrale
(
const
ibex
::
Interval
&
inf
,
const
ibex
::
Interval
&
sup
,
ibex
::
Function
*
f
,
ibex
::
Variable
*
var
);
integrale
(
const
ibex
::
Interval
&
inf
,
const
ibex
::
Interval
&
sup
,
ibex
::
Function
*
f
);
~
integrale
();
//GETTERS
inline
ibex
::
Interval
get_inf_bound
()
const
{
return
_inf_bound
;};
inline
ibex
::
Interval
get_sup_bound
()
const
{
return
_sup_bound
;};
inline
ibex
::
Function
*
get_f
()
const
{
return
_f
;};
inline
ibex
::
Variable
*
get_x_var
()
const
{
return
_x_var
;};
//
inline ibex::Variable * get_x_var() const {return _x_var;};
inline
std
::
list
<
zero
*>
*
get_zeros_inf
(){
return
_zeros_inf
;};
inline
std
::
list
<
zero
*>
*
get_zeros_sup
(){
return
_zeros_sup
;};
inline
std
::
pair
<
integrale_sol
,
integrale_sol
>
*
get_result
(){
return
_result
;};
...
...
src/integrale_sol.cpp
View file @
aed1ef30
...
...
@@ -32,6 +32,15 @@ integrale_sol::integrale_sol(zero* inf, zero* sup, const ibex::Interval& res) :
}
}
integrale_sol
::~
integrale_sol
()
{
// if (_inf)
// delete _inf;
// if (_sup)
// delete _sup;
}
integrale_sol
&
integrale_sol
::
operator
+=
(
const
integrale_sol
&
rhs
){
*
this
=
*
this
+
rhs
;
return
*
this
;
...
...
@@ -39,12 +48,11 @@ integrale_sol & integrale_sol::operator+=(const integrale_sol &rhs){
integrale_sol
operator
+
(
const
integrale_sol
&
lhs
,
const
integrale_sol
&
rhs
)
{
if
(
lhs
.
get_sup_bound
()
==
rhs
.
get_inf_bound
()){
// cout << "ici" << endl;
return
integrale_sol
(
&*
lhs
.
get_inf_bound
(),
&*
rhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
return
integrale_sol
(
lhs
.
get_inf_bound
(),
rhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
}
else
{
// cout << "la" << endl;
return
integrale_sol
(
&*
rhs
.
get_inf_bound
(),
&*
lhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
return
integrale_sol
(
rhs
.
get_inf_bound
(),
lhs
.
get_sup_bound
(),
(
lhs
.
get_res_integrale
()
+
rhs
.
get_res_integrale
()));
}
}
...
...
@@ -54,3 +62,15 @@ std::ostream & operator<<(std::ostream& os, const integrale_sol& inte)
os
<<
"Integral from ("
<<
*
(
inte
.
get_inf_bound
())
<<
") to ("
<<
*
inte
.
get_sup_bound
()
<<
") : "
<<
inte
.
get_res_integrale
();
return
os
;
}
bool
operator
==
(
const
integrale_sol
&
lhs
,
const
integrale_sol
&
rhs
)
{
return
(
lhs
.
get_inf_bound
()
==
rhs
.
get_inf_bound
()
&&
lhs
.
get_sup_bound
()
==
rhs
.
get_sup_bound
());
}
bool
operator
!=
(
const
integrale_sol
&
lhs
,
const
integrale_sol
&
rhs
)
{
return
!
(
lhs
==
rhs
);
}
src/integrale_sol.h
View file @
aed1ef30
...
...
@@ -35,6 +35,7 @@ private:
public:
integrale_sol
(
zero
*
inf
,
zero
*
sup
,
const
ibex
::
Interval
&
res
);
~
integrale_sol
();
inline
zero
*
get_inf_bound
()
const
{
return
_inf
;};
inline
zero
*
get_sup_bound
()
const
{
return
_sup
;};
...
...
@@ -49,6 +50,8 @@ public:
};
integrale_sol
operator
+
(
const
integrale_sol
&
,
const
integrale_sol
&
);
bool
operator
==
(
const
integrale_sol
&
,
const
integrale_sol
&
);
bool
operator
!=
(
const
integrale_sol
&
,
const
integrale_sol
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
integrale_sol
&
inte_sol
);
#endif // INTEGRALE_SOL_H
src/main.cpp
View file @
aed1ef30
...
...
@@ -8,16 +8,17 @@ using namespace std;
void
example
(){
cout
<<
setprecision
(
15
);
ibex
::
Variable
x
(
1
);
ibex
::
Function
f
(
x
,
ibex
::
sin
(
x
));
ibex
::
Function
f
(
x
,
-
15.
+
x
+
5.
*
ibex
::
sin
(
x
));
ibex
::
Interval
inf
(
0.
,
5.5
);
ibex
::
Interval
sup
(
10
,
15.
);
integrale
example
(
inf
,
sup
,
&
f
,
&
x
);
integrale
example
(
inf
,
sup
,
&
f
);
cout
<<
example
<<
endl
;
example
.
construct_zeros
();
for
(
auto
elem
:
*
example
.
get_zeros_sup
()){
cout
<<
elem
<<
endl
;
cout
<<
*
elem
<<
endl
<<
endl
;
}
example
.
compute_integral
();
cout
<<
"minimum: "
<<
example
.
get_result
()
->
first
<<
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment