synaps/usolve/SlvInterval.h

00001 #ifndef _SYNAPS_usolve_SlvInterval_H
00002 #define _SYNAPS_usolve_SlvInterval_H
00003 
00004 #include <vector>
00005 #include <synaps/init.h>
00006 #include <synaps/base/Seq.h>
00007 #include <synaps/arithm/Interval.h>
00008 
00009 __BEGIN_NAMESPACE_SYNAPS
00010 
00011 
00012 
00013 template < class X >
00014 struct SlvInterval
00015 {
00016   typedef SlvInterval  self_t;
00017   X eps; 
00018   SlvInterval():eps(1.e-6) {}  
00019   SlvInterval(const X& e):eps(e) {}
00020   SlvInterval(const self_t& mth): eps(mth.eps) {}
00021 };
00022 
00023 template<class T, class U>
00024 bool contains(const Interval<T>& I, const U& x)
00025 {
00026   return(I.inf()<= x && I.sup() >= x);
00027 }
00028 
00029 template<class T>
00030 Interval<T> pop(std::vector<Interval<T> >& LI)
00031 {
00032   Interval<T> I= LI[LI.size()-1];
00033   //  LI.resize(LI.size()-1);
00034   return I;
00035 }
00036 
00037 
00038 template<class UPOL, class C, class X> inline
00039 Seq< Interval<C> > 
00040 solve( const UPOL & f,
00041        const Interval<C>& U,
00042        const SlvInterval<X>& mth)
00043 {
00044   typedef Interval<C> interval_t;
00045   std::vector<interval_t> li;
00046   interval_t I,J;
00047   Seq<interval_t> res;
00048   li.push_back(U);
00049   C m;
00050   while(li.size())
00051     {
00052       I= pop(li);
00053       J = f(I);
00054       std::cout <<  J<<std::endl;
00055       if(contains(J,0))
00056         if(width(I)< mth.eps)
00057           res.push_back(I);
00058         else
00059           {
00060             m=median(I);
00061             li.push_back(interval_t(I.inf(),m));
00062             li.push_back(interval_t(m,I.sup()));
00063           }
00064     }
00065   return res;
00066 }
00067 
00068 __END_NAMESPACE_SYNAPS
00069 #endif // _SYNAPS_SOLVE_STURM_H_
00070 

SYNAPS DOCUMENTATION
logo