Debian Codegraph @

Test/test_lapack.C

raw
1 /*
2 * Test code for LORENE Matrice class and LAPACK
3 */
4
5 /*
6 * Copyright (c) 2001 Eric Gourgoulhon
7 *
8 * This file is part of LORENE.
9 *
10 * LORENE is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * LORENE 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
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 /*
27 * $Id: test_lapack.C,v 1.4 2014/10/13 08:54:08 j_novak Exp $
28 * $Log: test_lapack.C,v $
29 * Revision 1.4 2014/10/13 08:54:08 j_novak
30 * Lorene classes and functions now belong to the namespace Lorene.
31 *
32 * Revision 1.3 2014/10/06 15:07:36 j_novak
33 * Modified #include directives to use c++ syntax.
34 *
35 * Revision 1.2 2002/10/16 14:37:19 j_novak
36 * Reorganization of #include instructions of standard C++, in order to
37 * use experimental version 3 of gcc.
38 *
39 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
40 * LORENE
41 *
42 *
43 * $Header: /cvsroot/Lorene/Test/test_lapack.C,v 1.4 2014/10/13 08:54:08 j_novak Exp $
44 *
45 */
46
47 // C headers:
48 #include <cmath>
49
50 // Lorene headers
51 #include "matrice.h"
52
53 using namespace Lorene ;
54
55 int main() {
56
57 Matrice a(3, 3) ;
58 a.set_etat_qcq() ;
59
60 for (int i=0; i<3; i++) {
61 for (int j=0; j<3; j++) {
62 a.set(i, j) = 0 ;
63 }
64 }
65 a.set(0, 0) = 1 ;
66 a.set(1, 1) = 1 ;
67 a.set(2, 2) = 1 ;
68 a.set(1, 2) = 1 ;
69 a.set(2, 1) = -1 ;
70 a.set(0, 2) = 2 ;
71 a.set(1, 0) = -3 ;
72
73 Tbl x0(3) ;
74 x0.set_etat_qcq() ;
75
76 for (int i=0; i<3; i++) {
77 x0.set(i) = 1+i ;
78 }
79
80 Tbl y(3) ;
81 y.set_etat_qcq() ;
82
83 for (int i=0; i<3; i++) {
84 y.set(i) = 0 ;
85 for (int j=0; j<3; j++) {
86 y.set(i) += a(i, j) * x0(j) ;
87 }
88 }
89
90 a.set_band(2, 2) ;
91 a.set_lu() ;
92
93 Tbl x = a.inverse(y) ;
94
95 cout << "Matrix a : " << endl ;
96 cout << a << endl ;
97
98 cout << "Det(a) = " << a.determinant() << endl ;
99
100 cout << "R.H.S. y : " << endl ;
101 cout << y << endl ;
102
103
104 cout << "Test of resolution of the system A.x = y : " << endl ;
105 for (int i=0; i<3; i++) {
106 cout << x(i) - x0(i) << endl ;
107 }
108
109 return EXIT_SUCCESS ;
110
111 }