2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "CmplxCHOL.h" |
|
28 #include "dbleCHOL.h" |
|
29 |
|
30 #include "defun-dld.h" |
|
31 #include "error.h" |
|
32 #include "gripes.h" |
|
33 #include "oct-obj.h" |
|
34 #include "utils.h" |
|
35 |
|
36 DEFUN_DLD (chol, args, nargout, |
3243
|
37 "[R, p] = chol (X): cholesky factorization") |
2928
|
38 { |
|
39 octave_value_list retval; |
|
40 |
|
41 int nargin = args.length (); |
|
42 |
3243
|
43 if (nargin != 1 || nargout > 2) |
2928
|
44 { |
|
45 print_usage ("chol"); |
|
46 return retval; |
|
47 } |
|
48 |
|
49 octave_value arg = args(0); |
|
50 |
|
51 int nr = arg.rows (); |
|
52 int nc = arg.columns (); |
|
53 |
|
54 int arg_is_empty = empty_arg ("chol", nr, nc); |
|
55 |
|
56 if (arg_is_empty < 0) |
|
57 return retval; |
|
58 if (arg_is_empty > 0) |
|
59 return Matrix (); |
|
60 |
|
61 if (arg.is_real_type ()) |
|
62 { |
|
63 Matrix m = arg.matrix_value (); |
|
64 |
|
65 if (! error_state) |
|
66 { |
|
67 int info; |
|
68 CHOL fact (m, info); |
3244
|
69 if (nargout == 2 || info == 0) |
3243
|
70 { |
|
71 retval(1) = static_cast<double> (info); |
|
72 retval(0) = fact.chol_matrix (); |
|
73 } |
3244
|
74 else |
|
75 error ("chol: matrix not positive definite"); |
2928
|
76 } |
|
77 } |
|
78 else if (arg.is_complex_type ()) |
|
79 { |
|
80 ComplexMatrix m = arg.complex_matrix_value (); |
|
81 |
|
82 if (! error_state) |
|
83 { |
|
84 int info; |
|
85 ComplexCHOL fact (m, info); |
3244
|
86 if (nargout == 2 || info == 0) |
3243
|
87 { |
|
88 retval(1) = static_cast<double> (info); |
|
89 retval(0) = fact.chol_matrix (); |
|
90 } |
3244
|
91 else |
|
92 error ("chol: matrix not positive definite"); |
2928
|
93 } |
|
94 } |
|
95 else |
|
96 { |
|
97 gripe_wrong_type_arg ("chol", arg); |
|
98 } |
|
99 |
|
100 return retval; |
|
101 } |
|
102 |
|
103 /* |
|
104 ;;; Local Variables: *** |
|
105 ;;; mode: C++ *** |
|
106 ;;; End: *** |
|
107 */ |
|
108 |