| 47 | |
| 48 | /*! |
| 49 | \brief Class representing a differentiable function of two variables $f(x,u)$. |
| 50 | |
| 51 | Function of two variables. |
| 52 | |
| 53 | TODO: |
| 54 | 1) Technically, it could have a common parent (e.g. \c fnc ) with other functions. For now, we keep it as it is. |
| 55 | 2) It could be generalized into multivariate form, (which was original meaning of \c fnc ). |
| 56 | */ |
| 57 | class diffbifn: public fnc |
| 58 | { |
| 59 | protected: |
| 60 | RV rvx,rvu; |
| 61 | int dimx; |
| 62 | int dimu; |
| 63 | public: |
| 64 | //! Evaluates $f(x0,u0)$ (VS: Do we really need common eval? ) |
| 65 | vec eval ( const vec &cond ) |
| 66 | { |
| 67 | it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." ); |
| 68 | return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu ) );//-1 = end (in matlab) |
| 69 | }; |
| 70 | |
| 71 | //! Evaluates $f(x0,u0)$ |
| 72 | virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );}; |
| 73 | //! 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. |
| 74 | virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {}; |
| 75 | //! 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. |
| 76 | virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {}; |
| 77 | //!Default constructor (dimy is not set!) |
| 78 | diffbifn ( const RV rvx0, const RV rvu0 ) : rvx ( rvx0 ),rvu ( rvu0 ) {dimx=rvx.count();dimu=rvu.count();}; |
| 79 | //! access function |
| 80 | int _dimx() const{return dimx;} |
| 81 | //! access function |
| 82 | int _dimu() const{return dimu;} |
| 83 | }; |
| 84 | |
54 | | vec eval ( vec &cond ) |
| 92 | vec eval ( const vec &x0, const vec &u0 ); |
| 93 | |
| 94 | //! Default constructor |
| 95 | bilinfn ( const RV &rvx0, const RV &rvu0 ) : diffbifn ( rvx0,rvu0 ) ,A ( eye ( dimx ) ),B ( zeros ( dimx,dimu ) ) {}; |
| 96 | // |
| 97 | bilinfn ( const RV &rvx0, const RV &rvu0, const mat &A0, const mat &B0 ); |
| 98 | // |
| 99 | void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) |
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 ) |
| 101 | it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." ); |
| 102 | if ( full ) F=A; //else : nothing has changed no need to regenerate |
| 103 | } |
| 104 | // |
| 105 | void dfdu_cond ( const vec &x0, const vec &u0, mat &F, bool full=true ) |
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 ); |
| 107 | it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." ); |
| 108 | if ( full ) F=B; //else : nothing has changed no need to regenerate |
| 109 | } |