180
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
180
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
180
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
180
|
25 #endif |
|
26 |
1352
|
27 #include "CmplxCHOL.h" |
453
|
28 #include "dbleCHOL.h" |
180
|
29 |
1352
|
30 #include "defun-dld.h" |
|
31 #include "error.h" |
|
32 #include "gripes.h" |
|
33 #include "help.h" |
1740
|
34 #include "oct-obj.h" |
636
|
35 #include "utils.h" |
180
|
36 |
2465
|
37 DEFUN_DLD (chol, args, nargout, |
519
|
38 "R = chol (X): cholesky factorization") |
180
|
39 { |
2086
|
40 octave_value_list retval; |
519
|
41 |
712
|
42 int nargin = args.length (); |
|
43 |
|
44 if (nargin != 1 || nargout > 1) |
519
|
45 { |
|
46 print_usage ("chol"); |
|
47 return retval; |
|
48 } |
180
|
49 |
2086
|
50 octave_value arg = args(0); |
180
|
51 |
636
|
52 int nr = arg.rows (); |
|
53 int nc = arg.columns (); |
180
|
54 |
718
|
55 int arg_is_empty = empty_arg ("chol", nr, nc); |
|
56 |
|
57 if (arg_is_empty < 0) |
636
|
58 return retval; |
718
|
59 if (arg_is_empty > 0) |
|
60 return Matrix (); |
519
|
61 |
636
|
62 if (arg.is_real_type ()) |
620
|
63 { |
636
|
64 Matrix m = arg.matrix_value (); |
|
65 |
|
66 if (! error_state) |
|
67 { |
|
68 int info; |
|
69 CHOL fact (m, info); |
|
70 if (info != 0) |
|
71 error ("chol: matrix not positive definite"); |
|
72 else |
|
73 retval = fact.chol_matrix (); |
|
74 } |
620
|
75 } |
636
|
76 else if (arg.is_complex_type ()) |
180
|
77 { |
636
|
78 ComplexMatrix m = arg.complex_matrix_value (); |
|
79 |
|
80 if (! error_state) |
|
81 { |
|
82 int info; |
|
83 ComplexCHOL fact (m, info); |
|
84 if (info != 0) |
|
85 error ("chol: matrix not positive definite"); |
|
86 else |
|
87 retval = fact.chol_matrix (); |
|
88 } |
620
|
89 } |
|
90 else |
|
91 { |
636
|
92 gripe_wrong_type_arg ("chol", arg); |
620
|
93 } |
|
94 |
180
|
95 return retval; |
|
96 } |
|
97 |
|
98 /* |
|
99 ;;; Local Variables: *** |
|
100 ;;; mode: C++ *** |
|
101 ;;; End: *** |
|
102 */ |
|
103 |