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 { |
4811
|
45 if (i < a_nc) |
|
46 l.xelem (i, i) = 1.0; |
|
47 |
4329
|
48 for (int j = 0; j < (i < a_nc ? i : a_nc); j++) |
1991
|
49 l.xelem (i, j) = a_fact.xelem (i, j); |
|
50 } |
|
51 |
|
52 return l; |
|
53 } |
|
54 |
2049
|
55 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
56 lu_type |
2049
|
57 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: U (void) const |
1991
|
58 { |
4329
|
59 int a_nr = a_fact.rows (); |
|
60 int a_nc = a_fact.cols (); |
|
61 int mn = (a_nr < a_nc ? a_nr : a_nc); |
1991
|
62 |
4329
|
63 lu_type u (mn, a_nc, lu_elt_type (0.0)); |
|
64 |
|
65 for (int i = 0; i < mn; i++) |
1991
|
66 { |
4329
|
67 for (int j = i; j < a_nc; j++) |
1991
|
68 u.xelem (i, j) = a_fact.xelem (i, j); |
|
69 } |
|
70 |
|
71 return u; |
|
72 } |
|
73 |
2049
|
74 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
75 p_type |
2049
|
76 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: P (void) const |
1991
|
77 { |
4329
|
78 int a_nr = a_fact.rows (); |
1991
|
79 |
4329
|
80 Array<int> pvt (a_nr); |
1991
|
81 |
4329
|
82 for (int i = 0; i < a_nr; i++) |
1991
|
83 pvt.xelem (i) = i; |
|
84 |
4329
|
85 for (int i = 0; i < ipvt.length(); i++) |
1991
|
86 { |
|
87 int k = ipvt.xelem (i); |
|
88 |
|
89 if (k != i) |
|
90 { |
|
91 int tmp = pvt.xelem (k); |
|
92 pvt.xelem (k) = pvt.xelem (i); |
|
93 pvt.xelem (i) = tmp; |
|
94 } |
|
95 } |
|
96 |
4329
|
97 p_type p (a_nr, a_nr, p_elt_type (0.0)); |
1991
|
98 |
4329
|
99 for (int i = 0; i < a_nr; i++) |
1991
|
100 p.xelem (i, pvt.xelem (i)) = 1.0; |
|
101 |
|
102 return p; |
|
103 } |
|
104 |
|
105 /* |
|
106 ;;; Local Variables: *** |
|
107 ;;; mode: C++ *** |
|
108 ;;; End: *** |
|
109 */ |