block_matrix_tutorial.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ACADO Toolkit.
3  *
4  * ACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.
5  * Copyright (C) 2008-2014 by Boris Houska, Hans Joachim Ferreau,
6  * Milan Vukov, Rien Quirynen, KU Leuven.
7  * Developed within the Optimization in Engineering Center (OPTEC)
8  * under supervision of Moritz Diehl. All rights reserved.
9  *
10  * ACADO Toolkit is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 3 of the License, or (at your option) any later version.
14  *
15  * ACADO Toolkit is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with ACADO Toolkit; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  *
24  */
25 
26 
27 
37 
38 
39 /* >>> start tutorial code >>> */
40 int main( ){
41 
43 
44 
45  // DEFINE SOME MATRICES:
46  // ---------------------
47  DMatrix A(2,2), B(2,3), C(2,2);
48 
49  A(0,0) = 1.0; A(0,1) = 2.0;
50  A(1,0) = 3.0; A(1,1) = 4.0;
51 
52  B(0,0) = 1.0; B(0,1) = 2.0; B(0,2) = 3.0;
53  B(1,0) = 4.0; B(1,1) = 5.0; B(1,2) = 6.0;
54 
55  C(0,0) = 1.0; C(0,1) = 2.0;
56  C(1,0) = 4.0; C(1,1) = 5.0;
57 
58 
59  // DEFINE SOME BLOCK MATRICES:
60  // ---------------------------
61  BlockMatrix M(2,2),N(2,3),P(2,3);
62 
63  // -------------------------------------
64  // DEFINE A BLOCK MATRIX M OF THE FORM:
65  //
66  // ( 1 A )
67  // M := ( )
68  // ( 0 1 )
69  //
70  // WHERE 1 IS A 2x2 UNIT MATRIX:
71  // -------------------------------------
72  M.setIdentity(0,0,2); M.setDense (0,1,A);
73  /* skip */ M.setIdentity(1,1,2);
74 
75  // -------------------------------------
76  // DEFINE A BLOCK MATRIX N OF THE FORM:
77  //
78  // ( 1 B C )
79  // N := ( )
80  // ( 0 B 1 )
81  //
82  // -------------------------------------
83  N.setIdentity(0,0,2); N.setDense(0,1,B); N.setDense (0,2,C);
84  /* skip */ N.setDense(1,1,B); N.setIdentity(1,2,2);
85 
86 
87  // PRINT THE MATRICES M AND N :
88  // -------------------------------
89  printf("M = \n"); M.print();
90  printf("N = \n"); N.print();
91 
92  // COMPUTE THE MATRIX PRODUCT MN := M*N :
93  // ---------------------------------------
94  BlockMatrix MN; MN = M*N;
95 
96  // PRINT THE RESULT FOR MN:
97  // ------------------------
98  printf("MN = \n"); MN.print();
99 
100  // COMPUTE THE MATRIX PRODUCT MTN := M^T*N :
101  // ------------------------------------------
102  BlockMatrix MTN; MTN = M^N;
103 
104  // PRINT THE RESULT FOR MN:
105  // ------------------------
106  printf("MTN = \n"); MTN.print();
107 
108  return 0;
109 }
110 /* <<< end tutorial code <<< */
111 
112 
#define N
Implements a very rudimentary block sparse matrix class.
returnValue print(std::ostream &stream=std::cout) const
#define USING_NAMESPACE_ACADO
int main()


acado
Author(s): Milan Vukov, Rien Quirynen
autogenerated on Mon Jun 10 2019 12:34:29