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 | }; |
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 | | }; |
| 71 | class diffbifn: public fnc { |
| 72 | protected: |
| 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; |
| 81 | public: |
| 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 | }; |
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 | } |
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 | | } |
| 110 | class bilinfn: public diffbifn { |
| 111 | mat A; |
| 112 | mat B; |
| 113 | public : |
| 114 | //!\name Constructors |
| 115 | //!@{ |
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 | //!@} |