1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
1
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
445
|
27 #include "EIG.h" |
1
|
28 |
1352
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "help.h" |
1740
|
33 #include "oct-obj.h" |
636
|
34 #include "utils.h" |
1
|
35 |
2465
|
36 DEFUN_DLD (eig, args, nargout, |
519
|
37 "eig (X) or [V, D] = eig (X): compute eigenvalues and eigenvectors of X") |
1
|
38 { |
2086
|
39 octave_value_list retval; |
1
|
40 |
712
|
41 int nargin = args.length (); |
|
42 |
|
43 if (nargin != 1 || nargout > 2) |
519
|
44 { |
|
45 print_usage ("eig"); |
|
46 return retval; |
|
47 } |
|
48 |
2086
|
49 octave_value arg = args(0); |
1
|
50 |
636
|
51 int nr = arg.rows (); |
|
52 int nc = arg.columns (); |
1
|
53 |
718
|
54 int arg_is_empty = empty_arg ("eig", nr, nc); |
|
55 if (arg_is_empty < 0) |
636
|
56 return retval; |
718
|
57 else if (arg_is_empty > 0) |
2086
|
58 return octave_value_list (2, Matrix ()); |
1
|
59 |
636
|
60 if (nr != nc) |
1
|
61 { |
|
62 gripe_square_matrix_required ("eig"); |
|
63 return retval; |
|
64 } |
|
65 |
|
66 Matrix tmp; |
|
67 ComplexMatrix ctmp; |
|
68 EIG result; |
636
|
69 |
|
70 if (arg.is_real_type ()) |
620
|
71 { |
1
|
72 tmp = arg.matrix_value (); |
636
|
73 |
|
74 if (error_state) |
|
75 return retval; |
|
76 else |
|
77 result = EIG (tmp); |
620
|
78 } |
636
|
79 else if (arg.is_complex_type ()) |
620
|
80 { |
1
|
81 ctmp = arg.complex_matrix_value (); |
636
|
82 |
|
83 if (error_state) |
|
84 return retval; |
|
85 else |
|
86 result = EIG (ctmp); |
620
|
87 } |
|
88 else |
|
89 { |
|
90 gripe_wrong_type_arg ("eig", tmp); |
|
91 return retval; |
1
|
92 } |
|
93 |
497
|
94 if (nargout == 0 || nargout == 1) |
1
|
95 { |
516
|
96 retval(0) = result.eigenvalues (), 1; |
1
|
97 } |
|
98 else |
|
99 { |
1357
|
100 // Blame it on Matlab. |
1
|
101 |
|
102 ComplexDiagMatrix d (result.eigenvalues ()); |
|
103 |
620
|
104 retval(1) = d; |
516
|
105 retval(0) = result.eigenvectors (); |
1
|
106 } |
|
107 |
|
108 return retval; |
|
109 } |
|
110 |
|
111 /* |
|
112 ;;; Local Variables: *** |
|
113 ;;; mode: C++ *** |
|
114 ;;; End: *** |
|
115 */ |