dev_sparse_lu_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 
41 
42 
43 /* >>> start tutorial code >>> */
44 int main( ){
45 
47 
48  int i;
49 
50  // DEFINE A MATRIX:
51  // ----------------
52  DMatrix A = readFromFile("J.txt");
53 
54  const int m = A.getNumRows();
55 
56  DVector b(m);
57 
58  for( i = 0; i < m; i++ )
59  b(i) = 1.0;
60 
61  DMatrix B = A;
62 
63 
64  double t2 = -acadoGetTime();
65  A.computeSparseLUdecomposition();
66  t2 += acadoGetTime();
67  DVector res2 = b - B*A.solveSparseLU(b);
68 
69  printf("LU: TIME = %.16e , error = %.16e \n", t2, res2.getNorm( VN_LINF ) );
70 
71  DVector res3 = b - (B^A.solveTransposeSparseLU(b));
72  printf("LU: (transpose) , error = %.16e \n", res3.getNorm( VN_LINF ) );
73 
74 
75 // double t1 = -acadoGetTime();
76  A.computeQRdecomposition();
77 // t1 += acadoGetTime();
78 // DVector res1 = b - B*A.solveQR(b);
79 //
80 // printf("QR: TIME = %.16e , error = %.16e \n", t1, res1.getNorm( VN_LINF ) );
81 
82  return 0;
83 }
84 /* <<< end tutorial code <<< */
85 
86 
#define USING_NAMESPACE_ACADO
double acadoGetTime()
returnValue readFromFile(real_t *data, int nrow, int ncol, const char *datafilename)
int main()
unsigned getNumRows() const
Definition: matrix.hpp:185
T getNorm(VectorNorm _norm) const
Definition: vector.cpp:67


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