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" |
544
|
35 #include "help.h" |
519
|
36 #include "defun-dld.h" |
180
|
37 |
519
|
38 DEFUN_DLD ("chol", Fchol, Schol, 2, 1, |
|
39 "R = chol (X): cholesky factorization") |
180
|
40 { |
519
|
41 Octave_object retval; |
|
42 |
|
43 int nargin = args.length (); |
180
|
44 |
519
|
45 if (nargin != 2 || nargout > 1) |
|
46 { |
|
47 print_usage ("chol"); |
|
48 return retval; |
|
49 } |
180
|
50 |
519
|
51 tree_constant tmp = args(1).make_numeric (); |
180
|
52 |
|
53 int nr = tmp.rows (); |
|
54 int nc = tmp.columns (); |
|
55 |
|
56 if (nr == 0 || nc == 0) |
|
57 { |
|
58 int flag = user_pref.propagate_empty_matrices; |
|
59 if (flag != 0) |
|
60 { |
|
61 if (flag < 0) |
|
62 gripe_empty_arg ("chol", 0); |
519
|
63 |
|
64 retval.resize (1, Matrix ()); |
180
|
65 } |
|
66 else |
|
67 gripe_empty_arg ("chol", 1); |
|
68 |
|
69 return retval; |
|
70 } |
|
71 |
|
72 switch (tmp.const_type ()) |
|
73 { |
|
74 case tree_constant_rep::matrix_constant: |
|
75 { |
|
76 Matrix m = tmp.matrix_value (); |
|
77 int info; |
|
78 CHOL fact (m, info); |
|
79 if (info != 0) |
|
80 error ("chol: matrix not positive definite"); |
|
81 else |
516
|
82 retval = fact.chol_matrix (); |
180
|
83 } |
|
84 break; |
|
85 case tree_constant_rep::complex_matrix_constant: |
|
86 { |
|
87 ComplexMatrix m = tmp.complex_matrix_value (); |
|
88 int info; |
|
89 ComplexCHOL fact (m, info); |
|
90 if (info != 0) |
|
91 error ("chol: matrix not positive definite"); |
|
92 else |
516
|
93 retval = fact.chol_matrix (); |
180
|
94 } |
|
95 break; |
|
96 case tree_constant_rep::scalar_constant: |
|
97 { |
|
98 double d = tmp.double_value (); |
516
|
99 retval = d; |
180
|
100 } |
|
101 break; |
|
102 case tree_constant_rep::complex_scalar_constant: |
|
103 { |
|
104 Complex c = tmp.complex_value (); |
516
|
105 retval = c; |
180
|
106 } |
|
107 break; |
|
108 default: |
|
109 break; |
|
110 } |
|
111 return retval; |
|
112 } |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; page-delimiter: "^/\\*" *** |
|
118 ;;; End: *** |
|
119 */ |
|
120 |