1991
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
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 |
|
23 #if defined (__GNUG__) |
|
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 { |
|
37 int n = ipvt.length (); |
|
38 |
2049
|
39 lu_type l (n, n, lu_elt_type (0.0)); |
1991
|
40 |
|
41 for (int i = 0; i < n; i++) |
|
42 { |
|
43 l.xelem (i, i) = 1.0; |
|
44 for (int j = 0; j < i; j++) |
|
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 { |
|
55 int n = ipvt.length (); |
|
56 |
2049
|
57 lu_type u (n, n, lu_elt_type (0.0)); |
1991
|
58 |
|
59 for (int i = 0; i < n; i++) |
|
60 { |
|
61 for (int j = i; j < n; j++) |
|
62 u.xelem (i, j) = a_fact.xelem (i, j); |
|
63 } |
|
64 |
|
65 return u; |
|
66 } |
|
67 |
2049
|
68 template <class lu_type, class lu_elt_type, class p_type, class p_elt_type> |
1991
|
69 p_type |
2049
|
70 base_lu <lu_type, lu_elt_type, p_type, p_elt_type> :: P (void) const |
1991
|
71 { |
|
72 int n = ipvt.length (); |
|
73 |
|
74 Array<int> pvt (n); |
|
75 |
|
76 for (int i = 0; i < n; i++) |
|
77 pvt.xelem (i) = i; |
|
78 |
|
79 for (int i = 0; i < n - 1; i++) |
|
80 { |
|
81 int k = ipvt.xelem (i); |
|
82 |
|
83 if (k != i) |
|
84 { |
|
85 int tmp = pvt.xelem (k); |
|
86 pvt.xelem (k) = pvt.xelem (i); |
|
87 pvt.xelem (i) = tmp; |
|
88 } |
|
89 } |
|
90 |
2049
|
91 p_type p (n, n, p_elt_type (0.0)); |
1991
|
92 |
|
93 for (int i = 0; i < n; i++) |
|
94 p.xelem (i, pvt.xelem (i)) = 1.0; |
|
95 |
|
96 return p; |
|
97 } |
|
98 |
|
99 /* |
|
100 ;;; Local Variables: *** |
|
101 ;;; mode: C++ *** |
|
102 ;;; End: *** |
|
103 */ |