Mercurial > octave-nkf
annotate scripts/sparse/eigs.m @ 19627:446c46af4b42 stable
strip trailing whitespace from most source files
* Makefile.am, NEWS, build-aux/common.mk, configure.ac,
doc/Makefile.am, doc/doxyhtml/Makefile.am,
doc/interpreter/Makefile.am, doc/interpreter/arith.txi,
doc/interpreter/audio.txi, doc/interpreter/basics.txi,
doc/interpreter/bugs.txi, doc/interpreter/container.txi,
doc/interpreter/cp-idx.txi, doc/interpreter/data.txi,
doc/interpreter/debug.txi, doc/interpreter/diagperm.txi,
doc/interpreter/diffeq.txi, doc/interpreter/doccheck/README,
doc/interpreter/doccheck/spellcheck, doc/interpreter/emacs.txi,
doc/interpreter/errors.txi, doc/interpreter/eval.txi,
doc/interpreter/expr.txi, doc/interpreter/external.txi,
doc/interpreter/fn-idx.txi, doc/interpreter/func.txi,
doc/interpreter/geometry.txi, doc/interpreter/geometryimages.m,
doc/interpreter/gpl.txi, doc/interpreter/grammar.txi,
doc/interpreter/gui.txi, doc/interpreter/image.txi,
doc/interpreter/install.txi, doc/interpreter/interp.txi,
doc/interpreter/interpimages.m, doc/interpreter/intro.txi,
doc/interpreter/io.txi, doc/interpreter/java.txi,
doc/interpreter/linalg.txi, doc/interpreter/macros.texi,
doc/interpreter/matrix.txi, doc/interpreter/munge-texi.pl,
doc/interpreter/nonlin.txi, doc/interpreter/numbers.txi,
doc/interpreter/obsolete.txi, doc/interpreter/octave-config.1,
doc/interpreter/octave.texi, doc/interpreter/oop.txi,
doc/interpreter/op-idx.txi, doc/interpreter/optim.txi,
doc/interpreter/package.txi, doc/interpreter/plot.txi,
doc/interpreter/poly.txi, doc/interpreter/preface.txi,
doc/interpreter/quad.txi, doc/interpreter/set.txi,
doc/interpreter/signal.txi, doc/interpreter/sparse.txi,
doc/interpreter/sparseimages.m, doc/interpreter/splineimages.m,
doc/interpreter/stats.txi, doc/interpreter/stmt.txi,
doc/interpreter/strings.txi, doc/interpreter/system.txi,
doc/interpreter/testfun.txi, doc/interpreter/tips.txi,
doc/interpreter/var.txi, doc/interpreter/vectorize.txi,
doc/liboctave/Makefile.am, doc/liboctave/array.texi,
doc/liboctave/bugs.texi, doc/liboctave/cp-idx.texi,
doc/liboctave/dae.texi, doc/liboctave/diffeq.texi,
doc/liboctave/error.texi, doc/liboctave/factor.texi,
doc/liboctave/fn-idx.texi, doc/liboctave/gpl.texi,
doc/liboctave/install.texi, doc/liboctave/intro.texi,
doc/liboctave/liboctave.texi, doc/liboctave/matvec.texi,
doc/liboctave/nleqn.texi, doc/liboctave/nlfunc.texi,
doc/liboctave/ode.texi, doc/liboctave/optim.texi,
doc/liboctave/preface.texi, doc/liboctave/quad.texi,
doc/liboctave/range.texi, doc/refcard/Makefile.am,
doc/refcard/refcard.tex, etc/HACKING, etc/NEWS.1, etc/NEWS.2,
etc/NEWS.3, etc/OLD-ChangeLogs/ChangeLog,
etc/OLD-ChangeLogs/doc-ChangeLog,
etc/OLD-ChangeLogs/scripts-ChangeLog,
etc/OLD-ChangeLogs/src-ChangeLog, etc/OLD-ChangeLogs/test-ChangeLog,
etc/PROJECTS, etc/README.Cygwin, etc/README.MacOS, etc/README.MinGW,
etc/README.gnuplot, etc/gdbinit, etc/icons/Makefile.am,
examples/@polynomial/end.m, examples/@polynomial/subsasgn.m,
examples/Makefile.am, examples/standalonebuiltin.cc,
libgui/Makefile.am, libgui/qterminal/libqterminal/README,
libgui/qterminal/libqterminal/unix/BlockArray.cpp,
libgui/qterminal/libqterminal/unix/BlockArray.h,
libgui/qterminal/libqterminal/unix/Character.h,
libgui/qterminal/libqterminal/unix/CharacterColor.h,
libgui/qterminal/libqterminal/unix/Emulation.cpp,
libgui/qterminal/libqterminal/unix/Emulation.h,
libgui/qterminal/libqterminal/unix/Filter.cpp,
libgui/qterminal/libqterminal/unix/Filter.h,
libgui/qterminal/libqterminal/unix/History.cpp,
libgui/qterminal/libqterminal/unix/History.h,
libgui/qterminal/libqterminal/unix/KeyboardTranslator.cpp,
libgui/qterminal/libqterminal/unix/KeyboardTranslator.h,
libgui/qterminal/libqterminal/unix/LineFont.h,
libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp,
libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.h,
libgui/qterminal/libqterminal/unix/Screen.cpp,
libgui/qterminal/libqterminal/unix/Screen.h,
libgui/qterminal/libqterminal/unix/ScreenWindow.cpp,
libgui/qterminal/libqterminal/unix/ScreenWindow.h,
libgui/qterminal/libqterminal/unix/TerminalCharacterDecoder.cpp,
libgui/qterminal/libqterminal/unix/TerminalCharacterDecoder.h,
libgui/qterminal/libqterminal/unix/Vt102Emulation.h,
libgui/qterminal/libqterminal/win32/QWinTerminalImpl.cpp,
libgui/qterminal/qterminal/main.cpp,
libgui/src/m-editor/file-editor-tab.cc, libgui/src/octave-gui.cc,
libgui/src/octave-qt-link.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/defun-int.h, libinterp/corefcn/det.cc,
libinterp/corefcn/gl2ps-renderer.cc, libinterp/corefcn/graphics.cc,
libinterp/corefcn/graphics.in.h, libinterp/corefcn/ls-mat5.cc,
libinterp/corefcn/lu.cc, libinterp/corefcn/oct-tex-parser.yy,
libinterp/corefcn/oct-tex-symbols.in, libinterp/corefcn/quadcc.cc,
libinterp/corefcn/zfstream.cc, libinterp/dldfcn/__eigs__.cc,
libinterp/dldfcn/__voronoi__.cc, libinterp/gendoc.pl,
libinterp/genprops.awk, libinterp/mk-errno-list, libinterp/mk-pkg-add,
libinterp/mkbuiltins, libinterp/mkdefs, libinterp/mkdocs,
libinterp/mkops, libinterp/octave-value/ov-java.cc,
libinterp/parse-tree/lex.ll, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/octave.gperf, liboctave/Makefile.am,
liboctave/array/Array.cc, liboctave/array/module.mk,
liboctave/cruft/daspk/datv.f, liboctave/cruft/daspk/dcnst0.f,
liboctave/cruft/daspk/dcnstr.f, liboctave/cruft/daspk/ddasic.f,
liboctave/cruft/daspk/ddasid.f, liboctave/cruft/daspk/ddasik.f,
liboctave/cruft/daspk/ddaspk.f, liboctave/cruft/daspk/ddstp.f,
liboctave/cruft/daspk/ddwnrm.f, liboctave/cruft/daspk/dfnrmd.f,
liboctave/cruft/daspk/dfnrmk.f, liboctave/cruft/daspk/dhels.f,
liboctave/cruft/daspk/dheqr.f, liboctave/cruft/daspk/dinvwt.f,
liboctave/cruft/daspk/dlinsd.f, liboctave/cruft/daspk/dlinsk.f,
liboctave/cruft/daspk/dmatd.f, liboctave/cruft/daspk/dnedd.f,
liboctave/cruft/daspk/dnedk.f, liboctave/cruft/daspk/dnsd.f,
liboctave/cruft/daspk/dnsid.f, liboctave/cruft/daspk/dnsik.f,
liboctave/cruft/daspk/dnsk.f, liboctave/cruft/daspk/dorth.f,
liboctave/cruft/daspk/dslvd.f, liboctave/cruft/daspk/dslvk.f,
liboctave/cruft/daspk/dspigm.f, liboctave/cruft/daspk/dyypnw.f,
liboctave/cruft/dasrt/ddasrt.f, liboctave/cruft/dasrt/drchek.f,
liboctave/cruft/dassl/ddaslv.f, liboctave/cruft/dassl/ddassl.f,
liboctave/cruft/misc/blaswrap.c, liboctave/cruft/misc/module.mk,
liboctave/cruft/odepack/cfode.f, liboctave/cruft/odepack/dlsode.f,
liboctave/cruft/odepack/ewset.f, liboctave/cruft/odepack/intdy.f,
liboctave/cruft/odepack/prepj.f, liboctave/cruft/odepack/sintdy.f,
liboctave/cruft/odepack/slsode.f, liboctave/cruft/odepack/solsy.f,
liboctave/cruft/odepack/ssolsy.f, liboctave/cruft/odepack/stode.f,
liboctave/cruft/odepack/vnorm.f, liboctave/cruft/ranlib/Basegen.doc,
liboctave/cruft/ranlib/README, liboctave/cruft/ranlib/genbet.f,
liboctave/cruft/ranlib/genexp.f, liboctave/cruft/ranlib/gennch.f,
liboctave/cruft/ranlib/gennf.f, liboctave/cruft/ranlib/gennor.f,
liboctave/cruft/ranlib/getsd.f, liboctave/cruft/ranlib/initgn.f,
liboctave/cruft/ranlib/phrtsd.f, liboctave/cruft/ranlib/randlib.fdoc,
liboctave/cruft/ranlib/setsd.f, liboctave/cruft/ranlib/tstgmn.for,
liboctave/cruft/ranlib/tstmid.for, liboctave/cruft/slatec-fn/atanh.f,
liboctave/cruft/slatec-fn/datanh.f,
liboctave/cruft/slatec-fn/xgmainc.f,
liboctave/cruft/slatec-fn/xsgmainc.f, liboctave/numeric/module.mk,
liboctave/operators/mk-ops.awk, liboctave/operators/mx-ops,
liboctave/operators/sparse-mk-ops.awk,
liboctave/operators/sparse-mx-ops, liboctave/operators/vx-ops,
liboctave/util/module.mk, run-octave.in, scripts/@ftp/ftp.m,
scripts/audio/wavread.m, scripts/deprecated/java_convert_matrix.m,
scripts/deprecated/java_debug.m, scripts/deprecated/java_invoke.m,
scripts/deprecated/java_new.m,
scripts/deprecated/java_unsigned_conversion.m,
scripts/deprecated/javafields.m, scripts/deprecated/javamethods.m,
scripts/deprecated/shell_cmd.m, scripts/general/accumarray.m,
scripts/general/display.m, scripts/general/fieldnames.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/isa.m,
scripts/general/methods.m, scripts/general/sortrows.m,
scripts/geometry/convhull.m, scripts/geometry/delaunay.m,
scripts/geometry/delaunay3.m, scripts/geometry/delaunayn.m,
scripts/geometry/griddata.m, scripts/geometry/griddatan.m,
scripts/geometry/voronoi.m, scripts/geometry/voronoin.m,
scripts/gui/guihandles.m, scripts/gui/inputdlg.m,
scripts/gui/listdlg.m, scripts/gui/msgbox.m, scripts/gui/questdlg.m,
scripts/gui/uigetfile.m, scripts/gui/waitbar.m, scripts/gui/warndlg.m,
scripts/help/doc.m, scripts/help/help.m, scripts/help/type.m,
scripts/image/bone.m, scripts/image/cmpermute.m,
scripts/image/cmunique.m, scripts/image/colorcube.m,
scripts/image/colormap.m, scripts/image/contrast.m,
scripts/image/gray2ind.m, scripts/image/image.m,
scripts/image/imshow.m, scripts/image/ind2gray.m, scripts/image/jet.m,
scripts/image/rgb2ntsc.m, scripts/image/spinmap.m,
scripts/io/importdata.m, scripts/io/strread.m, scripts/io/textread.m,
scripts/io/textscan.m, scripts/java/java_get.m,
scripts/java/java_set.m, scripts/java/javaaddpath.m,
scripts/java/javaclasspath.m, scripts/java/javamem.m,
scripts/linear-algebra/linsolve.m, scripts/linear-algebra/qzhess.m,
scripts/miscellaneous/debug.m, scripts/miscellaneous/desktop.m,
scripts/miscellaneous/dir.m, scripts/miscellaneous/dos.m,
scripts/miscellaneous/edit.m, scripts/miscellaneous/fact.m,
scripts/miscellaneous/getappdata.m, scripts/miscellaneous/inputname.m,
scripts/miscellaneous/license.m, scripts/miscellaneous/ls_command.m,
scripts/miscellaneous/run.m, scripts/miscellaneous/setfield.m,
scripts/miscellaneous/unix.m, scripts/miscellaneous/ver.m,
scripts/mk-pkg-add, scripts/mkdoc.pl,
scripts/optimization/fminsearch.m, scripts/optimization/optimset.m,
scripts/optimization/sqp.m, scripts/pkg/pkg.m,
scripts/pkg/private/create_pkgadddel.m,
scripts/pkg/private/fix_depends.m, scripts/pkg/private/install.m,
scripts/plot/appearance/axis.m, scripts/plot/appearance/box.m,
scripts/plot/appearance/clabel.m, scripts/plot/appearance/daspect.m,
scripts/plot/appearance/datetick.m, scripts/plot/appearance/grid.m,
scripts/plot/appearance/legend.m, scripts/plot/appearance/orient.m,
scripts/plot/appearance/shading.m, scripts/plot/appearance/text.m,
scripts/plot/appearance/title.m, scripts/plot/appearance/xlabel.m,
scripts/plot/appearance/ylabel.m, scripts/plot/appearance/zlabel.m,
scripts/plot/draw/area.m, scripts/plot/draw/bar.m,
scripts/plot/draw/barh.m, scripts/plot/draw/colorbar.m,
scripts/plot/draw/contour.m, scripts/plot/draw/contour3.m,
scripts/plot/draw/contourf.m, scripts/plot/draw/ellipsoid.m,
scripts/plot/draw/errorbar.m, scripts/plot/draw/ezcontour.m,
scripts/plot/draw/ezcontourf.m, scripts/plot/draw/ezmesh.m,
scripts/plot/draw/ezpolar.m, scripts/plot/draw/fill.m,
scripts/plot/draw/fplot.m, scripts/plot/draw/hist.m,
scripts/plot/draw/meshc.m, scripts/plot/draw/meshz.m,
scripts/plot/draw/pareto.m, scripts/plot/draw/patch.m,
scripts/plot/draw/peaks.m, scripts/plot/draw/pie.m,
scripts/plot/draw/pie3.m, scripts/plot/draw/plot.m,
scripts/plot/draw/plotyy.m, scripts/plot/draw/private/__bar__.m,
scripts/plot/draw/private/__contour__.m,
scripts/plot/draw/private/__errplot__.m,
scripts/plot/draw/private/__ezplot__.m,
scripts/plot/draw/private/__patch__.m,
scripts/plot/draw/private/__stem__.m, scripts/plot/draw/rectangle.m,
scripts/plot/draw/ribbon.m, scripts/plot/draw/rose.m,
scripts/plot/draw/scatter.m, scripts/plot/draw/scatter3.m,
scripts/plot/draw/semilogx.m, scripts/plot/draw/shrinkfaces.m,
scripts/plot/draw/sombrero.m, scripts/plot/draw/sphere.m,
scripts/plot/draw/stairs.m, scripts/plot/draw/stem.m,
scripts/plot/draw/stemleaf.m, scripts/plot/draw/surf.m,
scripts/plot/draw/surface.m, scripts/plot/draw/surfc.m,
scripts/plot/draw/surfl.m, scripts/plot/draw/surfnorm.m,
scripts/plot/draw/tetramesh.m, scripts/plot/draw/trimesh.m,
scripts/plot/draw/triplot.m, scripts/plot/draw/trisurf.m,
scripts/plot/util/__gnuplot_drawnow__.m,
scripts/plot/util/__plt_get_axis_arg__.m, scripts/plot/util/axes.m,
scripts/plot/util/clf.m, scripts/plot/util/copyobj.m,
scripts/plot/util/figure.m, scripts/plot/util/gcbo.m,
scripts/plot/util/graphics_toolkit.m, scripts/plot/util/hggroup.m,
scripts/plot/util/meshgrid.m, scripts/plot/util/newplot.m,
scripts/plot/util/print.m,
scripts/plot/util/private/__add_default_menu__.m,
scripts/plot/util/private/__fltk_print__.m,
scripts/plot/util/private/__gnuplot_print__.m,
scripts/plot/util/private/__print_parse_opts__.m,
scripts/plot/util/refreshdata.m, scripts/plot/util/subplot.m,
scripts/polynomial/conv.m, scripts/polynomial/poly.m,
scripts/polynomial/polyeig.m, scripts/polynomial/polyfit.m,
scripts/polynomial/polyval.m,
scripts/polynomial/private/__splinefit__.m,
scripts/polynomial/spline.m, scripts/prefs/prefdir.m,
scripts/prefs/preferences.m, scripts/prefs/private/prefsfile.m,
scripts/prefs/rmpref.m, scripts/signal/freqz.m,
scripts/signal/module.mk, scripts/sparse/eigs.m, scripts/sparse/pcg.m,
scripts/sparse/private/__sprand_impl__.m, scripts/sparse/sprand.m,
scripts/sparse/sprandn.m, scripts/sparse/spy.m, scripts/sparse/svds.m,
scripts/specfun/expint.m, scripts/specfun/factor.m,
scripts/special-matrix/gallery.m, scripts/special-matrix/hankel.m,
scripts/special-matrix/toeplitz.m, scripts/startup/inputrc,
scripts/statistics/base/kurtosis.m, scripts/statistics/base/moment.m,
scripts/statistics/base/qqplot.m, scripts/statistics/base/var.m,
scripts/statistics/distributions/betarnd.m,
scripts/statistics/distributions/binoinv.m,
scripts/statistics/distributions/binopdf.m,
scripts/statistics/distributions/binornd.m,
scripts/statistics/distributions/cauchy_rnd.m,
scripts/statistics/distributions/chi2rnd.m,
scripts/statistics/distributions/discrete_pdf.m,
scripts/statistics/distributions/discrete_rnd.m,
scripts/statistics/distributions/empirical_rnd.m,
scripts/statistics/distributions/exprnd.m,
scripts/statistics/distributions/frnd.m,
scripts/statistics/distributions/gamrnd.m,
scripts/statistics/distributions/geornd.m,
scripts/statistics/distributions/hygernd.m,
scripts/statistics/distributions/kolmogorov_smirnov_cdf.m,
scripts/statistics/distributions/laplace_cdf.m,
scripts/statistics/distributions/laplace_pdf.m,
scripts/statistics/distributions/logistic_cdf.m,
scripts/statistics/distributions/logistic_pdf.m,
scripts/statistics/distributions/lognrnd.m,
scripts/statistics/distributions/nbincdf.m,
scripts/statistics/distributions/nbininv.m,
scripts/statistics/distributions/nbinpdf.m,
scripts/statistics/distributions/nbinrnd.m,
scripts/statistics/distributions/normrnd.m,
scripts/statistics/distributions/poissinv.m,
scripts/statistics/distributions/poissrnd.m,
scripts/statistics/distributions/tinv.m,
scripts/statistics/distributions/trnd.m,
scripts/statistics/distributions/unidcdf.m,
scripts/statistics/distributions/unidpdf.m,
scripts/statistics/distributions/unidrnd.m,
scripts/statistics/distributions/unifrnd.m,
scripts/statistics/distributions/wblrnd.m,
scripts/statistics/models/module.mk,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/strings/base2dec.m, scripts/strings/deblank.m,
scripts/strings/dec2base.m, scripts/strings/dec2bin.m,
scripts/strings/dec2hex.m, scripts/strings/mat2str.m,
scripts/strings/ostrsplit.m, scripts/strings/regexptranslate.m,
scripts/strings/str2num.m, scripts/strings/strcat.m,
scripts/strings/strjoin.m, scripts/strings/strsplit.m,
scripts/strings/strtok.m, scripts/strings/strtrim.m,
scripts/strings/strtrunc.m, scripts/strings/substr.m,
scripts/testfun/__run_test_suite__.m, scripts/testfun/speed.m,
scripts/testfun/test.m, scripts/time/asctime.m,
scripts/time/datenum.m, scripts/time/datevec.m,
scripts/time/weekday.m, src/Makefile.am, test/Makefile.am,
test/build-bc-overload-tests.sh, test/build-sparse-tests.sh,
test/jit.tst, test/line-continue.tst: Strip trailing whitespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 08:26:57 -0500 |
parents | 1782f5294fdc |
children | 0e1f5a750d00 08dbf53f34c1 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17338
diff
changeset
|
1 ## Copyright (C) 2005-2013 David Bateman |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
43 ## |
17220
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 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
66 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
71 ## |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 ## @table @asis |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
73 ## @item @qcode{"lm"} |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 ## Largest Magnitude (default). |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
75 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
76 ## @item @qcode{"sm"} |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 ## Smallest Magnitude. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
78 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
79 ## @item @qcode{"la"} |
17220
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). |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
81 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
82 ## @item @qcode{"sa"} |
17220
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). |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
84 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
85 ## @item @qcode{"be"} |
17220
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). |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
88 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
89 ## @item @qcode{"lr"} |
17220
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). |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
91 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
92 ## @item @qcode{"sr"} |
17220
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). |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
94 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
95 ## @item @qcode{"li"} |
17220
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). |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
97 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17220
diff
changeset
|
98 ## @item @qcode{"si"} |
17220
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 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
101 ## |
17220
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: |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
104 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
109 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
113 ## |
17220
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}. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
117 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
120 ## |
17220
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}}. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
126 ## |
17220
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})} |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
132 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
136 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
140 ## |
17220
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}}. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
145 ## |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 ## @end table |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
147 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
153 ## |
17220
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 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
157 ## |
17220
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". |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
161 ## |
17220
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". |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
164 ## |
17220
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}. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
168 ## |
17220
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 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
172 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
181 ## |
17220
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. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
185 ## |
17220
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/}. |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
189 ## |
17220
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 |
19627
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18817
diff
changeset
|
218 |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
285 error ('sigma = "la" requires real symmetric problem'); |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
292 error ('sigma = "sa" requires real symmetric problem'); |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
299 error ('sigma = "be" requires real symmetric problem'); |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
306 error ('sigma = "lr" requires complex or unsymmetric problem'); |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
313 error ('sigma = "sr" requires complex or unsymmetric problem'); |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
320 error ('sigma = "li" requires complex or unsymmetric problem'); |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
327 error ('sigma = "si" requires complex or unsymmetric problem'); |
17220
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 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
333 else |
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
334 ## numeric sigma, find k closest values |
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
335 [~, idx] = sort (abs (d - sigma)); |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
336 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
337 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
338 d = d(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
340 n = numel (d); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
341 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
342 k = min (k, n); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
343 |
17846
42453dcfa95e
eigs.m: Fix regression when numeric sigma is used and eig() is called instead of __eigs__.
Rik <rik@octave.org>
parents:
17845
diff
changeset
|
344 if (strcmp (sigma, "be")) |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
345 tmp = k / 2; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
346 n1 = floor (tmp); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
347 n2 = n - ceil (tmp) + 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
348 selection = [1:floor(k/2), n2:n]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
349 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
350 selection = 1:k; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
351 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
353 d = d(selection); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
354 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
355 if (numel (args) == 1) |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
356 out{1} = d; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
357 else |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
358 out{2} = diag (d); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
359 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
360 v = args{1}; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
361 v = v(:,idx); |
18817
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
362 out{1} = v(:,selection); |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
363 endif |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
364 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
365 endfunction |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
366 |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
367 |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
368 #### SPARSE MATRIX VERSIONS #### |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
369 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
370 ## Real positive definite tests, n must be even |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
371 %!shared n, k, A, d0, d2 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
372 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
373 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
374 %! 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
|
375 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
376 %! d2 = sort (d0); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
377 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
378 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
379 %! 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
|
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); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
382 %! 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
|
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+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
385 %! 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
|
386 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
387 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
388 %! 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
|
389 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
390 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
391 %! assert (d1, d0(k:-1: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, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
394 %! 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
|
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, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
397 %! assert (d1, d2(1:k), 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, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
400 %! 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
|
401 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
402 %! d1 = eigs (A, k+1, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
403 %! 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
|
404 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
405 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
406 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
408 %! 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
|
409 %!testif HAVE_ARPACK, HAVE_CHOLMOD |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
410 %! d1 = eigs (A, speye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
411 %! 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
|
412 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
413 %! 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
|
414 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
415 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
416 %! d1 = eigs (A, speye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
417 %! 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
|
418 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
419 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
420 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
421 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
422 %! 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
|
423 %! 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
|
424 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
426 %! 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
|
427 %! 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
|
428 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
429 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
430 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
431 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
432 %! 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
|
433 %! 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
|
434 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
435 %! 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
|
436 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
437 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
438 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
439 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
440 %! 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
|
441 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
442 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
443 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
444 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
445 %! assert (d1, d0(k:-1:1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
446 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
447 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
448 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
449 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
450 %! 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
|
451 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
452 %! AA = speye (10); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
453 %! fn = @(x) AA * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
454 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
455 %! 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
|
456 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
457 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
458 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
459 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
460 %! 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
|
461 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
462 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
463 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
464 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
465 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
466 %! 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
|
467 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
468 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
469 %! [v1,d1] = eigs (A, k, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
470 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
471 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
472 %! 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
|
473 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
474 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
475 %! [v1,d1] = eigs (A, k, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
476 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
477 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
478 %! 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
|
479 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
480 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
481 %! [v1,d1] = eigs (A, k, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
482 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
483 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
484 %! 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
|
485 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
486 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
487 ## Real unsymmetric tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
488 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
489 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
490 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
491 %! 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
|
492 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
493 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
494 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
495 %! 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
|
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); |
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+1))), 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+1); |
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))),1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
502 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
503 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
504 %! 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
|
505 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
506 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
507 %! 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
|
508 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
509 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
510 %! [~, idx] = sort (real (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
511 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
512 %! 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
|
513 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
514 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
515 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
517 %! 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
|
518 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
519 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
520 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
521 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
522 %! 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
|
523 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
524 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
525 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
526 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
527 %! 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
|
528 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
529 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
530 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
531 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
532 %! 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
|
533 %! 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
|
534 %!testif HAVE_ARPACK, HAVE_CHOLMOD |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
535 %! d1 = eigs (A, speye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
536 %! 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
|
537 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
538 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
539 %! d1 = eigs (A, speye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
540 %! 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
|
541 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
542 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
543 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
544 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
545 %! 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
|
546 %! 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
|
547 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
548 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
549 %! 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
|
550 %! 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
|
551 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
552 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
553 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
554 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
555 %! 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
|
556 %! 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
|
557 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
558 %! 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
|
559 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
560 %! 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
|
561 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
562 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
563 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
564 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
565 %! 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
|
566 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
567 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
568 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
569 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
570 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
571 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
572 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
573 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
574 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
575 %! 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
|
576 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
577 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
578 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
579 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
580 %! 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
|
581 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
582 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
583 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
584 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
585 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
586 %! 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
|
587 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
588 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
589 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
590 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
591 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
592 %! 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
|
593 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
594 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
595 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
596 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
597 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
598 %! 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
|
599 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
600 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
601 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
602 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
603 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
604 %! 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
|
605 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
606 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
607 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
608 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
609 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
610 %! 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
|
611 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
612 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
613 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
614 ## Complex hermitian tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
615 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
616 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
617 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
618 %! 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
|
619 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
620 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
621 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
622 %! 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
|
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); |
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+1))), 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+1); |
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))),1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
629 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
630 %! d1 = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
631 %! 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
|
632 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
633 %! d1 = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
634 %! 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
|
635 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
636 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
637 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
638 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
639 %! 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
|
640 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
641 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
642 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
643 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
644 %! 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
|
645 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
646 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
647 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
648 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
649 %! 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
|
650 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
651 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
652 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
653 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
654 %! 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
|
655 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
656 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
657 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
658 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
659 %! 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
|
660 %! 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
|
661 %!testif HAVE_ARPACK, HAVE_CHOLMOD |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
662 %! d1 = eigs (A, speye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
663 %! 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
|
664 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
665 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
666 %! d1 = eigs (A, speye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
667 %! 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
|
668 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
669 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
670 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
671 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
672 %! 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
|
673 %! 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
|
674 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
675 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
676 %! 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
|
677 %! 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
|
678 %! 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
|
679 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
680 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
681 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
682 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
683 %! 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
|
684 %! 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
|
685 %! 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
|
686 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
687 %! 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
|
688 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
689 %! 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
|
690 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
691 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
692 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
693 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
694 %! 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
|
695 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
696 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
697 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
698 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
699 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
700 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
701 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
702 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
703 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
704 %! 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
|
705 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
706 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
707 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
708 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
709 %! 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
|
710 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
711 %!testif HAVE_ARPACK, HAVE_UMFPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
712 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
713 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
714 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
715 %! 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
|
716 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
717 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
718 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
719 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
720 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
721 %! 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
|
722 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
723 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
724 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
725 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
726 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
727 %! 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
|
728 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
729 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
730 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
731 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
732 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
733 %! 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
|
734 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
735 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
736 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
737 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
738 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
739 %! 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
|
740 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
741 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
742 #### FULL MATRIX VERSIONS #### |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
743 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
744 ## Real positive definite tests, n must be even |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
745 %!shared n, k, A, d0, d2 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
746 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
747 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
748 %! 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
|
749 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
750 %! d2 = sort (d0); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
751 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
752 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
753 %! 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
|
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); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
756 %! 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
|
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+1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
759 %! 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
|
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, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
762 %! 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
|
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, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
765 %! assert (d1, d0(k:-1: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, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
768 %! 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
|
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, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
771 %! assert (d1, d2(1:k), 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, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
774 %! 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
|
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+1, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
777 %! 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
|
778 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
779 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
780 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
781 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
782 %! 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
|
783 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
784 %! d1 = eigs (A, eye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
785 %! 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
|
786 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
787 %! 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
|
788 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
789 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
790 %! d1 = eigs (A, eye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
791 %! 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
|
792 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
793 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
794 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
795 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
796 %! 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
|
797 %! 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
|
798 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
799 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
800 %! 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
|
801 %! 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
|
802 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
803 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
804 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
805 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
806 %! 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
|
807 %! 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
|
808 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
809 %! 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
|
810 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
811 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
812 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
813 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
814 %! 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
|
815 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
816 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
817 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
818 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
819 %! assert (d1, d0(k:-1:1), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
820 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
821 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
822 %! opts.issym = 1; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
823 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
824 %! 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
|
825 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
826 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
827 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
828 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
829 %! 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
|
830 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
831 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
832 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
833 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
834 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
835 %! 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
|
836 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
837 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
838 %! [v1,d1] = eigs (A, k, "la"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
839 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
840 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
841 %! 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
|
842 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
843 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
844 %! [v1,d1] = eigs (A, k, "sa"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
845 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
846 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
847 %! 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
|
848 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
849 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
850 %! [v1,d1] = eigs (A, k, "be"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
851 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
852 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
853 %! 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
|
854 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
855 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
856 ## Real unsymmetric tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
857 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
858 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
859 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
860 %! 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
|
861 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
862 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
863 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
864 %! 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
|
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); |
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+1))), 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+1); |
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))),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, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
873 %! 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
|
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, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
876 %! 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
|
877 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
878 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
879 %! [~, idx] = sort (real (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
880 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
881 %! 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
|
882 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
883 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
884 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
885 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
886 %! 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
|
887 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
888 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
889 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
890 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
891 %! 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
|
892 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
893 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
894 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
895 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
896 %! 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
|
897 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
898 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
899 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
900 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
901 %! 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
|
902 %! 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
|
903 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
904 %! d1 = eigs (A, eye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
905 %! 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
|
906 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
907 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
908 %! d1 = eigs (A, eye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
909 %! 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
|
910 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
911 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
912 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
913 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
914 %! 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
|
915 %! 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
|
916 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
917 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
918 %! 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
|
919 %! 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
|
920 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
921 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
922 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
923 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
924 %! 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
|
925 %! 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
|
926 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
927 %! 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
|
928 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
929 %! 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
|
930 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
931 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
932 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
933 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
934 %! 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
|
935 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
936 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
937 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
938 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
939 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
940 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
941 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
942 %! opts.issym = 0; opts.isreal = 1; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
943 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
944 %! 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
|
945 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
946 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
947 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
948 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
949 %! 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
|
950 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
951 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
952 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
953 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
954 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
955 %! 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
|
956 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
957 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
958 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
959 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
960 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
961 %! 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
|
962 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
963 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
964 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
965 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
966 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
967 %! 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
|
968 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
969 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
970 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
971 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
972 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
973 %! 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
|
974 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
975 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
976 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
977 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
978 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
979 %! 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
|
980 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
981 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
982 ## Complex hermitian tests |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
983 %!shared n, k, A, d0 |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
984 %! n = 20; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
985 %! k = 4; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
986 %! 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
|
987 %! d0 = eig (A); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
988 %! [~, idx] = sort (abs (d0)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
989 %! d0 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
990 %! 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
|
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); |
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+1))), 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+1); |
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))),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, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
999 %! 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
|
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, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1002 %! 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
|
1003 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1004 %! d1 = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1005 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1006 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1007 %! 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
|
1008 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1009 %! d1 = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1010 %! [~, idx] = sort (real (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1011 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1012 %! 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
|
1013 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1014 %! d1 = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1015 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1016 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1017 %! 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
|
1018 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1019 %! d1 = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1020 %! [~, idx] = sort (imag (abs (d0))); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1021 %! d2 = d0(idx); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1022 %! 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
|
1023 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1024 %! d1 = eigs (A, k, 4.1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1025 %! [~, idx0] = sort (abs (d0 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1026 %! [~, idx1] = sort (abs (d1 - 4.1)); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1027 %! 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
|
1028 %! 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
|
1029 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1030 %! d1 = eigs (A, eye (n), k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1031 %! 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
|
1032 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1033 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1034 %! d1 = eigs (A, eye (n), k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1035 %! 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
|
1036 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1037 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1038 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1039 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1040 %! 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
|
1041 %! 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
|
1042 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1043 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1044 %! 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
|
1045 %! 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
|
1046 %! 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
|
1047 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1048 %! opts.cholB = true; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1049 %! q = [2:n,1]; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1050 %! opts.permB = q; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1051 %! 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
|
1052 %! 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
|
1053 %! 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
|
1054 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1055 %! 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
|
1056 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1057 %! 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
|
1058 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1059 %! fn = @(x) A * x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1060 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1061 %! d1 = eigs (fn, n, k, "lm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1062 %! 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
|
1063 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1064 %! fn = @(x) A \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1065 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1066 %! d1 = eigs (fn, n, k, "sm", opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1067 %! assert (abs (d1), d0(1:k), 1e-11); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1068 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1069 %! fn = @(x) (A - 4.1 * eye (n)) \ x; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1070 %! opts.issym = 0; opts.isreal = 0; |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1071 %! d1 = eigs (fn, n, k, 4.1, opts); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1072 %! 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
|
1073 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1074 %! [v1,d1] = eigs (A, k, "lm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1075 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1076 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1077 %! 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
|
1078 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1079 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1080 %! [v1,d1] = eigs (A, k, "sm"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1081 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1082 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1083 %! 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
|
1084 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1085 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1086 %! [v1,d1] = eigs (A, k, "lr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1087 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1088 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1089 %! 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
|
1090 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1091 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1092 %! [v1,d1] = eigs (A, k, "sr"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1093 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1094 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1095 %! 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
|
1096 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1097 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1098 %! [v1,d1] = eigs (A, k, "li"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1099 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1100 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1101 %! 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
|
1102 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1103 %!testif HAVE_ARPACK |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1104 %! [v1,d1] = eigs (A, k, "si"); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1105 %! d1 = diag (d1); |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1106 %! for i=1:k |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1107 %! 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
|
1108 %! endfor |
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1109 |
17845
0f912af348e0
add a test to mark regression in eigs
Carlo de Falco <cdf@users.sourceforge.net>
parents:
17744
diff
changeset
|
1110 %!test |
0f912af348e0
add a test to mark regression in eigs
Carlo de Falco <cdf@users.sourceforge.net>
parents:
17744
diff
changeset
|
1111 %! A = 2 * diag (ones (10, 1)) - diag (ones (9, 1), 1) - diag (ones (9, 1), -1); |
0f912af348e0
add a test to mark regression in eigs
Carlo de Falco <cdf@users.sourceforge.net>
parents:
17744
diff
changeset
|
1112 %! B = diag (ones (10, 1)); |
0f912af348e0
add a test to mark regression in eigs
Carlo de Falco <cdf@users.sourceforge.net>
parents:
17744
diff
changeset
|
1113 %! reseig = eig (A, B); |
0f912af348e0
add a test to mark regression in eigs
Carlo de Falco <cdf@users.sourceforge.net>
parents:
17744
diff
changeset
|
1114 %! [~, idx] = sort (abs (reseig), "ascend"); |
0f912af348e0
add a test to mark regression in eigs
Carlo de Falco <cdf@users.sourceforge.net>
parents:
17744
diff
changeset
|
1115 %! assert (eigs (A, B, 10, 0), reseig (idx)) |
0f912af348e0
add a test to mark regression in eigs
Carlo de Falco <cdf@users.sourceforge.net>
parents:
17744
diff
changeset
|
1116 |
18817
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1117 %!test |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1118 %! X = [70 47 42 39 50 73 79 23; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1119 %! 19 52 61 80 36 76 63 68; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1120 %! 14 34 66 65 29 4 72 9; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1121 %! 24 8 78 49 58 54 43 33; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1122 %! 62 69 32 31 40 46 22 28; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1123 %! 48 12 45 59 10 17 15 25; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1124 %! 64 67 77 56 13 55 41 74; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1125 %! 37 38 18 21 11 3 71 7; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1126 %! 5 35 16 1 51 27 26 44; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1127 %! 30 57 60 75 2 53 20 6]; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1128 %! Z = X * X'; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1129 %! r = rank (Z); |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1130 %! assert (r, 8); |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1131 %! [V, D] = eigs (Z, r, "lm"); |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1132 %! ZZ = V * D * V'; |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1133 %! tmp = abs (Z - ZZ); |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1134 %! assert (max (tmp(:)) < 5e-11); |
1782f5294fdc
eigs: selection columns of V, not rows (bug #41795)
John W. Eaton <jwe@octave.org>
parents:
17846
diff
changeset
|
1135 |
17220
ea9992fd9c89
fix eigs to handle small matrices
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1136 %!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
|
1137 %!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
|
1138 %!assert (eigs (diag (1:5), 3, "be"), [1;4;5]); |