root/library/bdm/design/ctrlbase.cpp @ 679

Revision 679, 1.2 kB (checked in by smidl, 15 years ago)

Major changes in BM -- OK is only test suite and tests/tutorial -- the rest is broken!!!

RevLine 
[508]1#include "ctrlbase.h"
[491]2
[508]3namespace bdm{
4
[586]5void LQG::set_system(shared_ptr<StateSpace<fsqmat> > S0){
6        S = S0;
[679]7        dimx= S->_A().rows();
8        dimy= S->_C().rows();
9        dimu= S->_B().cols();
[508]10        pr=zeros(dimx+dimu+dimy,  dimu+dimx+dimu+dimy);
11        pr.set_submatrix(dimx, dimu+dimx, eye(dimu+dimy));
12}
13
[586]14void LQG::set_control_parameters(const mat &Qy0, const mat &Qu0, const vec &y_req0, int horizon0){
[508]15        Qy=Qy0;
16        Qu=Qu0;
17        y_req=y_req0;
18        horizon = horizon0;
[586]19        validate();
20        initialize();
[508]21}
22
[586]23void LQG::validate() {
[620]24        bdm_assert ( Qy.cols() == dimy, "LQG: wrong dimensions of Qy " );
25        bdm_assert ( Qu.cols() == dimu, "LQG: wrong dimensions of Qu " );
26        bdm_assert ( y_req.length() == dimy, "LQG: wrong dimensions of y_req " );
[586]27}
28
29void LQG::initialize(){
[508]30        // set parameter matrix
[586]31        pr.set_submatrix(0,0,S->_B());
32        pr.set_submatrix(0,dimu, S->_A());
[491]33       
34        //penalization
35        qux=zeros(dimu,dimx+2*dimu+dimy);     
36        qux.set_submatrix(0,0,Qu);
37        qux.set_submatrix(0,dimx+dimu+dimy,Qu);
38
[508]39        qyx=zeros(dimy, dimx+dimy+dimu);
[586]40        qyx.set_submatrix(0,0,S->_C());
[508]41        qyx.set_submatrix(0,dimx,-eye(dimy));
[491]42       
43        //
[586]44        s=1e-5*eye(dimx+dimu+dimy);
[491]45        // parts of QR
46        hqy=Qy*qyx*pr;
47       
48        // pre_qr
[508]49        pre_qr = concat_vertical(s*pr, concat_vertical(hqy, qux));
50        post_qr = zeros(pre_qr.rows(), pre_qr.cols());
51}
52
[565]53}
Note: See TracBrowser for help on using the browser.