descartes_solver< real_t, local_method > Class Template Reference

#include <system_descartes1d.hpp>

List of all members.

Public Member Functions

Public Attributes


Detailed Description

template<class real_t, class local_method = bsearch< real_t >>
class mmx::solvers::descartes_solver< real_t, local_method >

Definition at line 303 of file system_descartes1d.hpp.


Constructor & Destructor Documentation

descartes_solver ( unsigned  sz,
const real_t &  eps = 1e-12 
) [inline]

Definition at line 426 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_lmth, descartes_solver< real_t, local_method >::m_prec, descartes_solver< real_t, local_method >::m_stck, and descartes_solver< real_t, local_method >::m_sz.

00427     {
00428       m_stck = 0;
00429       m_sz   = sz;
00430       m_prec = eps;
00431       m_lmth = 0;
00432       unsigned maxdeep = 1;
00433       real_t ex = 1;
00434       while ( ex > m_prec ) { ex/=2; maxdeep ++ ; };
00435       //      std::cout << maxdeep << std::endl;
00436       maxdeep ++;
00437       maxdeep *= 3;
00438       unsigned tsz = maxdeep*(2+m_sz);
00439       m_stck = new real_t[ tsz ];
00440     };

~descartes_solver (  )  [inline]

Definition at line 442 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_stck.

00442                         { 
00443       delete[] m_stck; 
00444     };


Member Function Documentation

void output ( Prms &  prms,
real_t *  stck 
) [inline]

Definition at line 376 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::output().

Referenced by descartes_solver< real_t, local_method >::output().

00377     { output( prms, stck, sign_wanted< Prms >::result_t() ); };

void output ( Prms &  prms,
real_t *  stck,
const texp::false_t  
) [inline]

Definition at line 372 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_sz.

00373     { prms.output( stck[m_sz], stck[m_sz+1] ); };

void output ( Prms &  prms,
real_t *  stck,
const texp::true_t  
) [inline]

Definition at line 369 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_sz.

Referenced by descartes_solver< real_t, local_method >::solve().

00370     { prms.output( stck[m_sz], stck[m_sz+1], stck[0] > 0, stck[m_sz-1] > 0 ); };

real_t precision ( real_t *  l  )  [inline]

Definition at line 332 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_sz.

Referenced by descartes_solver< real_t, local_method >::solve().

00332 { return l[m_sz+1]-l[m_sz] ; };

bool precision_reached ( real_t *  l  )  [inline]
void reset ( unsigned  sz,
const real_t &  prec 
) [inline]

Definition at line 312 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_prec, and descartes_solver< real_t, local_method >::m_sz.

00313     {
00314       if ( sz <= m_sz && prec >= m_prec ) 
00315         {
00316           m_sz = sz;
00317           m_prec = prec;
00318           return;
00319         };
00320       m_sz = sz; m_prec = prec; 
00321       this->alloc();
00322     };

void rockwoodcuts ( real_t *  nxt,
real_t *  prv,
real_t *  mid 
) [inline]

Definition at line 345 of file system_descartes1d.hpp.

References mmx::brnops::decasteljau(), descartes_solver< real_t, local_method >::m_sz, and mmx::brnops::rockwood_cut().

00346     {
00347       //      [-------------] b
00348       //      [---][--------] b 
00349       //      [---][---][---] b
00350       real_t i0, i1;
00351       brnops::rockwood_cut( i0, nxt, m_sz );
00352       brnops::rockwood_cut( i1, nxt+m_sz-1, m_sz, -1 );
00353       std::cout << i0 << ", " << (1.0-i1) << std::endl;
00354       i1 = (1.0-i1);
00355       brnops::decasteljau(nxt,prv,m_sz,i0);
00356       brnops::decasteljau(nxt,mid,m_sz,(i1-i0)/(1.0-i0));
00357       i0 = (1.0-i0)*nxt[m_sz] + i0*nxt[m_sz+1];
00358       i1 = (1.0-i1)*nxt[m_sz] + i1*nxt[m_sz+1];
00359       prv[m_sz]   = nxt[m_sz];
00360       prv[m_sz+1] = i0;
00361       mid[m_sz]   = i0;
00362       mid[m_sz+1] = i1;
00363       nxt[m_sz]   = i1;
00364     };

void set_sz ( unsigned  sz  )  [inline]

Definition at line 366 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_sz.

00366 { m_sz = sz;};

unsigned solve ( Prms &  prms,
const In &  in,
int  option = 0 
) [inline]

Definition at line 380 of file system_descartes1d.hpp.

References descartes_solver< real_t, local_method >::m_lmth, descartes_solver< real_t, local_method >::m_prec, descartes_solver< real_t, local_method >::m_stck, descartes_solver< real_t, local_method >::m_sz, descartes_solver< real_t, local_method >::output(), descartes_solver< real_t, local_method >::precision(), mmx::realroot::sgn(), mmx::vctops::sgncnt(), and descartes_solver< real_t, local_method >::split().

00381     {
00382       for ( unsigned i = 0; i < m_sz; i ++ )  m_stck[i] = in[i]; 
00383       m_stck[m_sz] = 0.0; m_stck[m_sz+1] = 1.0;
00384       unsigned    roots = 0;
00385       const unsigned    inc  = m_sz+2;
00386       real_t * stck = m_stck;
00387       real_t * stop = stck-inc;
00388       do
00389         {
00390           unsigned sgn = vctops::sgncnt(stck,m_sz);
00391           switch( sgn )
00392             {
00393             case 0:
00394               stck -= inc;
00395               break;
00396             case 1:
00397               roots ++;
00398               if ( !option || (roots == option) )
00399                 {
00400                   if ( m_lmth == 0 ) m_lmth = new local_method(in,m_sz);
00401                   m_lmth->reach( stck, stck[m_sz], stck[m_sz+1], m_prec );
00402                   output( prms, stck );
00403                 };
00404               stck -= inc;
00405               break;
00406             default:
00407               if(  precision( stck ) < m_prec  )
00408                 { 
00409                   roots++; 
00410                   if ( !option || (roots == option) ) output(prms,stck);
00411                   stck -= inc;
00412                   break;
00413                 };
00414               split(stck);
00415               stck += inc;
00416               break;
00417             }
00418         }
00419       while( stck != stop  );
00420       if ( m_lmth ) { delete m_lmth; m_lmth = 0; };
00421       return roots;
00422     };

void split ( real_t *  r  )  [inline]

Definition at line 324 of file system_descartes1d.hpp.

References mmx::brnops::decasteljau(), and descartes_solver< real_t, local_method >::m_sz.

Referenced by descartes_solver< real_t, local_method >::solve().

00325     {
00326       real_t * l = r+m_sz+2;
00327       brnops::decasteljau(r,l,m_sz);
00328       l[m_sz]   = r[m_sz];
00329       l[m_sz+1] = (r[m_sz]+r[m_sz+1])/2.0;
00330       r[m_sz]   = l[m_sz+1];
00331     };


Member Data Documentation

local_method* m_lmth
real_t m_prec
unsigned m_ssz

Definition at line 306 of file system_descartes1d.hpp.

real_t* m_stck
unsigned m_sz

The documentation for this class was generated from the following file:

Generated on 6 Dec 2012 for realroot by  doxygen 1.6.1