1991
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1991
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
4192
|
23 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
1991
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "base-lu.h" |
|
32 |
2049
|
33 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
34 lu_type |
2049
|
35 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: L (void) const |
1991
|
36 { |
4329
|
37 int a_nr = a_fact.rows (); |
|
38 int a_nc = a_fact.cols (); |
|
39 int mn = (a_nr < a_nc ? a_nr : a_nc); |
1991
|
40 |
4329
|
41 lu_type l (a_nr, mn, lu_elt_type (0.0)); |
1991
|
42 |
4329
|
43 for (int i = 0; i < a_nr; i++) |
1991
|
44 { |
|
45 l.xelem (i, i) = 1.0; |
4329
|
46 for (int j = 0; j < (i < a_nc ? i : a_nc); j++) |
1991
|
47 l.xelem (i, j) = a_fact.xelem (i, j); |
|
48 } |
|
49 |
|
50 return l; |
|
51 } |
|
52 |
2049
|
53 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
54 lu_type |
2049
|
55 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: U (void) const |
1991
|
56 { |
4329
|
57 int a_nr = a_fact.rows (); |
|
58 int a_nc = a_fact.cols (); |
|
59 int mn = (a_nr < a_nc ? a_nr : a_nc); |
1991
|
60 |
4329
|
61 lu_type u (mn, a_nc, lu_elt_type (0.0)); |
|
62 |
|
63 for (int i = 0; i < mn; i++) |
1991
|
64 { |
4329
|
65 for (int j = i; j < a_nc; j++) |
1991
|
66 u.xelem (i, j) = a_fact.xelem (i, j); |
|
67 } |
|
68 |
|
69 return u; |
|
70 } |
|
71 |
2049
|
72 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
73 p_type |
2049
|
74 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: P (void) const |
1991
|
75 { |
4329
|
76 int a_nr = a_fact.rows (); |
1991
|
77 |
4329
|
78 Array<int> pvt (a_nr); |
1991
|
79 |
4329
|
80 for (int i = 0; i < a_nr; i++) |
1991
|
81 pvt.xelem (i) = i; |
|
82 |
4329
|
83 for (int i = 0; i < ipvt.length(); i++) |
1991
|
84 { |
|
85 int k = ipvt.xelem (i); |
|
86 |
|
87 if (k != i) |
|
88 { |
|
89 int tmp = pvt.xelem (k); |
|
90 pvt.xelem (k) = pvt.xelem (i); |
|
91 pvt.xelem (i) = tmp; |
|
92 } |
|
93 } |
|
94 |
4329
|
95 p_type p (a_nr, a_nr, p_elt_type (0.0)); |
1991
|
96 |
4329
|
97 for (int i = 0; i < a_nr; i++) |
1991
|
98 p.xelem (i, pvt.xelem (i)) = 1.0; |
|
99 |
|
100 return p; |
|
101 } |
|
102 |
|
103 /* |
|
104 ;;; Local Variables: *** |
|
105 ;;; mode: C++ *** |
|
106 ;;; End: *** |
|
107 */ |