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 |
|
36 DEFUN_DLD (det, args, , |
3548
|
37 "-*- texinfo -*-\n\ |
3372
|
38 @deftypefn {Loadable Function} {} det (@var{a})\n\ |
|
39 Compute the determinant of @var{a} using @sc{Linpack}.\n\ |
|
40 @end deftypefn") |
2928
|
41 { |
|
42 octave_value_list retval; |
|
43 |
|
44 int nargin = args.length (); |
|
45 |
|
46 if (nargin != 1) |
|
47 { |
|
48 print_usage ("det"); |
|
49 return retval; |
|
50 } |
|
51 |
|
52 octave_value arg = args(0); |
|
53 |
|
54 int nr = arg.rows (); |
|
55 int nc = arg.columns (); |
|
56 |
|
57 if (nr == 0 && nc == 0) |
|
58 { |
|
59 retval = 1.0; |
|
60 return retval; |
|
61 } |
|
62 |
|
63 int arg_is_empty = empty_arg ("det", nr, nc); |
|
64 if (arg_is_empty < 0) |
|
65 return retval; |
|
66 if (arg_is_empty > 0) |
|
67 return Matrix (1, 1, 1.0); |
|
68 |
|
69 if (nr != nc) |
|
70 { |
|
71 gripe_square_matrix_required ("det"); |
|
72 return retval; |
|
73 } |
|
74 |
|
75 if (arg.is_real_type ()) |
|
76 { |
|
77 Matrix m = arg.matrix_value (); |
|
78 |
|
79 if (! error_state) |
|
80 { |
|
81 int info; |
|
82 double rcond = 0.0; |
|
83 |
|
84 DET det = m.determinant (info, rcond); |
|
85 |
|
86 double d = 0.0; |
|
87 |
|
88 if (info == -1) |
|
89 warning ("det: matrix singular to machine precision, rcond = %g", |
|
90 rcond); |
|
91 else |
|
92 d = det.value (); |
|
93 |
|
94 retval = d; |
|
95 } |
|
96 } |
|
97 else if (arg.is_complex_type ()) |
|
98 { |
|
99 ComplexMatrix m = arg.complex_matrix_value (); |
|
100 |
|
101 if (! error_state) |
|
102 { |
|
103 int info; |
|
104 double rcond = 0.0; |
|
105 |
|
106 ComplexDET det = m.determinant (info, rcond); |
|
107 |
|
108 Complex c = 0.0; |
|
109 |
|
110 if (info == -1) |
|
111 warning ("det: matrix singular to machine precision, rcond = %g", |
|
112 rcond); |
|
113 else |
|
114 c = det.value (); |
|
115 |
|
116 retval = c; |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 gripe_wrong_type_arg ("det", arg); |
|
122 } |
|
123 |
|
124 return retval; |
|
125 } |
|
126 |
|
127 /* |
|
128 ;;; Local Variables: *** |
|
129 ;;; mode: C++ *** |
|
130 ;;; End: *** |
|
131 */ |