Changeset 19 for bdm/stat/libFN.h

Show
Ignore:
Timestamp:
02/16/08 15:12:24 (16 years ago)
Author:
smidl
Message:

Switch to CMake

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libFN.h

    r15 r19  
    22// C++ Interface: itpp_ext 
    33// 
    4 // Description:  
     4// Description: 
    55// 
    66// 
     
    1414 
    1515using namespace itpp; 
    16   
    17 class constfn : public fnc { 
    18         RV rv; 
    19         ivec indexlist; // needed by evalsome 
    20         vec val; 
    2116 
    22 public: 
    23         vec eval() {return val;}; 
    24         vec eval(vec &cond) {return val;}; 
    25          
    26         vec evalsome(ivec &rvind); 
    27 } 
     17//! class representing function $f(x) = a$, here rv is empty 
     18class constfn : public fnc 
     19{ 
     20                RV rv; 
     21                vec val; 
     22 
     23        public: 
     24                vec eval() {return val;}; 
     25                vec eval ( vec &cond ) {return val;}; 
     26                //!Default constructor 
     27                constfn ( const vec &val0 ) :rv(),val ( val0 ) {}; 
     28}; 
     29 
     30//! Class representing function $f(x) = Ax+B$ 
     31class linfn: public fnc 
     32{ 
     33                RV rv; 
     34                ivec indexlist; // needed by evalsome 
     35                mat A; 
     36                vec B; 
     37        public : 
     38                vec eval ( vec &cond ) {it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." );return A*cond+B;}; 
     39 
     40                linfn evalsome ( ivec &rvind ); 
     41                linfn ( const RV &rv0 ) :rv ( rv0 ),A ( eye ( rv0.count() ) ),B ( zeros ( rv0.count() ) ) { indexlist=rv.indexlist();}; 
     42                linfn ( const RV &rv0, const mat &A0 ) : rv ( rv0 ), A ( A0 ), B ( zeros ( rv0.count() ) ) { indexlist=rv.indexlist();}; 
     43                linfn ( const RV &rv0, const mat &A0, const vec &B0 ) :rv ( rv0 ), A ( A0 ), B ( B0 ) { indexlist=rv.indexlist();}; 
     44}; 
     45 
     46//! Class representing function $f(x,u) = Ax+Bu$ 
     47class bilinfn: public fnc 
     48{ 
     49                RV rv; 
     50                ivec indexlist; // needed by evalsome 
     51                mat A; 
     52                mat B; 
     53        public : 
     54                vec eval ( vec &cond ) 
     55                { 
     56                        it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." ); 
     57                        int sizex = A.cols(); 
     58                        return A*cond(0,sizex-1)+B*cond(sizex,-1);//-1 = end (in matlab) 
     59                }; 
     60                vec eval ( vec &xcond, vec &ucond ) 
     61                { 
     62                        it_assert_debug ( xcond.length() ==rv.count(), "linfn::eval Wrong cond." ); 
     63                        return A*xcond+B*ucond; 
     64                }; 
     65 
     66                bilinfn evalsome ( ivec &rvind ); 
     67                bilinfn ( const RV &x0, const RV &u0 ) :A ( eye ( x0.count() ) ),B ( zeros ( x0.count(),u0.count() ) ) 
     68                { 
     69                        rv=x0; rv.add ( u0 ); 
     70                        indexlist=rv.indexlist(); 
     71                }; 
     72                bilinfn ( const RV &x0, const RV &u0, const mat &A0, const mat &B0 ); 
     73};