180
|
1 // f-chol.cc -*- C++ -*- |
|
2 /* |
|
3 |
453
|
4 Copyright (C) 1993, 1994 John W. Eaton |
180
|
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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
180
|
26 #endif |
|
27 |
453
|
28 #include "dbleCHOL.h" |
|
29 #include "CmplxCHOL.h" |
180
|
30 |
|
31 #include "tree-const.h" |
|
32 #include "user-prefs.h" |
|
33 #include "gripes.h" |
|
34 #include "error.h" |
636
|
35 #include "utils.h" |
544
|
36 #include "help.h" |
519
|
37 #include "defun-dld.h" |
180
|
38 |
701
|
39 DEFUN_DLD_BUILTIN ("chol", Fchol, Schol, 2, 1, |
519
|
40 "R = chol (X): cholesky factorization") |
180
|
41 { |
519
|
42 Octave_object retval; |
|
43 |
712
|
44 int nargin = args.length (); |
|
45 |
|
46 if (nargin != 1 || nargout > 1) |
519
|
47 { |
|
48 print_usage ("chol"); |
|
49 return retval; |
|
50 } |
180
|
51 |
712
|
52 tree_constant arg = args(0); |
180
|
53 |
636
|
54 int nr = arg.rows (); |
|
55 int nc = arg.columns (); |
180
|
56 |
636
|
57 if (empty_arg ("chol", nr, nc) < 0) |
|
58 return retval; |
519
|
59 |
636
|
60 if (arg.is_real_type ()) |
620
|
61 { |
636
|
62 Matrix m = arg.matrix_value (); |
|
63 |
|
64 if (! error_state) |
|
65 { |
|
66 int info; |
|
67 CHOL fact (m, info); |
|
68 if (info != 0) |
|
69 error ("chol: matrix not positive definite"); |
|
70 else |
|
71 retval = fact.chol_matrix (); |
|
72 } |
620
|
73 } |
636
|
74 else if (arg.is_complex_type ()) |
180
|
75 { |
636
|
76 ComplexMatrix m = arg.complex_matrix_value (); |
|
77 |
|
78 if (! error_state) |
|
79 { |
|
80 int info; |
|
81 ComplexCHOL fact (m, info); |
|
82 if (info != 0) |
|
83 error ("chol: matrix not positive definite"); |
|
84 else |
|
85 retval = fact.chol_matrix (); |
|
86 } |
620
|
87 } |
|
88 else |
|
89 { |
636
|
90 gripe_wrong_type_arg ("chol", arg); |
620
|
91 } |
|
92 |
180
|
93 return retval; |
|
94 } |
|
95 |
|
96 /* |
|
97 ;;; Local Variables: *** |
|
98 ;;; mode: C++ *** |
|
99 ;;; page-delimiter: "^/\\*" *** |
|
100 ;;; End: *** |
|
101 */ |
|
102 |