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\ |
|
39 Compute the determinant of @var{a} using @sc{Linpack}. Return an estimate\n\ |
|
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 { |
|
60 retval = 1.0; |
|
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) |
|
68 return Matrix (1, 1, 1.0); |
|
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 { |
|
82 int info; |
|
83 double rcond = 0.0; |
|
84 |
|
85 DET det = m.determinant (info, rcond); |
|
86 |
3808
|
87 if (nargout > 1) |
|
88 retval(1) = rcond; |
2928
|
89 |
3808
|
90 retval(0) = (info == -1 ? 0.0 : det.value ()); |
2928
|
91 } |
|
92 } |
|
93 else if (arg.is_complex_type ()) |
|
94 { |
|
95 ComplexMatrix m = arg.complex_matrix_value (); |
|
96 |
|
97 if (! error_state) |
|
98 { |
|
99 int info; |
|
100 double rcond = 0.0; |
|
101 |
|
102 ComplexDET det = m.determinant (info, rcond); |
|
103 |
3808
|
104 if (nargout > 1) |
|
105 retval(1) = rcond; |
2928
|
106 |
3808
|
107 retval(0) = (info == -1 ? 0.0 : det.value ()); |
2928
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 gripe_wrong_type_arg ("det", arg); |
|
113 } |
|
114 |
|
115 return retval; |
|
116 } |
|
117 |
|
118 /* |
|
119 ;;; Local Variables: *** |
|
120 ;;; mode: C++ *** |
|
121 ;;; End: *** |
|
122 */ |