Mercurial > hg > octave-lyh
annotate scripts/sparse/eigs.m @ 17380:63b53ea33a8b
imread: fix returning multiple variables.
* imread.m: fix mistake when filling varargout from cset. Do not miss
the first cell.
* __magick_read__.cc (read_maps): change class of alpha map which is
only a column vector, not a Nx3 Matrix.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Wed, 04 Sep 2013 21:22:43 +0100 |
parents | 1c89599167a6 |
children |
rev | line source |
---|---|
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 ## Copyright (C) 2005-2012 David Bateman |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 ## your option) any later version. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 ## General Public License for more details. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 ## @deftypefn {Function File} {@var{d} =} eigs (@var{A}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{A}, @var{k}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{A}, @var{k}, @var{sigma}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{A}, @var{k}, @var{sigma}, @var{opts}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{A}, @var{B}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{A}, @var{B}, @var{k}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{A}, @var{B}, @var{k}, @var{sigma}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{A}, @var{B}, @var{k}, @var{sigma}, @var{opts}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}, @var{B}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}, @var{k}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}, @var{B}, @var{k}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}, @var{k}, @var{sigma}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}, @var{B}, @var{k}, @var{sigma}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}, @var{k}, @var{sigma}, @var{opts}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 ## @deftypefnx {Function File} {@var{d} =} eigs (@var{af}, @var{n}, @var{B}, @var{k}, @var{sigma}, @var{opts}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 ## @deftypefnx {Function File} {[@var{V}, @var{d}] =} eigs (@var{A}, @dots{}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 ## @deftypefnx {Function File} {[@var{V}, @var{d}] =} eigs (@var{af}, @var{n}, @dots{}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 ## @deftypefnx {Function File} {[@var{V}, @var{d}, @var{flag}] =} eigs (@var{A}, @dots{}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 ## @deftypefnx {Function File} {[@var{V}, @var{d}, @var{flag}] =} eigs (@var{af}, @var{n}, @dots{}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 ## Calculate a limited number of eigenvalues and eigenvectors of @var{A}, |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 ## based on a selection criteria. The number of eigenvalues and eigenvectors to |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 ## calculate is given by @var{k} and defaults to 6. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 ## By default, @code{eigs} solve the equation |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 ## @tex |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 ## $A \nu = \lambda \nu$, |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 ## @end tex |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 ## @ifinfo |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 ## @code{A * v = lambda * v}, |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 ## @end ifinfo |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 ## where |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 ## @tex |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
53 ## $\lambda$ is a scalar representing one of the eigenvalues, and $\nu$ |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 ## @end tex |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 ## @ifinfo |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 ## @code{lambda} is a scalar representing one of the eigenvalues, and @code{v} |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 ## @end ifinfo |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 ## is the corresponding eigenvector. If given the positive definite matrix |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 ## @var{B} then @code{eigs} solves the general eigenvalue equation |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 ## @tex |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 ## $A \nu = \lambda B \nu$. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 ## @end tex |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 ## @ifinfo |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 ## @code{A * v = lambda * B * v}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 ## @end ifinfo |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 ## The argument @var{sigma} determines which eigenvalues are returned. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 ## @var{sigma} can be either a scalar or a string. When @var{sigma} is a |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 ## scalar, the @var{k} eigenvalues closest to @var{sigma} are returned. If |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 ## @var{sigma} is a string, it must have one of the following values. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 ## @table @asis |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
73 ## @item @qcode{"lm"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 ## Largest Magnitude (default). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
76 ## @item @qcode{"sm"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 ## Smallest Magnitude. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
79 ## @item @qcode{"la"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 ## Largest Algebraic (valid only for real symmetric problems). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
82 ## @item @qcode{"sa"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 ## Smallest Algebraic (valid only for real symmetric problems). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
84 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
85 ## @item @qcode{"be"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
86 ## Both Ends, with one more from the high-end if @var{k} is odd (valid only for |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 ## real symmetric problems). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
89 ## @item @qcode{"lr"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 ## Largest Real part (valid only for complex or unsymmetric problems). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
92 ## @item @qcode{"sr"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 ## Smallest Real part (valid only for complex or unsymmetric problems). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
94 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
95 ## @item @qcode{"li"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
96 ## Largest Imaginary part (valid only for complex or unsymmetric problems). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 ## |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17228
diff
changeset
|
98 ## @item @qcode{"si"} |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 ## Smallest Imaginary part (valid only for complex or unsymmetric problems). |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
100 ## @end table |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 ## If @var{opts} is given, it is a structure defining possible options that |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 ## @code{eigs} should use. The fields of the @var{opts} structure are: |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 ## @table @code |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 ## @item issym |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 ## If @var{af} is given, then flags whether the function @var{af} defines a |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 ## symmetric problem. It is ignored if @var{A} is given. The default is false. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 ## @item isreal |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 ## If @var{af} is given, then flags whether the function @var{af} defines a |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 ## real problem. It is ignored if @var{A} is given. The default is true. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 ## @item tol |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 ## Defines the required convergence tolerance, calculated as |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 ## @code{tol * norm (A)}. The default is @code{eps}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 ## @item maxit |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
119 ## The maximum number of iterations. The default is 300. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 ## @item p |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
122 ## The number of Lanzcos basis vectors to use. More vectors will result in |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 ## faster convergence, but a greater use of memory. The optimal value of |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 ## @code{p} is problem dependent and should be in the range @var{k} to @var{n}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 ## The default value is @code{2 * @var{k}}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 ## @item v0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 ## The starting vector for the algorithm. An initial vector close to the |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 ## final vector will speed up convergence. The default is for @sc{arpack} |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 ## to randomly generate a starting vector. If specified, @code{v0} must be |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 ## an @var{n}-by-1 vector where @code{@var{n} = rows (@var{A})} |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 ## @item disp |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 ## The level of diagnostic printout (0|1|2). If @code{disp} is 0 then |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 ## diagnostics are disabled. The default value is 0. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 ## @item cholB |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 ## Flag if @code{chol (@var{B})} is passed rather than @var{B}. The default is |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 ## false. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
141 ## @item permB |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 ## The permutation vector of the Cholesky@tie{}factorization of @var{B} if |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 ## @code{cholB} is true. That is @code{chol (@var{B}(permB, permB))}. The |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 ## default is @code{1:@var{n}}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
145 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 ## @end table |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
147 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
148 ## It is also possible to represent @var{A} by a function denoted @var{af}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
149 ## @var{af} must be followed by a scalar argument @var{n} defining the length |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
150 ## of the vector argument accepted by @var{af}. @var{af} can be |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 ## a function handle, an inline function, or a string. When @var{af} is a |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
152 ## string it holds the name of the function to use. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
153 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
154 ## @var{af} is a function of the form @code{y = af (x)} |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
155 ## where the required return value of @var{af} is determined by |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
156 ## the value of @var{sigma}. The four possible forms are |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
157 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
158 ## @table @code |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
159 ## @item A * x |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
160 ## if @var{sigma} is not given or is a string other than "sm". |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
161 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 ## @item A \ x |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
163 ## if @var{sigma} is 0 or "sm". |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
164 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
165 ## @item (A - sigma * I) \ x |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
166 ## for the standard eigenvalue problem, where @code{I} is the identity matrix of |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
167 ## the same size as @var{A}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
168 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 ## @item (A - sigma * B) \ x |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
170 ## for the general eigenvalue problem. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
171 ## @end table |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
172 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
173 ## The return arguments of @code{eigs} depend on the number of return arguments |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
174 ## requested. With a single return argument, a vector @var{d} of length @var{k} |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
175 ## is returned containing the @var{k} eigenvalues that have been found. With |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
176 ## two return arguments, @var{V} is a @var{n}-by-@var{k} matrix whose columns |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
177 ## are the @var{k} eigenvectors corresponding to the returned eigenvalues. The |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
178 ## eigenvalues themselves are returned in @var{d} in the form of a |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
179 ## @var{n}-by-@var{k} matrix, where the elements on the diagonal are the |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
180 ## eigenvalues. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
181 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
182 ## Given a third return argument @var{flag}, @code{eigs} returns the status |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
183 ## of the convergence. If @var{flag} is 0 then all eigenvalues have converged. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
184 ## Any other value indicates a failure to converge. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
185 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
186 ## This function is based on the @sc{arpack} package, written by R. Lehoucq, |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
187 ## K. Maschhoff, D. Sorensen, and C. Yang. For more information see |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
188 ## @url{http://www.caam.rice.edu/software/ARPACK/}. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
189 ## |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
190 ## @seealso{eig, svds} |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
191 ## @end deftypefn |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
192 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
193 function varargout = eigs (varargin) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
194 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
195 ## For compatibility with Matlab, handle small matrix cases here |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
196 ## that ARPACK does not. |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
198 if (nargin == 0) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
199 print_usage (); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
200 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
201 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
202 call_eig = false; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
203 offset = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
204 k = 6; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
205 sigma = "lm"; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
206 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
207 if (isnumeric (varargin{1}) && issquare (varargin{1})) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
208 a = varargin{1}; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
209 if (nargin > 1 && isnumeric (varargin{2}) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
210 && issquare (varargin{2}) && size_equal (a, varargin{2})) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
211 b = varargin{2}; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
212 offset = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
213 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
214 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
215 if (rows (a) < 9) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
216 call_eig = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
217 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
218 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
219 if (nargin > 1 + offset) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
220 tmp = varargin{2+offset}; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
221 if (isnumeric (tmp) && isscalar (tmp) && isreal (tmp) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
222 && round (tmp) == tmp) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
223 k = tmp; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
224 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
225 if (rows (a) - k < 3) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
226 call_eig = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
227 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
228 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
229 call_eig = false; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
230 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
231 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
232 if (nargin > 2 + offset) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
233 tmp = varargin{3+offset}; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
234 if (ischar (tmp) || (isnumeric (tmp) && isscalar (tmp))) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
235 sigma = tmp; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
236 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
237 call_eig = false; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
238 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
239 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
240 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
241 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
242 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
243 if (call_eig) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
244 varargout = cell (1, min (2, max (1, nargout))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
245 if (offset) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
246 real_valued = isreal (a) && isreal (b); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 symmetric = issymmetric (a) && issymmetric (b); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
248 [varargout{:}] = eig (a, b); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
249 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
250 real_valued = isreal (a); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
251 symmetric = issymmetric (a); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
252 [varargout{:}] = eig (a); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
253 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
254 varargout = select (varargout, k, sigma, real_valued, symmetric); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
255 if (nargout == 3) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
256 varargout{3} = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
257 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
258 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
259 varargout = cell (1, max (1, nargout)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
260 [varargout{:}] = __eigs__ (varargin{:}); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
261 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
262 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
263 endfunction |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
264 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
265 function out = select (args, k, sigma, real_valued, symmetric) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
266 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
267 if (numel (args) == 1) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
268 d = args{1}; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
269 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
270 d = diag (args{2}); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
271 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
272 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
273 if (ischar (sigma)) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
274 switch (sigma) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
275 case "lm" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
276 [~, idx] = sort (abs (d), "descend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
277 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
278 case "sm" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
279 [~, idx] = sort (abs (d), "ascend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
280 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
281 case "la" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
282 if (real_valued && symmetric) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
283 [~, idx] = sort (real (d), "descend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
284 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
285 error ("sigma = \"la\" requires real symmetric problem"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
286 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
287 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
288 case "sa" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
289 if (real_valued && symmetric) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
290 [~, idx] = sort (real (d), "ascend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
291 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
292 error ("sigma = \"sa\" requires real symmetric problem"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
293 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
294 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
295 case "be" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
296 if (real_valued && symmetric) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
297 [~, idx] = sort (real (d), "ascend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
298 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
299 error ("sigma = \"be\" requires real symmetric problem"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
300 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
301 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
302 case "lr" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
303 if (! (real_valued || symmetric)) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
304 [~, idx] = sort (real (d), "descend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
305 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
306 error ("sigma = \"lr\" requires complex or unsymmetric problem"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
307 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
308 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
309 case "sr" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
310 if (! (real_valued || symmetric)) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
311 [~, idx] = sort (real (d), "ascend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
312 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
313 error ("sigma = \"sr\" requires complex or unsymmetric problem"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
314 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
315 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
316 case "li" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
317 if (! (real_valued || symmetric)) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
318 [~, idx] = sort (imag (d), "descend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
320 error ("sigma = \"li\" requires complex or unsymmetric problem"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
321 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
322 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
323 case "si" |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
324 if (! (real_valued || symmetric)) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
325 [~, idx] = sort (imag (d), "ascend"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
326 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
327 error ("sigma = \"si\" requires complex or unsymmetric problem"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
328 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
329 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
330 otherwise |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
331 error ("unrecognized value for sigma: %s", sigma); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
332 endswitch |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
333 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
334 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
335 d = d(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
336 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
337 n = numel (d); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
338 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 k = min (k, n); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
340 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
341 if (strcmp (sigma, 'be')) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
342 tmp = k / 2; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
343 n1 = floor (tmp); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
344 n2 = n - ceil (tmp) + 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
345 selection = [1:floor(k/2), n2:n]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
347 selection = 1:k; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
348 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
349 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
350 d = d(selection); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
351 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 if (numel (args) == 1) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
353 out{1} = d; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
354 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
355 out{2} = diag (d); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
356 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
357 v = args{1}; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
358 v = v(:,idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
359 out{1} = v(selection,:); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
360 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
361 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
362 endfunction |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
363 |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17289
diff
changeset
|
364 |
17228
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
365 #### SPARSE MATRIX VERSIONS #### |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
366 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
367 ## Real positive definite tests, n must be even |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
368 %!shared n, k, A, d0, d2 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
369 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
370 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
371 %! 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)]); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
372 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
373 %! d2 = sort (d0); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
374 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
375 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
376 %! rand ("state", 42); # initialize generator to make eigs behavior reproducible |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
377 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
378 %! d1 = eigs (A, k); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
379 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
380 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
381 %! d1 = eigs (A, k+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 %! assert (d1, d0(end:-1:(end-k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
383 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
384 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
385 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
386 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
387 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
388 %! assert (d1, d0(k:-1:1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
389 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
390 %! d1 = eigs (A, k, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
391 %! assert (d1, d2(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
392 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
393 %! d1 = eigs (A, k, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
394 %! assert (d1, d2(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
395 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
396 %! d1 = eigs (A, k, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 %! assert (d1, d2([1:floor(k/2), (end - ceil(k/2) + 1):end]), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
398 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
399 %! d1 = eigs (A, k+1, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
400 %! assert (d1, d2([1:floor((k+1)/2), (end - ceil((k+1)/2) + 1):end]), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
401 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
402 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
404 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 %! assert (d1(idx1), d0(idx0(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 %!testif HAVE_ARPACK, HAVE_CHOLMOD |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 %! d1 = eigs (A, speye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
408 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
409 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
410 %! assert (eigs (A, k, 4.1), eigs (A, speye (n), k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
411 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
412 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
413 %! d1 = eigs (A, speye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
414 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
415 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
416 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
417 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
418 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
419 %! d1 = eigs (A, speye (n)(q,q), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
420 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
421 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
422 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
423 %! d1 = eigs (A, speye (n), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
424 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
426 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
427 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
428 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
429 %! d1 = eigs (A, speye (n)(q,q), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
431 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
432 %! assert (eigs (A, k, 4.1), eigs (A, speye (n), k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
433 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
434 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
435 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
436 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
437 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
438 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
439 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
440 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
441 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
442 %! assert (d1, d0(k:-1:1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
443 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
444 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
445 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
446 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 %! assert (d1, eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
448 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
449 %! AA = speye (10); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 %! fn = @(x) AA * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
451 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
452 %! assert (eigs (fn, 10, AA, 3, "lm", opts), [1; 1; 1], 10*eps); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
453 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
454 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
455 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
456 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
457 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
458 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
459 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
460 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
461 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
462 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
463 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
464 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
465 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
466 %! [v1,d1] = eigs (A, k, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
467 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
468 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
469 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
470 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
471 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
472 %! [v1,d1] = eigs (A, k, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
473 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
474 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
475 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
476 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
477 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
478 %! [v1,d1] = eigs (A, k, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
479 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
480 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
481 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
482 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
483 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
484 ## Real unsymmetric tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
485 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
486 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
487 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 %! 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)]); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
489 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
490 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
491 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
492 %! rand ("state", 42); % initialize generator to make eigs behavior reproducible |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
493 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
494 %! d1 = eigs (A, k); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
495 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
496 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
497 %! d1 = eigs (A, k+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
498 %! assert (abs (d1), abs (d0(end:-1:(end-k))),1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
499 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
500 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
501 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
502 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
504 %! assert (abs (d1), abs (d0(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
505 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
506 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
507 %! [~, idx] = sort (real (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
508 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
509 %! assert (real (d1), real (d2(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
510 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
511 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
512 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
513 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
514 %! assert (real (d1), real (d2(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
515 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
517 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
518 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
519 %! assert (sort (imag (d1)), sort (imag (d2(end:-1:(end-k+1)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
520 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
521 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
522 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
523 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
524 %! assert (sort (imag (d1)), sort (imag (d2(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
525 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
526 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
527 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
528 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
529 %! assert (abs (d1(idx1)), abs (d0(idx0(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
530 %! assert (sort (imag (d1(idx1))), sort (imag (d0(idx0(1:k)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
531 %!testif HAVE_ARPACK, HAVE_CHOLMOD |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
532 %! d1 = eigs (A, speye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
533 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
534 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
535 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
536 %! d1 = eigs (A, speye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
537 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
538 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
539 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
540 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
541 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
542 %! d1 = eigs (A, speye (n)(q,q), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
543 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
544 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
545 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
546 %! d1 = eigs (A, speye (n), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
547 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
548 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
549 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
550 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
551 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
552 %! d1 = eigs (A, speye (n)(q,q), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
553 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
554 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
555 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, speye (n), k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
556 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
557 %! assert (sort (imag (eigs (A, k, 4.1))), sort (imag (eigs (A, speye (n), k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
558 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
559 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
560 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
561 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
562 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
563 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
564 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
565 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
566 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
567 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
568 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
569 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
570 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
571 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
572 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
573 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
574 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
575 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
576 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
577 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
578 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
579 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
580 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
581 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
582 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
583 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
584 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
585 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
586 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
587 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
588 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
589 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
590 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
591 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
592 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
593 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
594 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
595 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
596 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
597 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
598 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
599 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
600 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
601 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
602 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
603 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
604 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
605 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
606 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
607 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
608 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
609 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
610 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
611 ## Complex hermitian tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
612 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
613 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
614 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
615 %! 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)]); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
616 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
617 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
618 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
619 %! rand ("state", 42); % initialize generator to make eigs behavior reproducible |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
620 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
621 %! d1 = eigs (A, k); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
622 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
623 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
624 %! d1 = eigs (A, k+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
625 %! assert (abs (d1), abs (d0(end:-1:(end-k))),1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
626 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
627 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
628 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
629 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
630 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
631 %! assert (abs (d1), abs (d0(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
632 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
633 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
634 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
635 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
636 %! assert (real (d1), real (d2(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
637 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
638 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
639 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
640 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
641 %! assert (real (d1), real (d2(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
642 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
643 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
644 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
645 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
646 %! assert (sort (imag (d1)), sort (imag (d2(end:-1:(end-k+1)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
647 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
648 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
649 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
650 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
651 %! assert (sort (imag (d1)), sort (imag (d2(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
652 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
653 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
654 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
655 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
656 %! assert (abs (d1(idx1)), abs (d0(idx0(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
657 %! assert (sort (imag (d1(idx1))), sort (imag (d0(idx0(1:k)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
658 %!testif HAVE_ARPACK, HAVE_CHOLMOD |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
659 %! d1 = eigs (A, speye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
660 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
661 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
662 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
663 %! d1 = eigs (A, speye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
664 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
665 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
666 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
667 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
668 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
669 %! d1 = eigs (A, speye (n)(q,q), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
670 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
671 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
672 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
673 %! d1 = eigs (A, speye (n), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
674 %! assert (abs (abs (d1)), abs (eigs (A, k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
675 %! assert (sort (imag (abs (d1))), sort (imag (eigs (A, k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
676 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
677 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
678 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
679 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
680 %! d1 = eigs (A, speye (n)(q,q), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
681 %! assert (abs (abs (d1)), abs (eigs (A, k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
682 %! assert (sort (imag (abs (d1))), sort (imag (eigs (A, k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
683 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
684 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, speye (n), k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
685 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
686 %! assert (sort (imag (eigs (A, k, 4.1))), sort (imag (eigs (A, speye (n), k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
687 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
688 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
689 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
690 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
691 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
692 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
693 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
694 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
695 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
696 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
697 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
698 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
699 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
700 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
701 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
702 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
703 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
704 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
705 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
706 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
707 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
708 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
709 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
710 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
711 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
712 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
713 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
714 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
715 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
716 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
717 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
718 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
719 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
720 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
721 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
722 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
723 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
724 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
725 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
726 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
727 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
728 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
729 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
730 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
731 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
732 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
733 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
734 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
735 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
736 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
737 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
738 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
739 #### FULL MATRIX VERSIONS #### |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
740 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
741 ## Real positive definite tests, n must be even |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
742 %!shared n, k, A, d0, d2 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
743 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
744 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
745 %! 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)])); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
746 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
747 %! d2 = sort (d0); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
748 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
749 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
750 %! rand ("state", 42); % initialize generator to make eigs behavior reproducible |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
751 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
752 %! d1 = eigs (A, k); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
753 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
754 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
755 %! d1 = eigs (A, k+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
756 %! assert (d1, d0(end:-1:(end-k)),1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
757 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
758 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
759 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
760 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
761 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
762 %! assert (d1, d0(k:-1:1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
763 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
764 %! d1 = eigs (A, k, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
765 %! assert (d1, d2(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
766 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
767 %! d1 = eigs (A, k, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
768 %! assert (d1, d2(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
769 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
770 %! d1 = eigs (A, k, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
771 %! assert (d1, d2([1:floor(k/2), (end - ceil(k/2) + 1):end]), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
772 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
773 %! d1 = eigs (A, k+1, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
774 %! assert (d1, d2([1:floor((k+1)/2), (end - ceil((k+1)/2) + 1):end]), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
775 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
776 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
777 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
778 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
779 %! assert (d1(idx1), d0(idx0(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
780 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
781 %! d1 = eigs (A, eye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
782 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
783 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
784 %! assert (eigs (A, k, 4.1), eigs (A, eye (n), k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
785 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
786 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
787 %! d1 = eigs (A, eye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
788 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
789 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
790 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
791 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
792 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
793 %! d1 = eigs (A, eye (n)(q,q), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
794 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
795 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
796 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
797 %! d1 = eigs (A, eye (n), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
798 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
799 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
800 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
801 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
802 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
803 %! d1 = eigs (A, eye (n)(q,q), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
804 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
805 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
806 %! assert (eigs (A, k, 4.1), eigs (A, eye (n), k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
807 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
808 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
809 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
810 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
811 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
812 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
813 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
814 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
815 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
816 %! assert (d1, d0(k:-1:1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
817 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
818 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
819 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
820 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
821 %! assert (d1, eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
822 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
823 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
824 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
825 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
826 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
827 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
828 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
829 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
830 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
831 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
832 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
833 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
834 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
835 %! [v1,d1] = eigs (A, k, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
836 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
837 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
838 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
839 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
840 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
841 %! [v1,d1] = eigs (A, k, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
842 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
843 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
844 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
845 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
846 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
847 %! [v1,d1] = eigs (A, k, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
848 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
849 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
850 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
851 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
852 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
853 ## Real unsymmetric tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
854 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
855 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
856 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
857 %! 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)])); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
858 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
859 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
860 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
861 %! rand ("state", 42); % initialize generator to make eigs behavior reproducible |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
862 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
863 %! d1 = eigs (A, k); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
864 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
865 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
866 %! d1 = eigs (A, k+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
867 %! assert (abs (d1), abs (d0(end:-1:(end-k))),1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
868 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
869 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
870 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
871 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
872 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
873 %! assert (abs (d1), abs (d0(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
874 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
875 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
876 %! [~, idx] = sort (real (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
877 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
878 %! assert (real (d1), real (d2(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
879 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
880 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
881 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
882 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
883 %! assert (real (d1), real (d2(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
884 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
885 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
886 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
887 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
888 %! assert (sort (imag (d1)), sort (imag (d2(end:-1:(end-k+1)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
889 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
890 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
891 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
892 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
893 %! assert (sort (imag (d1)), sort (imag (d2(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
894 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
895 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
896 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
897 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
898 %! assert (abs (d1(idx1)), abs (d0(idx0(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
899 %! assert (sort (imag (d1(idx1))), sort (imag (d0(idx0(1:k)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
900 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
901 %! d1 = eigs (A, eye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
902 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
903 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
904 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
905 %! d1 = eigs (A, eye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
906 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
907 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
908 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
909 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
910 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
911 %! d1 = eigs (A, eye (n)(q,q), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
912 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
913 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
914 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
915 %! d1 = eigs (A, eye (n), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
916 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
917 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
918 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
919 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
920 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
921 %! d1 = eigs (A, eye (n)(q,q), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
922 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
923 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
924 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, eye (n), k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
925 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
926 %! assert (sort (imag (eigs (A, k, 4.1))), sort (imag (eigs (A, eye (n), k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
927 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
928 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
929 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
930 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
931 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
932 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
933 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
934 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
935 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
936 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
937 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
938 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
939 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
940 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
941 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
942 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
943 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
944 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
945 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
946 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
947 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
948 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
949 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
950 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
951 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
952 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
953 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
954 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
955 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
956 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
957 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
958 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
959 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
960 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
961 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
962 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
963 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
964 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
965 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
966 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
967 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
968 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
969 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
970 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
971 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
972 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
973 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
974 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
975 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
976 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
977 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
978 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
979 ## Complex hermitian tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
980 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
981 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
982 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
983 %! 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)])); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
984 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
985 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
986 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
987 %! rand ("state", 42); % initialize generator to make eigs behavior reproducible |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
988 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
989 %! d1 = eigs (A, k); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
990 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
991 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
992 %! d1 = eigs (A, k+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
993 %! assert (abs (d1), abs (d0(end:-1:(end-k))),1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
994 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
995 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
996 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
997 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
998 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
999 %! assert (abs (d1), abs (d0(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1000 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1001 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1002 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1003 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1004 %! assert (real (d1), real (d2(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1005 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1006 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1007 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1008 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1009 %! assert (real (d1), real (d2(1:k)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1010 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1011 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1012 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1013 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1014 %! assert (sort (imag (d1)), sort (imag (d2(end:-1:(end-k+1)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1015 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1016 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1017 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1018 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1019 %! assert (sort (imag (d1)), sort (imag (d2(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1020 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1021 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1022 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1023 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1024 %! assert (abs (d1(idx1)), abs (d0(idx0(1:k))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1025 %! assert (sort (imag (d1(idx1))), sort (imag (d0(idx0(1:k)))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1026 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1027 %! d1 = eigs (A, eye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1028 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1029 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1030 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1031 %! d1 = eigs (A, eye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1032 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1033 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1034 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1035 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1036 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1037 %! d1 = eigs (A, eye (n)(q,q), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1038 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1039 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1040 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1041 %! d1 = eigs (A, eye (n), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1042 %! assert (abs (abs (d1)), abs (eigs (A, k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1043 %! assert (sort (imag (abs (d1))), sort (imag (eigs (A, k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1044 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1045 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1046 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1047 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1048 %! d1 = eigs (A, eye (n)(q,q), k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1049 %! assert (abs (abs (d1)), abs (eigs (A, k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1050 %! assert (sort (imag (abs (d1))), sort (imag (eigs (A, k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1051 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1052 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, eye (n), k, 4.1)), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1053 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1054 %! assert (sort (imag (eigs (A, k, 4.1))), sort (imag (eigs (A, eye (n), k, 4.1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1055 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1056 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1057 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1058 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1059 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1060 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1061 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1062 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1063 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1064 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1065 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1066 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1067 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1068 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1069 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1070 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1071 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1072 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1073 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1074 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1075 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1076 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1077 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1078 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1079 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1080 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1081 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1082 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1083 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1084 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1085 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1086 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1087 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1088 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1089 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1090 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1091 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1092 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1093 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1094 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1095 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1096 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1097 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1098 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1099 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1100 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1101 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1102 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1103 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1104 %! assert (max (abs ((A - d1(i)*eye (n))*v1(:,i))), 0, 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1105 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1106 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1107 %!assert (eigs (diag (1:5), 5, "sa"), [1;2;3;4;5]); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1108 %!assert (eigs (diag (1:5), 5, "la"), [5;4;3;2;1]); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1109 %!assert (eigs (diag (1:5), 3, "be"), [1;4;5]); |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17289
diff
changeset
|
1110 |