Show
Ignore:
Timestamp:
08/05/09 14:40:03 (15 years ago)
Author:
mido
Message:

panove, vite, jak jsem peclivej na upravu kodu.. snad se vam bude libit:) konfigurace je v souboru /system/astylerc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/math/functions.h

    r384 r477  
    1515#include "../base/bdmbase.h" 
    1616 
    17 namespace bdm{ 
     17namespace bdm { 
    1818 
    1919//! class representing function \f$f(x) = a\f$, here \c rv is empty 
    20 class constfn : public fnc 
    21 { 
    22                 //! value of the function 
    23                 vec val; 
     20class constfn : public fnc { 
     21        //! value of the function 
     22        vec val; 
    2423 
    25         public: 
    26                 //vec eval() {return val;}; 
    27                 //! inherited 
    28                 vec eval ( const vec &cond ) {return val;}; 
    29                 //!Default constructor 
    30                 constfn ( const vec &val0 ) :fnc(), val ( val0 ) {dimy=val.length();}; 
     24public: 
     25        //vec eval() {return val;}; 
     26        //! inherited 
     27        vec eval ( const vec &cond ) { 
     28                return val; 
     29        }; 
     30        //!Default constructor 
     31        constfn ( const vec &val0 ) : fnc(), val ( val0 ) { 
     32                dimy = val.length(); 
     33        }; 
    3134}; 
    3235 
    3336//! Class representing function \f$f(x) = Ax+B\f$ 
    34 class linfn: public fnc 
    35 { 
    36                 //! Identification of \f$x\f$ 
    37                 RV rv; 
    38                 //! Matrix A 
    39                 mat A; 
    40                 //! vector B 
    41                 vec B; 
    42         public : 
    43                 vec eval (const vec &cond ) {it_assert_debug ( cond.length() ==A.cols(), "linfn::eval Wrong cond." );return A*cond+B;}; 
     37class linfn: public fnc { 
     38        //! Identification of \f$x\f$ 
     39        RV rv; 
     40        //! Matrix A 
     41        mat A; 
     42        //! vector B 
     43        vec B; 
     44public : 
     45        vec eval ( const vec &cond ) { 
     46                it_assert_debug ( cond.length() == A.cols(), "linfn::eval Wrong cond." ); 
     47                return A*cond + B; 
     48        }; 
    4449 
    4550//              linfn evalsome ( ivec &rvind ); 
    46                 //!default constructor 
    47                 linfn ( ) : fnc(), A ( ),B () { }; 
    48                 //! Set values of \c A and \c B 
    49                 void set_parameters ( const mat &A0 , const vec &B0 ) {A=A0; B=B0; dimy=A.rows();}; 
     51        //!default constructor 
     52        linfn ( ) : fnc(), A ( ), B () { }; 
     53        //! Set values of \c A and \c B 
     54        void set_parameters ( const mat &A0 , const vec &B0 ) { 
     55                A = A0; 
     56                B = B0; 
     57                dimy = A.rows(); 
     58        }; 
    5059}; 
    5160 
     
    60692) It could be generalized into multivariate form, (which was original meaning of \c fnc ). 
    6170*/ 
    62 class diffbifn: public fnc 
    63 { 
    64         protected: 
    65                 //! Indentifier of the first rv. 
    66                 RV rvx; 
    67                 //! Indentifier of the second rv. 
    68                 RV rvu; 
    69                 //! cache for rvx.count() 
    70                 int dimx; 
    71                 //! cache for rvu.count() 
    72                 int dimu; 
    73         public: 
    74                 //! Evaluates \f$f(x0,u0)\f$ (VS: Do we really need common eval? ) 
    75                 vec eval ( const vec &cond ) 
    76                 { 
    77                         it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." ); 
    78                         return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu-1 ) );//-1 = end (in matlab) 
    79                 }; 
     71class diffbifn: public fnc { 
     72protected: 
     73        //! Indentifier of the first rv. 
     74        RV rvx; 
     75        //! Indentifier of the second rv. 
     76        RV rvu; 
     77        //! cache for rvx.count() 
     78        int dimx; 
     79        //! cache for rvu.count() 
     80        int dimu; 
     81public: 
     82        //! Evaluates \f$f(x0,u0)\f$ (VS: Do we really need common eval? ) 
     83        vec eval ( const vec &cond ) { 
     84                it_assert_debug ( cond.length() == ( dimx + dimu ), "linfn::eval Wrong cond." ); 
     85                return eval ( cond ( 0, dimx - 1 ), cond ( dimx, dimx + dimu - 1 ) );//-1 = end (in matlab) 
     86        }; 
    8087 
    81                 //! Evaluates \f$f(x0,u0)\f$ 
    82                 virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );}; 
    83                 //! Evaluates \f$A=\frac{d}{dx}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed. @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
    84                 virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {}; 
    85                 //! Evaluates \f$A=\frac{d}{du}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed.        @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
    86                 virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {}; 
    87                 //!Default constructor (dimy is not set!) 
    88                 diffbifn () : fnc() {}; 
    89                 //! access function 
    90                 int _dimx() const{return dimx;} 
    91                 //! access function 
    92                 int _dimu() const{return dimu;} 
     88        //! Evaluates \f$f(x0,u0)\f$ 
     89        virtual vec eval ( const vec &x0, const vec &u0 ) { 
     90                return zeros ( dimy ); 
     91        }; 
     92        //! Evaluates \f$A=\frac{d}{dx}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed. @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
     93        virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full = true ) {}; 
     94        //! Evaluates \f$A=\frac{d}{du}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed.        @param x0 numeric value of \f$x\f$, @param u0 numeric value of \f$u\f$ @param A a place where the result will be stored. 
     95        virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full = true ) {}; 
     96        //!Default constructor (dimy is not set!) 
     97        diffbifn () : fnc() {}; 
     98        //! access function 
     99        int _dimx() const { 
     100                return dimx; 
     101        } 
     102        //! access function 
     103        int _dimu() const { 
     104                return dimu; 
     105        } 
    93106}; 
    94107 
    95108//! Class representing function \f$f(x,u) = Ax+Bu\f$ 
    96109//TODO can be generalized into multilinear form! 
    97 class bilinfn: public diffbifn 
    98 { 
    99                 mat A; 
    100                 mat B; 
    101         public : 
    102                 //!\name Constructors 
    103                 //!@{ 
    104                  
    105                 bilinfn () : diffbifn () ,A() ,B()      {}; 
    106                 bilinfn (const mat A0, const mat B0) {set_parameters(A0,B0);}; 
    107                 //! Alternative constructor 
    108                 void set_parameters(const mat A0, const mat B0){ 
    109                         it_assert_debug(A0.rows()==B0.rows(),""); 
    110                         A=A0;B=B0; 
    111                         dimy=A.rows(); 
    112                         dimx=A.cols(); 
    113                         dimu=B.cols(); 
    114                 } 
    115                 //!@} 
    116                  
    117                 //!\name Mathematical operations 
    118                 //!@{ 
    119                 inline vec eval ( const  vec &x0, const vec &u0 ) 
    120                 { 
    121                         it_assert_debug ( x0.length() ==dimx, "linfn::eval Wrong xcond." ); 
    122                         it_assert_debug ( u0.length() ==dimu, "linfn::eval Wrong ucond." ); 
    123                         return A*x0+B*u0; 
    124                 } 
     110class bilinfn: public diffbifn { 
     111        mat A; 
     112        mat B; 
     113public : 
     114        //!\name Constructors 
     115        //!@{ 
    125116 
    126                 void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) 
    127                 { 
    128                         it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." ); 
    129                         if ( full ) F=A;        //else : nothing has changed no need to regenerate 
    130                 } 
    131                 //! 
    132                 void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true ) 
    133                 { 
    134                         it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." ); 
    135                         if ( full ) F=B;        //else : nothing has changed no need to regenerate 
    136                 } 
    137                 //!@} 
     117        bilinfn () : diffbifn () , A() , B()    {}; 
     118        bilinfn ( const mat A0, const mat B0 ) { 
     119                set_parameters ( A0, B0 ); 
     120        }; 
     121        //! Alternative constructor 
     122        void set_parameters ( const mat A0, const mat B0 ) { 
     123                it_assert_debug ( A0.rows() == B0.rows(), "" ); 
     124                A = A0; 
     125                B = B0; 
     126                dimy = A.rows(); 
     127                dimx = A.cols(); 
     128                dimu = B.cols(); 
     129        } 
     130        //!@} 
     131 
     132        //!\name Mathematical operations 
     133        //!@{ 
     134        inline vec eval ( const  vec &x0, const vec &u0 ) { 
     135                it_assert_debug ( x0.length() == dimx, "linfn::eval Wrong xcond." ); 
     136                it_assert_debug ( u0.length() == dimu, "linfn::eval Wrong ucond." ); 
     137                return A*x0 + B*u0; 
     138        } 
     139 
     140        void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) { 
     141                it_assert_debug ( ( F.cols() == A.cols() ) & ( F.rows() == A.rows() ), "Allocated F is not compatible." ); 
     142                if ( full ) F = A;      //else : nothing has changed no need to regenerate 
     143        } 
     144        //! 
     145        void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full = true ) { 
     146                it_assert_debug ( ( F.cols() == B.cols() ) & ( F.rows() == B.rows() ), "Allocated F is not compatible." ); 
     147                if ( full ) F = B;      //else : nothing has changed no need to regenerate 
     148        } 
     149        //!@} 
    138150}; 
    139151