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 "CmplxDET.h" |
|
28 #include "dbleDET.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 |
3808
|
36 DEFUN_DLD (det, args, nargout, |
3548
|
37 "-*- texinfo -*-\n\ |
3808
|
38 @deftypefn {Loadable Function} {[@var{d}, @var{rcond}] = } det (@var{a})\n\ |
4329
|
39 Compute the determinant of @var{a} using @sc{Lapack}. Return an estimate\n\ |
3808
|
40 of the reciprocal condition number if requested.\n\ |
3372
|
41 @end deftypefn") |
2928
|
42 { |
|
43 octave_value_list retval; |
|
44 |
|
45 int nargin = args.length (); |
|
46 |
|
47 if (nargin != 1) |
|
48 { |
|
49 print_usage ("det"); |
|
50 return retval; |
|
51 } |
|
52 |
|
53 octave_value arg = args(0); |
|
54 |
|
55 int nr = arg.rows (); |
|
56 int nc = arg.columns (); |
|
57 |
|
58 if (nr == 0 && nc == 0) |
|
59 { |
4233
|
60 retval(0) = 1.0; |
2928
|
61 return retval; |
|
62 } |
|
63 |
|
64 int arg_is_empty = empty_arg ("det", nr, nc); |
|
65 if (arg_is_empty < 0) |
|
66 return retval; |
|
67 if (arg_is_empty > 0) |
4233
|
68 return octave_value (Matrix (1, 1, 1.0)); |
2928
|
69 |
|
70 if (nr != nc) |
|
71 { |
|
72 gripe_square_matrix_required ("det"); |
|
73 return retval; |
|
74 } |
|
75 |
|
76 if (arg.is_real_type ()) |
|
77 { |
|
78 Matrix m = arg.matrix_value (); |
|
79 |
|
80 if (! error_state) |
|
81 { |
5070
|
82 // Always compute rcond, so we can detect numerically |
|
83 // singular matrices. |
|
84 |
2928
|
85 int info; |
5064
|
86 double rcond = 0.0; |
5070
|
87 DET det = m.determinant (info, rcond); |
|
88 retval(1) = rcond; |
|
89 volatile double xrcond = rcond; |
|
90 xrcond += 1.0; |
|
91 retval(0) = ((info == -1 || xrcond == 1.0) ? 0.0 : det.value ()); |
2928
|
92 } |
|
93 } |
|
94 else if (arg.is_complex_type ()) |
|
95 { |
|
96 ComplexMatrix m = arg.complex_matrix_value (); |
|
97 |
|
98 if (! error_state) |
|
99 { |
5070
|
100 // Always compute rcond, so we can detect numerically |
|
101 // singular matrices. |
|
102 |
2928
|
103 int info; |
5064
|
104 double rcond = 0.0; |
5070
|
105 ComplexDET det = m.determinant (info, rcond); |
|
106 retval(1) = rcond; |
|
107 volatile double xrcond = rcond; |
|
108 xrcond += 1.0; |
|
109 retval(0) = ((info == -1 || xrcond == 1.0) |
|
110 ? Complex (0.0) : det.value ()); |
2928
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 gripe_wrong_type_arg ("det", arg); |
|
116 } |
|
117 |
|
118 return retval; |
|
119 } |
|
120 |
|
121 /* |
|
122 ;;; Local Variables: *** |
|
123 ;;; mode: C++ *** |
|
124 ;;; End: *** |
|
125 */ |