Mercurial > hg > octave-lyh
annotate src/DLD-FUNCTIONS/eigs.cc @ 8683:e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 05 Feb 2009 13:09:22 -0500 |
parents | e6497be3f3d6 |
children | 3c4628550318 |
rev | line source |
---|---|
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 Copyright (C) 2005 David Bateman |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 This file is part of Octave. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 Octave is free software; you can redistribute it and/or modify it |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 Free Software Foundation; either version 3 of the License, or (at your |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 option) any later version. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 for more details. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 <http://www.gnu.org/licenses/>. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
21 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
22 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
23 #ifdef HAVE_CONFIG_H |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
24 #include <config.h> |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
25 #endif |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 #include "ov.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 #include "defun-dld.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
29 #include "error.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 #include "gripes.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 #include "quit.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 #include "variables.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
33 #include "ov-re-sparse.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
34 #include "ov-cx-sparse.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
35 #include "oct-map.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
36 #include "pager.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
37 #include "unwind-prot.h" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
38 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 #include "eigs-base.cc" |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
41 // Global pointer for user defined function. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
42 static octave_function *eigs_fcn = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
43 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 // Have we warned about imaginary values returned from user function? |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
45 static bool warned_imaginary = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
46 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
47 // Is this a recursive call? |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
48 static int call_depth = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
49 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
50 ColumnVector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
51 eigs_func (const ColumnVector &x, int &eigs_error) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
52 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
53 ColumnVector retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
54 octave_value_list args; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
55 args(0) = x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
56 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
57 if (eigs_fcn) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
58 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
59 octave_value_list tmp = eigs_fcn->do_multi_index_op (1, args); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
60 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
61 if (error_state) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
62 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
63 eigs_error = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
64 gripe_user_supplied_eval ("eigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
65 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
66 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
67 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
68 if (tmp.length () && tmp(0).is_defined ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
69 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
70 if (! warned_imaginary && tmp(0).is_complex_type ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
71 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
72 warning ("eigs: ignoring imaginary part returned from user-supplied function"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
73 warned_imaginary = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
74 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
75 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
76 retval = ColumnVector (tmp(0).vector_value ()); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
77 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
78 if (error_state) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
79 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
80 eigs_error = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
81 gripe_user_supplied_eval ("eigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
82 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
83 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
84 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
85 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
86 eigs_error = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
87 gripe_user_supplied_eval ("eigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
88 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
89 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
90 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
91 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
92 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
93 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
94 ComplexColumnVector |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
95 eigs_complex_func (const ComplexColumnVector &x, int &eigs_error) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
96 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
97 ComplexColumnVector retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
98 octave_value_list args; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
99 args(0) = x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
100 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
101 if (eigs_fcn) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
102 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
103 octave_value_list tmp = eigs_fcn->do_multi_index_op (1, args); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
104 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
105 if (error_state) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
106 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
107 eigs_error = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
108 gripe_user_supplied_eval ("eigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
109 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
110 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
111 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
112 if (tmp.length () && tmp(0).is_defined ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
113 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
114 retval = ComplexColumnVector (tmp(0).complex_vector_value ()); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
115 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
116 if (error_state) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
117 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
118 eigs_error = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
119 gripe_user_supplied_eval ("eigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
120 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
121 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
122 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
123 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
124 eigs_error = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
125 gripe_user_supplied_eval ("eigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
126 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
127 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
128 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
129 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
130 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
131 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
132 DEFUN_DLD (eigs, args, nargout, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
133 "-*- texinfo -*-\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
134 @deftypefn {Loadable Function} {@var{d}} = eigs (@var{a})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
135 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{a}, @var{k})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
136 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{a}, @var{k}, @var{sigma})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
137 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{a}, @var{k}, @var{sigma},@var{opts})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
138 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{a}, @var{b})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
139 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{a}, @var{b}, @var{k})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
140 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{a}, @var{b}, @var{k}, @var{sigma})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
141 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{a}, @var{b}, @var{k}, @var{sigma}, @var{opts})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
142 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
143 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n}, @var{b})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
144 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n}, @var{k})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
145 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n}, @var{b}, @var{k})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
146 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n}, @var{k}, @var{sigma})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
147 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n}, @var{b}, @var{k}, @var{sigma})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
148 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n}, @var{k}, @var{sigma}, @var{opts})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
149 @deftypefnx {Loadable Function} {@var{d}} = eigs (@var{af}, @var{n}, @var{b}, @var{k}, @var{sigma}, @var{opts})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
150 @deftypefnx {Loadable Function} {[@var{v}, @var{d}]} = eigs (@var{a}, @dots{})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
151 @deftypefnx {Loadable Function} {[@var{v}, @var{d}]} = eigs (@var{af}, @var{n}, @dots{})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
152 @deftypefnx {Loadable Function} {[@var{v}, @var{d}, @var{flag}]} = eigs (@var{a}, @dots{})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
153 @deftypefnx {Loadable Function} {[@var{v}, @var{d}, @var{flag}]} = eigs (@var{af}, @var{n}, @dots{})\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
154 Calculate a limited number of eigenvalues and eigenvectors of @var{a},\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
155 based on a selection criteria. The number eigenvalues and eigenvectors to\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
156 calculate is given by @var{k} whose default value is 6.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
157 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
158 By default @code{eigs} solve the equation\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
159 @iftex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
160 @tex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
161 $A \\nu = \\lambda \\nu$\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
162 @end tex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
163 @end iftex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
164 @ifinfo\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
165 @code{A * v = lambda * v}\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
166 @end ifinfo\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
167 , where\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
168 @iftex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
169 @tex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
170 $\\lambda$ is a scalar representing one of the eigenvalues, and $\\nu$\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
171 @end tex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
172 @end iftex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
173 @ifinfo\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
174 @code{lambda} is a scalar representing one of the eigenvalues, and @code{v}\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
175 @end ifinfo\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
176 is the corresponding eigenvector. If given the positive definite matrix\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
177 @var{B} then @code{eigs} solves the general eigenvalue equation\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
178 @iftex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
179 @tex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
180 $A \\nu = \\lambda B \\nu$\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
181 @end tex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
182 @end iftex\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
183 @ifinfo\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
184 @code{A * v = lambda * B * v}\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
185 @end ifinfo\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
186 .\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
187 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
188 The argument @var{sigma} determines which eigenvalues are returned.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
189 @var{sigma} can be either a scalar or a string. When @var{sigma} is a scalar,\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
190 the @var{k} eigenvalues closest to @var{sigma} are returned. If @var{sigma}\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
191 is a string, it must have one of the values\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
192 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
193 @table @asis\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
194 @item 'lm'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
195 Largest magnitude (default).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
196 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
197 @item 'sm'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
198 Smallest magnitude.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
199 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
200 @item 'la'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
201 Largest Algebraic (valid only for real symmetric problems).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
202 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
203 @item 'sa'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
204 Smallest Algebraic (valid only for real symmetric problems).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
205 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
206 @item 'be'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
207 Both ends, with one more from the high-end if @var{k} is odd (valid only for\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
208 real symmetric problems).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
209 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
210 @item 'lr'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
211 Largest real part (valid only for complex or unsymmetric problems).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
212 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
213 @item 'sr'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
214 Smallest real part (valid only for complex or unsymmetric problems).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
215 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
216 @item 'li'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
217 Largest imaginary part (valid only for complex or unsymmetric problems).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
218 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
219 @item 'si'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
220 Smallest imaginary part (valid only for complex or unsymmetric problems).\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
221 @end table\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
222 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
223 If @var{opts} is given, it is a structure defining some of the options that\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
224 @code{eigs} should use. The fields of the structure @var{opts} are\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
225 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
226 @table @code\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
227 @item issym\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
228 If @var{af} is given, then flags whether the function @var{af} defines a\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
229 symmetric problem. It is ignored if @var{a} is given. The default is false.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
230 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
231 @item isreal\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
232 If @var{af} is given, then flags whether the function @var{af} defines a\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
233 real problem. It is ignored if @var{a} is given. The default is true.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
234 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
235 @item tol\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
236 Defines the required convergence tolerance, given as @code{tol * norm (A)}.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
237 The default is @code{eps}.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
238 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
239 @item maxit\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
240 The maximum number of iterations. The default is 300.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
241 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
242 @item p\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
243 The number of Lanzcos basis vectors to use. More vectors will result in\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
244 faster convergence, but a larger amount of memory. The optimal value of 'p'\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
245 is problem dependent and should be in the range @var{k} to @var{n}. The\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
246 default value is @code{2 * @var{k}}.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
247 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
248 @item v0\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
249 The starting vector for the computation. The default is to have @sc{Arpack}\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
250 randomly generate a starting vector.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
251 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
252 @item disp\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
253 The level of diagnostic printout. If @code{disp} is 0 then there is no\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
254 printout. The default value is 1.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
255 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
256 @item cholB\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
257 Flag if @code{chol (@var{b})} is passed rather than @var{b}. The default is\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
258 false.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
259 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
260 @item permB\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
261 The permutation vector of the Cholesky factorization of @var{b} if\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
262 @code{cholB} is true. That is @code{chol ( @var{b} (permB, permB))}. The\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
263 default is @code{1:@var{n}}.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
264 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
265 @end table\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
266 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
267 It is also possible to represent @var{a} by a function denoted @var{af}.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
268 @var{af} must be followed by a scalar argument @var{n} defining the length\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
269 of the vector argument accepted by @var{af}. @var{af} can be passed either\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
270 as an inline function, function handle or as a string. In the case where\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
271 @var{af} is passed as a string, the name of the string defines the function\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
272 to use.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
273 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
274 @var{af} is a function of the form @code{function y = af (x), y = @dots{};\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
275 endfunction}, where the required return value of @var{af} is determined by\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
276 the value of @var{sigma}, and are\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
277 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
278 @table @code\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
279 @item A * x\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
280 If @var{sigma} is not given or is a string other than 'sm'.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
281 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
282 @item A \\ x\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
283 If @var{sigma} is 'sm'.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
284 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
285 @item (A - sigma * I) \\ x\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
286 for standard eigenvalue problem, where @code{I} is the identity matrix of\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
287 the same size as @code{A}. If @var{sigma} is zero, this reduces the\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
288 @code{A \\ x}.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
289 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
290 @item (A - sigma * B) \\ x\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
291 for the general eigenvalue problem.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
292 @end table\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
293 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
294 The return arguments of @code{eigs} depends on the number of return\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
295 arguments. With a single return argument, a vector @var{d} of length @var{k}\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
296 is returned, represent the @var{k} eigenvalues that have been found. With two\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
297 return arguments, @var{v} is a @var{n}-by-@var{k} matrix whose columns are\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
298 the @var{k} eigenvectors corresponding to the returned eigenvalues. The\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
299 eigenvalues themselves are then returned in @var{d} in the form of a\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
300 @var{n}-by-@var{k} matrix, where the elements on the diagonal are the\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
301 eigenvalues.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
302 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
303 Given a third return argument @var{flag}, @code{eigs} also returns the status\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
304 of the convergence. If @var{flag} is 0, then all eigenvalues have converged,\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
305 otherwise not.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
306 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
307 This function is based on the @sc{Arpack} package, written by R Lehoucq,\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
308 K Maschhoff, D Sorensen and C Yang. For more information see\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
309 @url{http://www.caam.rice.edu/software/ARPACK/}.\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
310 \n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
311 @end deftypefn\n\ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
312 @seealso{eig, svds}") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
313 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
314 octave_value_list retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
315 #ifdef HAVE_ARPACK |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
316 int nargin = args.length (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
317 std::string fcn_name; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
318 octave_idx_type n = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
319 octave_idx_type k = 6; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
320 Complex sigma = 0.; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
321 double sigmar, sigmai; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
322 bool have_sigma = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
323 std::string typ = "LM"; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
324 Matrix amm, bmm, bmt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
325 ComplexMatrix acm, bcm, bct; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
326 SparseMatrix asmm, bsmm, bsmt; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
327 SparseComplexMatrix ascm, bscm, bsct; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
328 int b_arg = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
329 bool have_b = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
330 bool have_a_fun = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
331 bool a_is_complex = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
332 bool b_is_complex = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
333 bool symmetric = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
334 bool cholB = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
335 bool a_is_sparse = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
336 ColumnVector permB; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
337 int arg_offset = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
338 double tol = DBL_EPSILON; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
339 int maxit = 300; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
340 int disp = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
341 octave_idx_type p = -1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
342 ColumnVector resid; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
343 ComplexColumnVector cresid; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
344 octave_idx_type info = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
345 char bmat = 'I'; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
346 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
347 warned_imaginary = false; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
348 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
349 unwind_protect::begin_frame ("Feigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
350 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
351 unwind_protect_int (call_depth); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
352 call_depth++; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
353 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
354 if (call_depth > 1) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
355 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
356 error ("eigs: invalid recursive call"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
357 if (fcn_name.length()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
358 clear_function (fcn_name); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
359 unwind_protect::run_frame ("Feigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
360 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
361 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
362 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
363 if (nargin == 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
364 print_usage (); |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
365 else if (args(0).is_function_handle () || args(0).is_inline_function () |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
366 || args(0).is_string ()) |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
367 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
368 if (args(0).is_string ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
369 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
370 std::string name = args(0).string_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
371 std::string fname = "function y = "; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
372 fcn_name = unique_symbol_name ("__eigs_fcn_"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
373 fname.append (fcn_name); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
374 fname.append ("(x) y = "); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
375 eigs_fcn = extract_function (args(0), "eigs", fcn_name, fname, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
376 "; endfunction"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
377 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
378 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
379 eigs_fcn = args(0).function_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
380 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
381 if (!eigs_fcn) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
382 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
383 error ("eigs: unknown function"); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
384 return retval; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
385 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
386 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
387 if (nargin < 2) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
388 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
389 error ("eigs: incorrect number of arguments"); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
390 return retval; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
391 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
392 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
393 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
394 n = args(1).nint_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
395 arg_offset = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
396 have_a_fun = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
397 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
398 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
399 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
400 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
401 if (args(0).is_complex_type ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
402 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
403 if (args(0).is_sparse_type ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
404 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
405 ascm = (args(0).sparse_complex_matrix_value()); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
406 a_is_sparse = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
407 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
408 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
409 acm = (args(0).complex_matrix_value()); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
410 a_is_complex = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
411 symmetric = false; // ARAPACK doesn't special case complex symmetric |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
412 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
413 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
414 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
415 if (args(0).is_sparse_type ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
416 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
417 asmm = (args(0).sparse_matrix_value()); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
418 a_is_sparse = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
419 symmetric = asmm.is_symmetric(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
420 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
421 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
422 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
423 amm = (args(0).matrix_value()); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
424 symmetric = amm.is_symmetric(); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
425 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
426 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
427 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
428 // Note hold off reading B till later to avoid issues of double |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
429 // copies of the matrix if B is full/real while A is complex.. |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
430 if (!error_state && nargin > 1 && !(args(1).is_real_scalar ())) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
431 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
432 if (args(1).is_complex_type ()) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
433 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
434 b_arg = 1+arg_offset; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
435 have_b = true; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
436 bmat = 'G'; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
437 b_is_complex = true; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
438 arg_offset++; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
439 } |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
440 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
441 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
442 b_arg = 1+arg_offset; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
443 have_b = true; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
444 bmat = 'G'; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
445 arg_offset++; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
446 } |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
447 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
448 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
449 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
450 if (!error_state && nargin > (1+arg_offset)) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
451 k = args(1+arg_offset).nint_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
452 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
453 if (!error_state && nargin > (2+arg_offset)) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
454 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
455 if (args(2+arg_offset).is_real_scalar () |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
456 || args(2+arg_offset).is_complex_scalar ()) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
457 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
458 sigma = args(2+arg_offset).complex_value (); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
459 have_sigma = true; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
460 } |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
461 else if (args(2+arg_offset).is_string ()) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
462 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
463 typ = args(2+arg_offset).string_value (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
464 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
465 // Use STL function to convert to upper case |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
466 transform (typ.begin (), typ.end (), typ.begin (), toupper); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
467 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
468 sigma = 0.; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
469 } |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
470 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
471 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
472 error ("eigs: sigma must be a scalar or a string"); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
473 return retval; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
474 } |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
475 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
476 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
477 sigmar = std::real (sigma); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
478 sigmai = std::imag (sigma); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
479 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
480 if (!error_state && nargin > (3+arg_offset)) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
481 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
482 if (args(3+arg_offset).is_map ()) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
483 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
484 Octave_map map = args(3+arg_offset).map_value (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
485 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
486 // issym is ignored if A is not a function |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
487 if (map.contains ("issym") && have_a_fun) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
488 symmetric = map.contents ("issym")(0).double_value () != 0.; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
489 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
490 // isreal is ignored if A is not a function |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
491 if (map.contains ("isreal") && have_a_fun) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
492 a_is_complex = ! (map.contents ("isreal")(0).double_value () != 0.); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
493 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
494 if (map.contains ("tol")) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
495 tol = map.contents ("tol")(0).double_value (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
496 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
497 if (map.contains ("maxit")) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
498 maxit = map.contents ("maxit")(0).nint_value (); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
499 |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
500 if (map.contains ("p")) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
501 p = map.contents ("p")(0).nint_value (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
502 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
503 if (map.contains ("v0")) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
504 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
505 if (a_is_complex || b_is_complex) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
506 cresid = ComplexColumnVector |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
507 (map.contents ("v0")(0).complex_vector_value()); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
508 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
509 resid = ColumnVector (map.contents ("v0")(0).vector_value()); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
510 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
511 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
512 if (map.contains ("disp")) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
513 disp = map.contents ("disp")(0).nint_value (); |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
514 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
515 if (map.contains ("cholB")) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
516 cholB = map.contents ("cholB")(0).double_value () != 0.; |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
517 |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
518 if (map.contains ("permB")) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
519 permB = ColumnVector (map.contents ("permB")(0).vector_value ()) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
520 - 1.0; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
521 } |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
522 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
523 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
524 error ("eigs: options argument must be a structure"); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
525 return retval; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
526 } |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
527 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
528 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
529 if (nargin > (4+arg_offset)) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
530 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
531 error ("eigs: incorrect number of arguments"); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
532 return retval; |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
533 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
534 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
535 if (have_b) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
536 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
537 if (a_is_complex || b_is_complex) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
538 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
539 if (a_is_sparse) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
540 bscm = args(b_arg).sparse_complex_matrix_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
541 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
542 bcm = args(b_arg).complex_matrix_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
543 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
544 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
545 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
546 if (a_is_sparse) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
547 bsmm = args(b_arg).sparse_matrix_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
548 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
549 bmm = args(b_arg).matrix_value (); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
550 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
551 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
552 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
553 // Mode 1 for SM mode seems unstable for some reason. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
554 // Use Mode 3 instead, with sigma = 0. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
555 if (!error_state && !have_sigma && typ == "SM") |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
556 have_sigma = true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
557 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
558 if (!error_state) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
559 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
560 octave_idx_type nconv; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
561 if (a_is_complex || b_is_complex) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
562 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
563 ComplexMatrix eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
564 ComplexColumnVector eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
565 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
566 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
567 if (have_a_fun) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
568 nconv = EigsComplexNonSymmetricFunc |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
569 (eigs_complex_func, n, typ, sigma, k, p, info, eig_vec, eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
570 cresid, octave_stdout, tol, (nargout > 1), cholB, disp, maxit); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
571 else if (have_sigma) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
572 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
573 if (a_is_sparse) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
574 nconv = EigsComplexNonSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
575 (ascm, sigma, k, p, info, eig_vec, eig_val, bscm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
576 cresid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
577 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
578 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
579 nconv = EigsComplexNonSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
580 (acm, sigma, k, p, info, eig_vec, eig_val, bcm, permB, cresid, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
581 octave_stdout, tol, (nargout > 1), cholB, disp, maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
582 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
583 else |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
584 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
585 if (a_is_sparse) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
586 nconv = EigsComplexNonSymmetricMatrix |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
587 (ascm, typ, k, p, info, eig_vec, eig_val, bscm, permB, cresid, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
588 octave_stdout, tol, (nargout > 1), cholB, disp, maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
589 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
590 nconv = EigsComplexNonSymmetricMatrix |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
591 (acm, typ, k, p, info, eig_vec, eig_val, bcm, permB, cresid, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
592 octave_stdout, tol, (nargout > 1), cholB, disp, maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
593 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
594 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
595 if (nargout < 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
596 retval (0) = eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
597 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
598 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
599 retval(2) = double (info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
600 retval(1) = ComplexDiagMatrix (eig_val); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
601 retval(0) = eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
602 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
603 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
604 else if (sigmai != 0.) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
605 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
606 // Promote real problem to a complex one. |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
607 ComplexMatrix eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
608 ComplexColumnVector eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
609 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
610 if (have_a_fun) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
611 nconv = EigsComplexNonSymmetricFunc |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
612 (eigs_complex_func, n, typ, sigma, k, p, info, eig_vec, eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
613 cresid, octave_stdout, tol, (nargout > 1), cholB, disp, maxit); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
614 else |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
615 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
616 if (a_is_sparse) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
617 nconv = EigsComplexNonSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
618 (SparseComplexMatrix (asmm), sigma, k, p, info, eig_vec, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
619 eig_val, SparseComplexMatrix (bsmm), permB, cresid, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
620 octave_stdout, tol, (nargout > 1), cholB, disp, maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
621 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
622 nconv = EigsComplexNonSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
623 (ComplexMatrix (amm), sigma, k, p, info, eig_vec, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
624 eig_val, ComplexMatrix (bmm), permB, cresid, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
625 octave_stdout, tol, (nargout > 1), cholB, disp, maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
626 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
627 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
628 if (nargout < 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
629 retval (0) = eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
630 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
631 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
632 retval(2) = double (info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
633 retval(1) = ComplexDiagMatrix (eig_val); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
634 retval(0) = eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
635 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
636 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
637 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
638 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
639 if (symmetric) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
640 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
641 Matrix eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
642 ColumnVector eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
643 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
644 if (have_a_fun) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
645 nconv = EigsRealSymmetricFunc |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
646 (eigs_func, n, typ, sigmar, k, p, info, eig_vec, eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
647 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
648 maxit); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
649 else if (have_sigma) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
650 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
651 if (a_is_sparse) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
652 nconv = EigsRealSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
653 (asmm, sigmar, k, p, info, eig_vec, eig_val, bsmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
654 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
655 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
656 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
657 nconv = EigsRealSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
658 (amm, sigmar, k, p, info, eig_vec, eig_val, bmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
659 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
660 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
661 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
662 else |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
663 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
664 if (a_is_sparse) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
665 nconv = EigsRealSymmetricMatrix |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
666 (asmm, typ, k, p, info, eig_vec, eig_val, bsmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
667 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
668 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
669 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
670 nconv = EigsRealSymmetricMatrix |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
671 (amm, typ, k, p, info, eig_vec, eig_val, bmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
672 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
673 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
674 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
675 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
676 if (nargout < 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
677 retval (0) = eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
678 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
679 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
680 retval(2) = double (info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
681 retval(1) = DiagMatrix (eig_val); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
682 retval(0) = eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
683 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
684 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
685 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
686 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
687 ComplexMatrix eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
688 ComplexColumnVector eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
689 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
690 if (have_a_fun) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
691 nconv = EigsRealNonSymmetricFunc |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
692 (eigs_func, n, typ, sigmar, k, p, info, eig_vec, eig_val, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
693 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
694 maxit); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
695 else if (have_sigma) |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
696 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
697 if (a_is_sparse) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
698 nconv = EigsRealNonSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
699 (asmm, sigmar, k, p, info, eig_vec, eig_val, bsmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
700 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
701 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
702 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
703 nconv = EigsRealNonSymmetricMatrixShift |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
704 (amm, sigmar, k, p, info, eig_vec, eig_val, bmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
705 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
706 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
707 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
708 else |
8683
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
709 { |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
710 if (a_is_sparse) |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
711 nconv = EigsRealNonSymmetricMatrix |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
712 (asmm, typ, k, p, info, eig_vec, eig_val, bsmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
713 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
714 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
715 else |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
716 nconv = EigsRealNonSymmetricMatrix |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
717 (amm, typ, k, p, info, eig_vec, eig_val, bmm, permB, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
718 resid, octave_stdout, tol, (nargout > 1), cholB, disp, |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
719 maxit); |
e4f89f4a7cf8
eigs.cc (Feigs): avoid warnings; style fixes; return after errors
John W. Eaton <jwe@octave.org>
parents:
8585
diff
changeset
|
720 } |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
721 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
722 if (nargout < 2) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
723 retval (0) = eig_val; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
724 else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
725 { |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
726 retval(2) = double (info); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
727 retval(1) = ComplexDiagMatrix (eig_val); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
728 retval(0) = eig_vec; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
729 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
730 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
731 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
732 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
733 if (nconv <= 0) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
734 warning ("eigs: None of the %d requested eigenvalues converged", k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
735 else if (nconv < k) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
736 warning ("eigs: Only %d of the %d requested eigenvalues converged", |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
737 nconv, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
738 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
739 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
740 if (! fcn_name.empty ()) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
741 clear_function (fcn_name); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
742 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
743 unwind_protect::run_frame ("Feigs"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
744 #else |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
745 error ("eigs: not available in this version of Octave"); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
746 #endif |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
747 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
748 return retval; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
749 } |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
750 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
751 /* #### SPARSE MATRIX VERSIONS #### */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
752 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
753 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
754 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
755 %% Real positive definite tests, n must be even |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
756 %!shared n, k, A, d0, d2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
757 %! n = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
758 %! k = 4; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
759 %! A = sparse([3:n,1:n,1:(n-2)],[1:(n-2),1:n,3:n],[ones(1,n-2),4*ones(1,n),ones(1,n-2)]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
760 %! d0 = eig (A); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
761 %! d2 = sort(d0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
762 %! [dum, idx] = sort( abs(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
763 %! d0 = d0(idx); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
764 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
765 %! d1 = eigs (A, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
766 %! assert (d1, d0(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
767 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
768 %! d1 = eigs (A,k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
769 %! assert (d1, d0(end:-1:(end-k)),1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
770 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
771 %! d1 = eigs (A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
772 %! assert (d1, d0(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
773 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
774 %! d1 = eigs (A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
775 %! assert (d1, d0(k:-1:1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
776 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
777 %! d1 = eigs (A, k, 'la'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
778 %! assert (d1, d2(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
779 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
780 %! d1 = eigs (A, k, 'sa'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
781 %! assert (d1, d2(1:k), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
782 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
783 %! d1 = eigs (A, k, 'be'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
784 %! assert (d1, d2([1:floor(k/2), (end - ceil(k/2) + 1):end]), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
785 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
786 %! d1 = eigs (A, k+1, 'be'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
787 %! assert (d1, d2([1:floor((k+1)/2), (end - ceil((k+1)/2) + 1):end]), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
788 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
789 %! d1 = eigs (A, k, 4.1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
790 %! [dum,idx0] = sort (abs(d0 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
791 %! [dum,idx1] = sort (abs(d1 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
792 %! assert (d1(idx1), d0(idx0(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
793 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
794 %! d1 = eigs(A, speye(n), k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
795 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
796 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
797 %! assert (eigs(A,k,4.1), eigs(A,speye(n),k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
798 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
799 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
800 %! d1 = eigs(A, speye(n), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
801 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
802 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
803 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
804 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
805 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
806 %! d1 = eigs(A, speye(n)(q,q), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
807 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
808 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
809 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
810 %! d1 = eigs(A, speye(n), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
811 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
812 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
813 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
814 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
815 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
816 %! d1 = eigs(A, speye(n)(q,q), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
817 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
818 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
819 %! assert (eigs(A,k,4.1), eigs(A,speye(n),k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
820 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
821 %! fn = @(x) A * x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
822 %! opts.issym = 1; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
823 %! d1 = eigs (fn, n, k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
824 %! assert (d1, d0(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
825 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
826 %! fn = @(x) A \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
827 %! opts.issym = 1; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
828 %! d1 = eigs (fn, n, k, 'sm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
829 %! assert (d1, d0(k:-1:1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
830 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
831 %! fn = @(x) (A - 4.1 * eye(n)) \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
832 %! opts.issym = 1; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
833 %! d1 = eigs (fn, n, k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
834 %! assert (d1, eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
835 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
836 %! [v1,d1] = eigs(A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
837 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
838 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
839 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
840 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
841 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
842 %! [v1,d1] = eigs(A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
843 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
844 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
845 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
846 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
847 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
848 %! [v1,d1] = eigs(A, k, 'la'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
849 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
850 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
851 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
852 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
853 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
854 %! [v1,d1] = eigs(A, k, 'sa'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
855 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
856 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
857 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
858 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
859 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
860 %! [v1,d1] = eigs(A, k, 'be'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
861 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
862 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
863 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
864 %! endfor |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
865 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
866 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
867 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
868 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
869 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
870 %% Real unsymmetric tests |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
871 %!shared n, k, A, d0 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
872 %! n = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
873 %! k = 4; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
874 %! A = sparse([3:n,1:n,1:(n-2)],[1:(n-2),1:n,3:n],[ones(1,n-2),1:n,-ones(1,n-2)]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
875 %! d0 = eig (A); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
876 %! [dum, idx] = sort(abs(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
877 %! d0 = d0(idx); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
878 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
879 %! d1 = eigs (A, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
880 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
881 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
882 %! d1 = eigs (A,k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
883 %! assert (abs(d1), abs(d0(end:-1:(end-k))),1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
884 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
885 %! d1 = eigs (A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
886 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
887 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
888 %! d1 = eigs (A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
889 %! assert (abs(d1), abs(d0(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
890 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
891 %! d1 = eigs (A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
892 %! [dum, idx] = sort (real(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
893 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
894 %! assert (real(d1), real(d2(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
895 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
896 %! d1 = eigs (A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
897 %! [dum, idx] = sort (real(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
898 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
899 %! assert (real(d1), real(d2(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
900 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
901 %! d1 = eigs (A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
902 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
903 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
904 %! assert (sort(imag(d1)), sort(imag(d2(end:-1:(end-k+1)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
905 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
906 %! d1 = eigs (A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
907 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
908 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
909 %! assert (sort(imag(d1)), sort(imag(d2(1:k))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
910 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
911 %! d1 = eigs (A, k, 4.1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
912 %! [dum,idx0] = sort (abs(d0 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
913 %! [dum,idx1] = sort (abs(d1 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
914 %! assert (abs(d1(idx1)), abs(d0(idx0(1:k))), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
915 %! assert (sort(imag(d1(idx1))), sort(imag(d0(idx0(1:k)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
916 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
917 %! d1 = eigs(A, speye(n), k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
918 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
919 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
920 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
921 %! d1 = eigs(A, speye(n), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
922 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
923 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
924 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
925 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
926 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
927 %! d1 = eigs(A, speye(n)(q,q), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
928 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
929 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
930 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
931 %! d1 = eigs(A, speye(n), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
932 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
933 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
934 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
935 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
936 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
937 %! d1 = eigs(A, speye(n)(q,q), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
938 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
939 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
940 %! assert (abs(eigs(A,k,4.1)), abs(eigs(A,speye(n),k,4.1)), 1e-12); |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
941 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
942 %! assert (sort(imag(eigs(A,k,4.1))), sort(imag(eigs(A,speye(n),k,4.1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
943 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
944 %! fn = @(x) A * x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
945 %! opts.issym = 0; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
946 %! d1 = eigs (fn, n, k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
947 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
948 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
949 %! fn = @(x) A \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
950 %! opts.issym = 0; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
951 %! d1 = eigs (fn, n, k, 'sm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
952 %! assert (abs(d1), d0(1:k), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
953 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
954 %! fn = @(x) (A - 4.1 * eye(n)) \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
955 %! opts.issym = 0; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
956 %! d1 = eigs (fn, n, k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
957 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
958 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
959 %! [v1,d1] = eigs(A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
960 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
961 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
962 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
963 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
964 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
965 %! [v1,d1] = eigs(A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
966 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
967 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
968 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
969 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
970 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
971 %! [v1,d1] = eigs(A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
972 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
973 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
974 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
975 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
976 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
977 %! [v1,d1] = eigs(A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
978 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
979 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
980 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
981 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
982 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
983 %! [v1,d1] = eigs(A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
984 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
985 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
986 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
987 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
988 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
989 %! [v1,d1] = eigs(A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
990 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
991 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
992 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
993 %! endfor |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
994 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
995 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
996 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
997 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
998 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
999 %% Complex hermitian tests |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1000 %!shared n, k, A, d0 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1001 %! n = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1002 %! k = 4; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1003 %! A = sparse([3:n,1:n,1:(n-2)],[1:(n-2),1:n,3:n],[1i*ones(1,n-2),4*ones(1,n),-1i*ones(1,n-2)]); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1004 %! d0 = eig (A); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1005 %! [dum, idx] = sort(abs(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1006 %! d0 = d0(idx); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1007 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1008 %! d1 = eigs (A, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1009 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1010 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1011 %! d1 = eigs (A,k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1012 %! assert (abs(d1), abs(d0(end:-1:(end-k))),1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1013 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1014 %! d1 = eigs (A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1015 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1016 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1017 %! d1 = eigs (A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1018 %! assert (abs(d1), abs(d0(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1019 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1020 %! d1 = eigs (A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1021 %! [dum, idx] = sort (real(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1022 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1023 %! assert (real(d1), real(d2(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1024 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1025 %! d1 = eigs (A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1026 %! [dum, idx] = sort (real(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1027 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1028 %! assert (real(d1), real(d2(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1029 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1030 %! d1 = eigs (A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1031 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1032 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1033 %! assert (sort(imag(d1)), sort(imag(d2(end:-1:(end-k+1)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1034 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1035 %! d1 = eigs (A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1036 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1037 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1038 %! assert (sort(imag(d1)), sort(imag(d2(1:k))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1039 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1040 %! d1 = eigs (A, k, 4.1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1041 %! [dum,idx0] = sort (abs(d0 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1042 %! [dum,idx1] = sort (abs(d1 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1043 %! assert (abs(d1(idx1)), abs(d0(idx0(1:k))), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1044 %! assert (sort(imag(d1(idx1))), sort(imag(d0(idx0(1:k)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1045 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1046 %! d1 = eigs(A, speye(n), k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1047 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1048 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1049 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1050 %! d1 = eigs(A, speye(n), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1051 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1052 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1053 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1054 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1055 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1056 %! d1 = eigs(A, speye(n)(q,q), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1057 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1058 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1059 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1060 %! d1 = eigs(A, speye(n), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1061 %! assert (abs(abs(d1)), abs(eigs(A,k,4.1)), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1062 %! assert (sort(imag(abs(d1))), sort(imag(eigs(A,k,4.1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1063 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1064 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1065 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1066 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1067 %! d1 = eigs(A, speye(n)(q,q), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1068 %! assert (abs(abs(d1)), abs(eigs(A,k,4.1)), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1069 %! assert (sort(imag(abs(d1))), sort(imag(eigs(A,k,4.1))), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1070 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1071 %! assert (abs(eigs(A,k,4.1)), abs(eigs(A,speye(n),k,4.1)), 1e-12); |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1072 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1073 %! assert (sort(imag(eigs(A,k,4.1))), sort(imag(eigs(A,speye(n),k,4.1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1074 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1075 %! fn = @(x) A * x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1076 %! opts.issym = 0; opts.isreal = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1077 %! d1 = eigs (fn, n, k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1078 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1079 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1080 %! fn = @(x) A \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1081 %! opts.issym = 0; opts.isreal = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1082 %! d1 = eigs (fn, n, k, 'sm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1083 %! assert (abs(d1), d0(1:k), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1084 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1085 %! fn = @(x) (A - 4.1 * eye(n)) \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1086 %! opts.issym = 0; opts.isreal = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1087 %! d1 = eigs (fn, n, k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1088 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1089 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1090 %! [v1,d1] = eigs(A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1091 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1092 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1093 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1094 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1095 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1096 %! [v1,d1] = eigs(A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1097 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1098 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1099 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1100 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1101 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1102 %! [v1,d1] = eigs(A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1103 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1104 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1105 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1106 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1107 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1108 %! [v1,d1] = eigs(A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1109 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1110 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1111 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1112 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1113 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1114 %! [v1,d1] = eigs(A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1115 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1116 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1117 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1118 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1119 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1120 %! [v1,d1] = eigs(A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1121 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1122 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1123 %! assert(max(abs((A - d1(i)*speye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1124 %! endfor |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1125 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1126 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1127 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1128 /* #### FULL MATRIX VERSIONS #### */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1129 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1130 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1131 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1132 %% Real positive definite tests, n must be even |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1133 %!shared n, k, A, d0, d2 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1134 %! n = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1135 %! k = 4; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1136 %! A = full(sparse([3:n,1:n,1:(n-2)],[1:(n-2),1:n,3:n],[ones(1,n-2),4*ones(1,n),ones(1,n-2)])); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1137 %! d0 = eig (A); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1138 %! d2 = sort(d0); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1139 %! [dum, idx] = sort( abs(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1140 %! d0 = d0(idx); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1141 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1142 %! d1 = eigs (A, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1143 %! assert (d1, d0(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1144 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1145 %! d1 = eigs (A,k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1146 %! assert (d1, d0(end:-1:(end-k)),1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1147 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1148 %! d1 = eigs (A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1149 %! assert (d1, d0(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1150 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1151 %! d1 = eigs (A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1152 %! assert (d1, d0(k:-1:1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1153 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1154 %! d1 = eigs (A, k, 'la'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1155 %! assert (d1, d2(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1156 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1157 %! d1 = eigs (A, k, 'sa'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1158 %! assert (d1, d2(1:k), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1159 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1160 %! d1 = eigs (A, k, 'be'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1161 %! assert (d1, d2([1:floor(k/2), (end - ceil(k/2) + 1):end]), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1162 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1163 %! d1 = eigs (A, k+1, 'be'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1164 %! assert (d1, d2([1:floor((k+1)/2), (end - ceil((k+1)/2) + 1):end]), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1165 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1166 %! d1 = eigs (A, k, 4.1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1167 %! [dum,idx0] = sort (abs(d0 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1168 %! [dum,idx1] = sort (abs(d1 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1169 %! assert (d1(idx1), d0(idx0(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1170 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1171 %! d1 = eigs(A, eye(n), k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1172 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1173 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1174 %! assert (eigs(A,k,4.1), eigs(A,eye(n),k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1175 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1176 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1177 %! d1 = eigs(A, eye(n), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1178 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1179 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1180 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1181 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1182 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1183 %! d1 = eigs(A, eye(n)(q,q), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1184 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1185 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1186 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1187 %! d1 = eigs(A, eye(n), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1188 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1189 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1190 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1191 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1192 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1193 %! d1 = eigs(A, eye(n)(q,q), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1194 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1195 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1196 %! assert (eigs(A,k,4.1), eigs(A,eye(n),k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1197 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1198 %! fn = @(x) A * x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1199 %! opts.issym = 1; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1200 %! d1 = eigs (fn, n, k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1201 %! assert (d1, d0(end:-1:(end-k+1)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1202 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1203 %! fn = @(x) A \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1204 %! opts.issym = 1; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1205 %! d1 = eigs (fn, n, k, 'sm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1206 %! assert (d1, d0(k:-1:1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1207 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1208 %! fn = @(x) (A - 4.1 * eye(n)) \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1209 %! opts.issym = 1; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1210 %! d1 = eigs (fn, n, k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1211 %! assert (d1, eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1212 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1213 %! [v1,d1] = eigs(A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1214 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1215 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1216 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1217 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1218 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1219 %! [v1,d1] = eigs(A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1220 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1221 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1222 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1223 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1224 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1225 %! [v1,d1] = eigs(A, k, 'la'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1226 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1227 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1228 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1229 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1230 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1231 %! [v1,d1] = eigs(A, k, 'sa'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1232 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1233 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1234 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1235 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1236 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1237 %! [v1,d1] = eigs(A, k, 'be'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1238 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1239 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1240 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1241 %! endfor |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1242 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1243 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1244 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1245 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1246 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1247 %% Real unsymmetric tests |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1248 %!shared n, k, A, d0 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1249 %! n = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1250 %! k = 4; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1251 %! A = full(sparse([3:n,1:n,1:(n-2)],[1:(n-2),1:n,3:n],[ones(1,n-2),1:n,-ones(1,n-2)])); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1252 %! d0 = eig (A); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1253 %! [dum, idx] = sort(abs(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1254 %! d0 = d0(idx); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1255 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1256 %! d1 = eigs (A, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1257 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1258 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1259 %! d1 = eigs (A,k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1260 %! assert (abs(d1), abs(d0(end:-1:(end-k))),1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1261 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1262 %! d1 = eigs (A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1263 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1264 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1265 %! d1 = eigs (A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1266 %! assert (abs(d1), abs(d0(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1267 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1268 %! d1 = eigs (A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1269 %! [dum, idx] = sort (real(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1270 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1271 %! assert (real(d1), real(d2(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1272 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1273 %! d1 = eigs (A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1274 %! [dum, idx] = sort (real(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1275 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1276 %! assert (real(d1), real(d2(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1277 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1278 %! d1 = eigs (A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1279 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1280 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1281 %! assert (sort(imag(d1)), sort(imag(d2(end:-1:(end-k+1)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1282 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1283 %! d1 = eigs (A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1284 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1285 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1286 %! assert (sort(imag(d1)), sort(imag(d2(1:k))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1287 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1288 %! d1 = eigs (A, k, 4.1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1289 %! [dum,idx0] = sort (abs(d0 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1290 %! [dum,idx1] = sort (abs(d1 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1291 %! assert (abs(d1(idx1)), abs(d0(idx0(1:k))), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1292 %! assert (sort(imag(d1(idx1))), sort(imag(d0(idx0(1:k)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1293 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1294 %! d1 = eigs(A, eye(n), k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1295 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1296 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1297 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1298 %! d1 = eigs(A, eye(n), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1299 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1300 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1301 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1302 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1303 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1304 %! d1 = eigs(A, eye(n)(q,q), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1305 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1306 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1307 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1308 %! d1 = eigs(A, eye(n), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1309 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1310 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1311 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1312 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1313 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1314 %! d1 = eigs(A, eye(n)(q,q), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1315 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1316 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1317 %! assert (abs(eigs(A,k,4.1)), abs(eigs(A,eye(n),k,4.1)), 1e-12); |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1318 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1319 %! assert (sort(imag(eigs(A,k,4.1))), sort(imag(eigs(A,eye(n),k,4.1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1320 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1321 %! fn = @(x) A * x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1322 %! opts.issym = 0; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1323 %! d1 = eigs (fn, n, k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1324 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1325 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1326 %! fn = @(x) A \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1327 %! opts.issym = 0; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1328 %! d1 = eigs (fn, n, k, 'sm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1329 %! assert (abs(d1), d0(1:k), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1330 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1331 %! fn = @(x) (A - 4.1 * eye(n)) \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1332 %! opts.issym = 0; opts.isreal = 1; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1333 %! d1 = eigs (fn, n, k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1334 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1335 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1336 %! [v1,d1] = eigs(A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1337 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1338 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1339 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1340 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1341 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1342 %! [v1,d1] = eigs(A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1343 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1344 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1345 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1346 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1347 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1348 %! [v1,d1] = eigs(A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1349 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1350 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1351 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1352 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1353 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1354 %! [v1,d1] = eigs(A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1355 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1356 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1357 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1358 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1359 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1360 %! [v1,d1] = eigs(A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1361 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1362 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1363 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1364 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1365 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1366 %! [v1,d1] = eigs(A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1367 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1368 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1369 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1370 %! endfor |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1371 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1372 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1373 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1374 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1375 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1376 %% Complex hermitian tests |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1377 %!shared n, k, A, d0 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1378 %! n = 20; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1379 %! k = 4; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1380 %! A = full(sparse([3:n,1:n,1:(n-2)],[1:(n-2),1:n,3:n],[1i*ones(1,n-2),4*ones(1,n),-1i*ones(1,n-2)])); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1381 %! d0 = eig (A); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1382 %! [dum, idx] = sort(abs(d0)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1383 %! d0 = d0(idx); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1384 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1385 %! d1 = eigs (A, k); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1386 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1387 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1388 %! d1 = eigs (A,k+1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1389 %! assert (abs(d1), abs(d0(end:-1:(end-k))),1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1390 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1391 %! d1 = eigs (A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1392 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1393 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1394 %! d1 = eigs (A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1395 %! assert (abs(d1), abs(d0(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1396 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1397 %! d1 = eigs (A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1398 %! [dum, idx] = sort (real(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1399 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1400 %! assert (real(d1), real(d2(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1401 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1402 %! d1 = eigs (A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1403 %! [dum, idx] = sort (real(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1404 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1405 %! assert (real(d1), real(d2(1:k)), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1406 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1407 %! d1 = eigs (A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1408 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1409 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1410 %! assert (sort(imag(d1)), sort(imag(d2(end:-1:(end-k+1)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1411 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1412 %! d1 = eigs (A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1413 %! [dum, idx] = sort (imag(abs(d0))); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1414 %! d2 = d0(idx); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1415 %! assert (sort(imag(d1)), sort(imag(d2(1:k))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1416 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1417 %! d1 = eigs (A, k, 4.1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1418 %! [dum,idx0] = sort (abs(d0 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1419 %! [dum,idx1] = sort (abs(d1 - 4.1)); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1420 %! assert (abs(d1(idx1)), abs(d0(idx0(1:k))), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1421 %! assert (sort(imag(d1(idx1))), sort(imag(d0(idx0(1:k)))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1422 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1423 %! d1 = eigs(A, eye(n), k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1424 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1425 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1426 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1427 %! d1 = eigs(A, eye(n), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1428 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1429 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1430 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1431 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1432 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1433 %! d1 = eigs(A, eye(n)(q,q), k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1434 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1435 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1436 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1437 %! d1 = eigs(A, eye(n), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1438 %! assert (abs(abs(d1)), abs(eigs(A,k,4.1)), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1439 %! assert (sort(imag(abs(d1))), sort(imag(eigs(A,k,4.1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1440 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1441 %! opts.cholB=true; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1442 %! q = [2:n,1]; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1443 %! opts.permB=q; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1444 %! d1 = eigs(A, eye(n)(q,q), k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1445 %! assert (abs(abs(d1)), abs(eigs(A,k,4.1)), 1e-12); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1446 %! assert (sort(imag(abs(d1))), sort(imag(eigs(A,k,4.1))), 1e-12); |
8585
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1447 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1448 %! assert (abs(eigs(A,k,4.1)), abs(eigs(A,eye(n),k,4.1)), 1e-12); |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1449 %!testif HAVE_ARPACK |
e6497be3f3d6
Skip tests if ARPACK is missing.
Ben Abbott <bpabbott@mac.com>
parents:
8420
diff
changeset
|
1450 %! assert (sort(imag(eigs(A,k,4.1))), sort(imag(eigs(A,eye(n),k,4.1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1451 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1452 %! fn = @(x) A * x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1453 %! opts.issym = 0; opts.isreal = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1454 %! d1 = eigs (fn, n, k, 'lm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1455 %! assert (abs(d1), abs(d0(end:-1:(end-k+1))), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1456 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1457 %! fn = @(x) A \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1458 %! opts.issym = 0; opts.isreal = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1459 %! d1 = eigs (fn, n, k, 'sm', opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1460 %! assert (abs(d1), d0(1:k), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1461 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1462 %! fn = @(x) (A - 4.1 * eye(n)) \ x; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1463 %! opts.issym = 0; opts.isreal = 0; |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1464 %! d1 = eigs (fn, n, k, 4.1, opts); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1465 %! assert (abs(d1), eigs(A,k,4.1), 1e-12); |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1466 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1467 %! [v1,d1] = eigs(A, k, 'lm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1468 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1469 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1470 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1471 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1472 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1473 %! [v1,d1] = eigs(A, k, 'sm'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1474 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1475 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1476 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1477 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1478 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1479 %! [v1,d1] = eigs(A, k, 'lr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1480 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1481 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1482 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1483 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1484 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1485 %! [v1,d1] = eigs(A, k, 'sr'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1486 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1487 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1488 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1489 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1490 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1491 %! [v1,d1] = eigs(A, k, 'li'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1492 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1493 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1494 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1495 %! endfor |
8420
9038f311c1a8
eigs.cc: skip tests if ARPACK is missing
John W. Eaton <jwe@octave.org>
parents:
8417
diff
changeset
|
1496 %!testif HAVE_ARPACK |
8417
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1497 %! [v1,d1] = eigs(A, k, 'si'); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1498 %! d1 = diag(d1); |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1499 %! for i=1:k |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1500 %! assert(max(abs((A - d1(i)*eye(n))*v1(:,i))),0.,1e-12) |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1501 %! endfor |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1502 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1503 */ |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1504 |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1505 /* |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1506 ;;; Local Variables: *** |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1507 ;;; mode: C++ *** |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1508 ;;; End: *** |
654bcfb937bf
Add the eigs and svds functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
1509 */ |