53 | | //!default constructor |
54 | | linfn ( ) : fnc(), A ( ), B () { }; |
55 | | //! Set values of \c A and \c B |
56 | | void set_parameters ( const mat &A0 , const vec &B0 ) { |
57 | | A = A0; |
58 | | B = B0; |
59 | | }; |
60 | | void from_setting(const Setting &set){ |
61 | | UI::get(A,set,"A",UI::compulsory); |
62 | | UI::get(B,set,"B",UI::compulsory); |
63 | | } |
64 | | void validate(){ |
65 | | dimy = A.rows(); |
66 | | dimc = A.cols(); |
67 | | } |
68 | | |
| 53 | //!default constructor |
| 54 | linfn ( ) : fnc(), A ( ), B () { }; |
| 55 | //! Set values of \c A and \c B |
| 56 | void set_parameters ( const mat &A0 , const vec &B0 ) { |
| 57 | A = A0; |
| 58 | B = B0; |
| 59 | }; |
| 60 | void from_setting(const Setting &set) { |
| 61 | UI::get(A,set,"A",UI::compulsory); |
| 62 | UI::get(B,set,"B",UI::compulsory); |
| 63 | } |
| 64 | void validate() { |
| 65 | dimy = A.rows(); |
| 66 | dimc = A.cols(); |
| 67 | } |
| 68 | |
93 | | //! Evaluates \f$f(x0,u0)\f$ (VS: Do we really need common eval? ) |
94 | | vec eval ( const vec &cond ) { |
95 | | bdm_assert_debug ( cond.length() == ( dimx + dimu ), "linfn::eval Wrong cond." ); |
96 | | if ( dimu > 0 ) { |
97 | | return eval ( cond ( 0, dimx - 1 ), cond ( dimx, dimx + dimu - 1 ) );//-1 = end (in matlab) |
98 | | } else { |
99 | | return eval ( cond ( 0, dimx - 1 ), vec ( 0 ) );//-1 = end (in matlab) |
100 | | } |
| 93 | //! Evaluates \f$f(x0,u0)\f$ (VS: Do we really need common eval? ) |
| 94 | vec eval ( const vec &cond ) { |
| 95 | bdm_assert_debug ( cond.length() == ( dimx + dimu ), "linfn::eval Wrong cond." ); |
| 96 | if ( dimu > 0 ) { |
| 97 | return eval ( cond ( 0, dimx - 1 ), cond ( dimx, dimx + dimu - 1 ) );//-1 = end (in matlab) |
| 98 | } else { |
| 99 | return eval ( cond ( 0, dimx - 1 ), vec ( 0 ) );//-1 = end (in matlab) |
| 100 | } |
104 | | //! Evaluates \f$f(x0,u0)\f$ |
105 | | virtual vec eval ( const vec &x0, const vec &u0 ) { |
106 | | return zeros ( dimy ); |
107 | | }; |
108 | | //! 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. |
109 | | virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full = true ) {}; |
110 | | //! 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. |
111 | | virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full = true ) {}; |
112 | | //!Default constructor (dimy is not set!) |
113 | | diffbifn () : fnc() {}; |
114 | | //! access function |
115 | | int _dimx() const { |
116 | | return dimx; |
117 | | } |
118 | | //! access function |
119 | | int _dimu() const { |
120 | | return dimu; |
121 | | } |
| 104 | //! Evaluates \f$f(x0,u0)\f$ |
| 105 | virtual vec eval ( const vec &x0, const vec &u0 ) { |
| 106 | return zeros ( dimy ); |
| 107 | }; |
| 108 | //! 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. |
| 109 | virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full = true ) {}; |
| 110 | //! 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. |
| 111 | virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full = true ) {}; |
| 112 | //!Default constructor (dimy is not set!) |
| 113 | diffbifn () : fnc() {}; |
| 114 | //! access function |
| 115 | int _dimx() const { |
| 116 | return dimx; |
| 117 | } |
| 118 | //! access function |
| 119 | int _dimu() const { |
| 120 | return dimu; |
| 121 | } |
150 | | //!\name Mathematical operations |
151 | | //!@{ |
152 | | inline vec eval ( const vec &x0, const vec &u0 ) { |
153 | | bdm_assert_debug ( x0.length() == dimx, "bilinfn::eval Wrong xcond." ); |
154 | | bdm_assert_debug ( u0.length() == dimu, "bilinfn::eval Wrong ucond." ); |
155 | | return A*x0 + B*u0; |
156 | | } |
| 150 | //!\name Mathematical operations |
| 151 | //!@{ |
| 152 | inline vec eval ( const vec &x0, const vec &u0 ) { |
| 153 | bdm_assert_debug ( x0.length() == dimx, "bilinfn::eval Wrong xcond." ); |
| 154 | bdm_assert_debug ( u0.length() == dimu, "bilinfn::eval Wrong ucond." ); |
| 155 | return A*x0 + B*u0; |
| 156 | } |
158 | | void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) { |
159 | | bdm_assert_debug ( ( F.cols() == A.cols() ) && ( F.rows() == A.rows() ), "Allocated F is not compatible." ); |
160 | | if ( full ) F = A; //else : nothing has changed no need to regenerate |
161 | | } |
| 158 | void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) { |
| 159 | bdm_assert_debug ( ( F.cols() == A.cols() ) && ( F.rows() == A.rows() ), "Allocated F is not compatible." ); |
| 160 | if ( full ) F = A; //else : nothing has changed no need to regenerate |
| 161 | } |
163 | | void dfdu_cond ( const vec &x0, const vec &u0, mat &F, bool full = true ) { |
164 | | bdm_assert_debug ( ( F.cols() == B.cols() ) && ( F.rows() == B.rows() ), "Allocated F is not compatible." ); |
165 | | if ( full ) F = B; //else : nothing has changed no need to regenerate |
166 | | } |
167 | | //!@} |
| 163 | void dfdu_cond ( const vec &x0, const vec &u0, mat &F, bool full = true ) { |
| 164 | bdm_assert_debug ( ( F.cols() == B.cols() ) && ( F.rows() == B.rows() ), "Allocated F is not compatible." ); |
| 165 | if ( full ) F = B; //else : nothing has changed no need to regenerate |
| 166 | } |
| 167 | //!@} |