7
|
1 // f-lu.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1993, 1994, 1995 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
1352
|
28 #include "CmplxLU.h" |
453
|
29 #include "dbleLU.h" |
1
|
30 |
1352
|
31 #include "defun-dld.h" |
1740
|
32 #include "error.h" |
1352
|
33 #include "gripes.h" |
|
34 #include "help.h" |
1740
|
35 #include "oct-obj.h" |
1
|
36 #include "user-prefs.h" |
636
|
37 #include "utils.h" |
1
|
38 |
1684
|
39 DEFUN_DLD_BUILTIN ("lu", Flu, Slu, FSlu, 11, |
519
|
40 "[L, U, P] = lu (A): LU factorization") |
1
|
41 { |
519
|
42 Octave_object retval; |
|
43 |
712
|
44 int nargin = args.length (); |
|
45 |
|
46 if (nargin != 1 || nargout > 3) |
519
|
47 { |
|
48 print_usage ("lu"); |
|
49 return retval; |
|
50 } |
1
|
51 |
712
|
52 tree_constant arg = args(0); |
636
|
53 |
|
54 int nr = arg.rows (); |
|
55 int nc = arg.columns (); |
|
56 |
718
|
57 int arg_is_empty = empty_arg ("lu", nr, nc); |
|
58 |
|
59 if (arg_is_empty < 0) |
636
|
60 return retval; |
718
|
61 else if (arg_is_empty > 0) |
|
62 return Octave_object (3, Matrix ()); |
636
|
63 |
|
64 if (nr != nc) |
1
|
65 { |
636
|
66 gripe_square_matrix_required ("lu"); |
|
67 return retval; |
1
|
68 } |
|
69 |
636
|
70 if (arg.is_real_type ()) |
1
|
71 { |
636
|
72 Matrix m = arg.matrix_value (); |
|
73 |
|
74 if (! error_state) |
620
|
75 { |
|
76 LU fact (m); |
636
|
77 |
620
|
78 switch (nargout) |
|
79 { |
|
80 case 0: |
|
81 case 1: |
|
82 case 2: |
1
|
83 { |
620
|
84 Matrix P = fact.P (); |
|
85 Matrix L = P.transpose () * fact.L (); |
516
|
86 retval(1) = fact.U (); |
620
|
87 retval(0) = L; |
1
|
88 } |
620
|
89 break; |
636
|
90 |
620
|
91 case 3: |
|
92 default: |
|
93 retval(2) = fact.P (); |
|
94 retval(1) = fact.U (); |
|
95 retval(0) = fact.L (); |
|
96 break; |
|
97 } |
|
98 } |
1
|
99 } |
785
|
100 else if (arg.is_complex_type ()) |
620
|
101 { |
636
|
102 ComplexMatrix m = arg.complex_matrix_value (); |
|
103 |
|
104 if (! error_state) |
620
|
105 { |
|
106 ComplexLU fact (m); |
636
|
107 |
620
|
108 switch (nargout) |
|
109 { |
|
110 case 0: |
|
111 case 1: |
|
112 case 2: |
|
113 { |
|
114 ComplexMatrix P = fact.P (); |
|
115 ComplexMatrix L = P.transpose () * fact.L (); |
|
116 retval(1) = fact.U (); |
|
117 retval(0) = L; |
|
118 } |
|
119 break; |
636
|
120 |
620
|
121 case 3: |
|
122 default: |
|
123 retval(2) = fact.P (); |
|
124 retval(1) = fact.U (); |
|
125 retval(0) = fact.L (); |
|
126 break; |
|
127 } |
|
128 } |
|
129 } |
|
130 else |
|
131 { |
636
|
132 gripe_wrong_type_arg ("lu", arg); |
620
|
133 } |
|
134 |
1
|
135 return retval; |
|
136 } |
|
137 |
|
138 /* |
|
139 ;;; Local Variables: *** |
|
140 ;;; mode: C++ *** |
|
141 ;;; page-delimiter: "^/\\*" *** |
|
142 ;;; End: *** |
|
143 */ |