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, |
3372
|
37 "-*- texinfo -*- |
|
38 @deftypefn {Loadable Function} {} chol (@var{a})\n\ |
|
39 @cindex Cholesky factorization\n\ |
|
40 Compute the Cholesky factor, @var{r}, of the symmetric positive definite\n\ |
|
41 matrix @var{a}, where\n\ |
|
42 @iftex\n\ |
|
43 @tex\n\ |
|
44 $ R^T R = A $.\n\ |
|
45 @end tex\n\ |
|
46 @end iftex\n\ |
|
47 @ifinfo\n\ |
|
48 \n\ |
|
49 @example\n\ |
|
50 r' * r = a.\n\ |
|
51 @end example\n\ |
|
52 @end ifinfo\n\ |
|
53 @end deftypefn") |
2928
|
54 { |
|
55 octave_value_list retval; |
|
56 |
|
57 int nargin = args.length (); |
|
58 |
3243
|
59 if (nargin != 1 || nargout > 2) |
2928
|
60 { |
|
61 print_usage ("chol"); |
|
62 return retval; |
|
63 } |
|
64 |
|
65 octave_value arg = args(0); |
|
66 |
|
67 int nr = arg.rows (); |
|
68 int nc = arg.columns (); |
|
69 |
|
70 int arg_is_empty = empty_arg ("chol", nr, nc); |
|
71 |
|
72 if (arg_is_empty < 0) |
|
73 return retval; |
|
74 if (arg_is_empty > 0) |
|
75 return Matrix (); |
|
76 |
|
77 if (arg.is_real_type ()) |
|
78 { |
|
79 Matrix m = arg.matrix_value (); |
|
80 |
|
81 if (! error_state) |
|
82 { |
|
83 int info; |
|
84 CHOL fact (m, info); |
3244
|
85 if (nargout == 2 || info == 0) |
3243
|
86 { |
|
87 retval(1) = static_cast<double> (info); |
|
88 retval(0) = fact.chol_matrix (); |
|
89 } |
3244
|
90 else |
|
91 error ("chol: matrix not positive definite"); |
2928
|
92 } |
|
93 } |
|
94 else if (arg.is_complex_type ()) |
|
95 { |
|
96 ComplexMatrix m = arg.complex_matrix_value (); |
|
97 |
|
98 if (! error_state) |
|
99 { |
|
100 int info; |
|
101 ComplexCHOL fact (m, info); |
3244
|
102 if (nargout == 2 || info == 0) |
3243
|
103 { |
|
104 retval(1) = static_cast<double> (info); |
|
105 retval(0) = fact.chol_matrix (); |
|
106 } |
3244
|
107 else |
|
108 error ("chol: matrix not positive definite"); |
2928
|
109 } |
|
110 } |
|
111 else |
|
112 { |
|
113 gripe_wrong_type_arg ("chol", arg); |
|
114 } |
|
115 |
|
116 return retval; |
|
117 } |
|
118 |
|
119 /* |
|
120 ;;; Local Variables: *** |
|
121 ;;; mode: C++ *** |
|
122 ;;; End: *** |
|
123 */ |
|
124 |