1 | // |
---|
2 | // C++ Interface: itpp_ext |
---|
3 | // |
---|
4 | // Description: |
---|
5 | // |
---|
6 | // |
---|
7 | // Author: smidl <smidl@utia.cas.cz>, (C) 2008 |
---|
8 | // |
---|
9 | // Copyright: See COPYING file that comes with this distribution |
---|
10 | // |
---|
11 | // |
---|
12 | #include <itpp/itbase.h> |
---|
13 | #include "libBM.h" |
---|
14 | |
---|
15 | using namespace itpp; |
---|
16 | |
---|
17 | //! class representing function $f(x) = a$, here rv is empty |
---|
18 | class 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$ |
---|
31 | class 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$ |
---|
47 | class 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 | }; |
---|