1991
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 2002, 2003, 2004, 2005, 2007 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 |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
1991
|
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 |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
1991
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "base-lu.h" |
|
28 |
2049
|
29 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
30 lu_type |
2049
|
31 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: L (void) const |
1991
|
32 { |
5275
|
33 octave_idx_type a_nr = a_fact.rows (); |
|
34 octave_idx_type a_nc = a_fact.cols (); |
|
35 octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); |
1991
|
36 |
4329
|
37 lu_type l (a_nr, mn, lu_elt_type (0.0)); |
1991
|
38 |
5275
|
39 for (octave_idx_type i = 0; i < a_nr; i++) |
1991
|
40 { |
4811
|
41 if (i < a_nc) |
|
42 l.xelem (i, i) = 1.0; |
|
43 |
5275
|
44 for (octave_idx_type j = 0; j < (i < a_nc ? i : a_nc); j++) |
1991
|
45 l.xelem (i, j) = a_fact.xelem (i, j); |
|
46 } |
|
47 |
|
48 return l; |
|
49 } |
|
50 |
2049
|
51 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
52 lu_type |
2049
|
53 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: U (void) const |
1991
|
54 { |
5275
|
55 octave_idx_type a_nr = a_fact.rows (); |
|
56 octave_idx_type a_nc = a_fact.cols (); |
|
57 octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); |
1991
|
58 |
4329
|
59 lu_type u (mn, a_nc, lu_elt_type (0.0)); |
|
60 |
5275
|
61 for (octave_idx_type i = 0; i < mn; i++) |
1991
|
62 { |
5275
|
63 for (octave_idx_type j = i; j < a_nc; j++) |
1991
|
64 u.xelem (i, j) = a_fact.xelem (i, j); |
|
65 } |
|
66 |
|
67 return u; |
|
68 } |
|
69 |
2049
|
70 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
71 p_type |
2049
|
72 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: P (void) const |
1991
|
73 { |
5275
|
74 octave_idx_type a_nr = a_fact.rows (); |
1991
|
75 |
5275
|
76 Array<octave_idx_type> pvt (a_nr); |
1991
|
77 |
5275
|
78 for (octave_idx_type i = 0; i < a_nr; i++) |
1991
|
79 pvt.xelem (i) = i; |
|
80 |
5275
|
81 for (octave_idx_type i = 0; i < ipvt.length(); i++) |
1991
|
82 { |
5275
|
83 octave_idx_type k = ipvt.xelem (i); |
1991
|
84 |
|
85 if (k != i) |
|
86 { |
5275
|
87 octave_idx_type tmp = pvt.xelem (k); |
1991
|
88 pvt.xelem (k) = pvt.xelem (i); |
|
89 pvt.xelem (i) = tmp; |
|
90 } |
|
91 } |
|
92 |
4329
|
93 p_type p (a_nr, a_nr, p_elt_type (0.0)); |
1991
|
94 |
5275
|
95 for (octave_idx_type i = 0; i < a_nr; i++) |
1991
|
96 p.xelem (i, pvt.xelem (i)) = 1.0; |
|
97 |
|
98 return p; |
|
99 } |
|
100 |
|
101 /* |
|
102 ;;; Local Variables: *** |
|
103 ;;; mode: C++ *** |
|
104 ;;; End: *** |
|
105 */ |