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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1991
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "base-lu.h" |
|
29 |
2049
|
30 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
31 lu_type |
2049
|
32 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: L (void) const |
1991
|
33 { |
5275
|
34 octave_idx_type a_nr = a_fact.rows (); |
|
35 octave_idx_type a_nc = a_fact.cols (); |
|
36 octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); |
1991
|
37 |
4329
|
38 lu_type l (a_nr, mn, lu_elt_type (0.0)); |
1991
|
39 |
5275
|
40 for (octave_idx_type i = 0; i < a_nr; i++) |
1991
|
41 { |
4811
|
42 if (i < a_nc) |
|
43 l.xelem (i, i) = 1.0; |
|
44 |
5275
|
45 for (octave_idx_type j = 0; j < (i < a_nc ? i : a_nc); j++) |
1991
|
46 l.xelem (i, j) = a_fact.xelem (i, j); |
|
47 } |
|
48 |
|
49 return l; |
|
50 } |
|
51 |
2049
|
52 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
53 lu_type |
2049
|
54 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: U (void) const |
1991
|
55 { |
5275
|
56 octave_idx_type a_nr = a_fact.rows (); |
|
57 octave_idx_type a_nc = a_fact.cols (); |
|
58 octave_idx_type mn = (a_nr < a_nc ? a_nr : a_nc); |
1991
|
59 |
4329
|
60 lu_type u (mn, a_nc, lu_elt_type (0.0)); |
|
61 |
5275
|
62 for (octave_idx_type i = 0; i < mn; i++) |
1991
|
63 { |
5275
|
64 for (octave_idx_type j = i; j < a_nc; j++) |
1991
|
65 u.xelem (i, j) = a_fact.xelem (i, j); |
|
66 } |
|
67 |
|
68 return u; |
|
69 } |
|
70 |
2049
|
71 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
72 p_type |
2049
|
73 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: P (void) const |
1991
|
74 { |
5275
|
75 octave_idx_type a_nr = a_fact.rows (); |
1991
|
76 |
5275
|
77 Array<octave_idx_type> pvt (a_nr); |
1991
|
78 |
5275
|
79 for (octave_idx_type i = 0; i < a_nr; i++) |
1991
|
80 pvt.xelem (i) = i; |
|
81 |
5275
|
82 for (octave_idx_type i = 0; i < ipvt.length(); i++) |
1991
|
83 { |
5275
|
84 octave_idx_type k = ipvt.xelem (i); |
1991
|
85 |
|
86 if (k != i) |
|
87 { |
5275
|
88 octave_idx_type tmp = pvt.xelem (k); |
1991
|
89 pvt.xelem (k) = pvt.xelem (i); |
|
90 pvt.xelem (i) = tmp; |
|
91 } |
|
92 } |
|
93 |
4329
|
94 p_type p (a_nr, a_nr, p_elt_type (0.0)); |
1991
|
95 |
5275
|
96 for (octave_idx_type i = 0; i < a_nr; i++) |
1991
|
97 p.xelem (i, pvt.xelem (i)) = 1.0; |
|
98 |
|
99 return p; |
|
100 } |
|
101 |
|
102 /* |
|
103 ;;; Local Variables: *** |
|
104 ;;; mode: C++ *** |
|
105 ;;; End: *** |
|
106 */ |