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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "CmplxCHOL.h" |
|
29 #include "dbleCHOL.h" |
|
30 |
|
31 #include "defun-dld.h" |
|
32 #include "error.h" |
|
33 #include "gripes.h" |
|
34 #include "oct-obj.h" |
|
35 #include "utils.h" |
|
36 |
|
37 DEFUN_DLD (chol, args, nargout, |
3548
|
38 "-*- texinfo -*-\n\ |
3372
|
39 @deftypefn {Loadable Function} {} chol (@var{a})\n\ |
|
40 @cindex Cholesky factorization\n\ |
|
41 Compute the Cholesky factor, @var{r}, of the symmetric positive definite\n\ |
|
42 matrix @var{a}, where\n\ |
|
43 @iftex\n\ |
|
44 @tex\n\ |
|
45 $ R^T R = A $.\n\ |
|
46 @end tex\n\ |
|
47 @end iftex\n\ |
|
48 @ifinfo\n\ |
|
49 \n\ |
|
50 @example\n\ |
|
51 r' * r = a.\n\ |
|
52 @end example\n\ |
|
53 @end ifinfo\n\ |
|
54 @end deftypefn") |
2928
|
55 { |
|
56 octave_value_list retval; |
|
57 |
|
58 int nargin = args.length (); |
|
59 |
3243
|
60 if (nargin != 1 || nargout > 2) |
2928
|
61 { |
|
62 print_usage ("chol"); |
|
63 return retval; |
|
64 } |
|
65 |
|
66 octave_value arg = args(0); |
|
67 |
5275
|
68 octave_idx_type nr = arg.rows (); |
|
69 octave_idx_type nc = arg.columns (); |
2928
|
70 |
|
71 int arg_is_empty = empty_arg ("chol", nr, nc); |
|
72 |
|
73 if (arg_is_empty < 0) |
|
74 return retval; |
|
75 if (arg_is_empty > 0) |
4233
|
76 return octave_value (Matrix ()); |
2928
|
77 |
|
78 if (arg.is_real_type ()) |
|
79 { |
|
80 Matrix m = arg.matrix_value (); |
|
81 |
|
82 if (! error_state) |
|
83 { |
5275
|
84 octave_idx_type info; |
2928
|
85 CHOL 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 if (arg.is_complex_type ()) |
|
96 { |
|
97 ComplexMatrix m = arg.complex_matrix_value (); |
|
98 |
|
99 if (! error_state) |
|
100 { |
5275
|
101 octave_idx_type info; |
2928
|
102 ComplexCHOL fact (m, info); |
3244
|
103 if (nargout == 2 || info == 0) |
3243
|
104 { |
|
105 retval(1) = static_cast<double> (info); |
|
106 retval(0) = fact.chol_matrix (); |
|
107 } |
3244
|
108 else |
|
109 error ("chol: matrix not positive definite"); |
2928
|
110 } |
|
111 } |
|
112 else |
|
113 { |
|
114 gripe_wrong_type_arg ("chol", arg); |
|
115 } |
|
116 |
|
117 return retval; |
|
118 } |
|
119 |
|
120 /* |
|
121 ;;; Local Variables: *** |
|
122 ;;; mode: C++ *** |
|
123 ;;; End: *** |
|
124 */ |
|
125 |