7
|
1 // f-eig.cc -*- C++ -*- |
1
|
2 /* |
|
3 |
277
|
4 Copyright (C) 1993, 1994 John W. Eaton |
1
|
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" |
1
|
26 #endif |
|
27 |
445
|
28 #include "EIG.h" |
1
|
29 |
|
30 #include "tree-const.h" |
|
31 #include "user-prefs.h" |
|
32 #include "gripes.h" |
|
33 #include "error.h" |
7
|
34 #include "f-eig.h" |
1
|
35 |
|
36 #ifdef WITH_DLD |
|
37 tree_constant * |
277
|
38 builtin_eig_2 (const tree_constant *args, int nargin, int nargout) |
1
|
39 { |
|
40 return eig (args, nargin, nargout); |
|
41 } |
|
42 #endif |
|
43 |
|
44 tree_constant * |
163
|
45 eig (const tree_constant *args, int nargin, int nargout) |
1
|
46 { |
|
47 tree_constant *retval = NULL_TREE_CONST; |
|
48 |
|
49 tree_constant arg = args[1].make_numeric (); |
|
50 |
|
51 int a_nr = arg.rows (); |
|
52 int a_nc = arg.columns (); |
|
53 |
|
54 if (a_nr == 0 || a_nc == 0) |
|
55 { |
|
56 int flag = user_pref.propagate_empty_matrices; |
|
57 if (flag != 0) |
|
58 { |
|
59 if (flag < 0) |
|
60 gripe_empty_arg ("eig", 0); |
|
61 Matrix m; |
|
62 retval = new tree_constant [3]; |
|
63 retval[0] = tree_constant (m); |
|
64 retval[1] = tree_constant (m); |
|
65 } |
|
66 else |
|
67 gripe_empty_arg ("eig", 1); |
|
68 |
|
69 return retval; |
|
70 } |
|
71 |
|
72 if (a_nr != a_nc) |
|
73 { |
|
74 gripe_square_matrix_required ("eig"); |
|
75 return retval; |
|
76 } |
|
77 |
|
78 Matrix tmp; |
|
79 ComplexMatrix ctmp; |
|
80 EIG result; |
|
81 switch (arg.const_type ()) |
|
82 { |
|
83 case tree_constant_rep::scalar_constant: |
|
84 tmp.resize (1, 1); |
|
85 tmp.elem (0, 0) = arg.double_value (); |
|
86 result = EIG (tmp); |
|
87 break; |
|
88 case tree_constant_rep::matrix_constant: |
|
89 tmp = arg.matrix_value (); |
|
90 result = EIG (tmp); |
|
91 break; |
|
92 case tree_constant_rep::complex_scalar_constant: |
|
93 ctmp.resize (1, 1); |
|
94 ctmp.elem (0, 0) = arg.complex_value (); |
|
95 result = EIG (ctmp); |
|
96 break; |
|
97 case tree_constant_rep::complex_matrix_constant: |
|
98 ctmp = arg.complex_matrix_value (); |
|
99 result = EIG (ctmp); |
|
100 break; |
|
101 default: |
|
102 panic_impossible (); |
|
103 break; |
|
104 } |
|
105 |
|
106 if (nargout == 1) |
|
107 { |
|
108 retval = new tree_constant [2]; |
|
109 retval[0] = tree_constant (result.eigenvalues (), 1); |
|
110 } |
|
111 else |
|
112 { |
|
113 // Blame it on Matlab. |
|
114 |
|
115 ComplexDiagMatrix d (result.eigenvalues ()); |
|
116 |
|
117 retval = new tree_constant [3]; |
|
118 retval[0] = tree_constant (result.eigenvectors ()); |
|
119 retval[1] = tree_constant (d); |
|
120 } |
|
121 |
|
122 return retval; |
|
123 } |
|
124 |
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; page-delimiter: "^/\\*" *** |
|
129 ;;; End: *** |
|
130 */ |