comparison scripts/sparse/eigs.m @ 30893:e1788b1a315f

maint: Use "fcn" as preferred abbreviation for "function" in m-files. * accumarray.m, accumdim.m, quadl.m, quadv.m, randi.m, structfun.m, __is_function__.m, uigetfile.m, uimenu.m, uiputfile.m, doc_cache_create.m, colorspace_conversion_input_check.m, imageIO.m, argnames.m, vectorize.m, vectorize.m, normest1.m, inputname.m, nthargout.m, display_info_file.m, decic.m, ode15i.m, ode15s.m, ode23.m, ode23s.m, ode45.m, odeset.m, check_default_input.m, integrate_adaptive.m, ode_event_handler.m, runge_kutta_23.m, runge_kutta_23s.m, runge_kutta_45_dorpri.m, runge_kutta_interpolate.m, starting_stepsize.m, __all_opts__.m, fminbnd.m, fminsearch.m, fminunc.m, fsolve.m, fzero.m, sqp.m, fplot.m, plotyy.m, __bar__.m, __ezplot__.m, flat_entry.html, profexport.m, movfun.m, bicg.m, bicgstab.m, cgs.m, eigs.m, gmres.m, pcg.m, __alltohandles__.m, __sprand__.m, qmr.m, tfqmr.m, dump_demos.m: Replace "func", "fun", "fn" in documentation and variable names with "fcn".
author Rik <rik@octave.org>
date Mon, 04 Apr 2022 18:14:56 -0700
parents 796f54d4ddbf
children 597f3ee61a48
comparison
equal deleted inserted replaced
30892:1a3cc2811090 30893:e1788b1a315f
532 %! d1 = eigs (A, speye (n)(q,q), k, 4.1, opts); 532 %! d1 = eigs (A, speye (n)(q,q), k, 4.1, opts);
533 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); 533 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11);
534 %!testif HAVE_ARPACK, HAVE_UMFPACK 534 %!testif HAVE_ARPACK, HAVE_UMFPACK
535 %! assert (eigs (A, k, 4.1), eigs (A, speye (n), k, 4.1), 1e-11); 535 %! assert (eigs (A, k, 4.1), eigs (A, speye (n), k, 4.1), 1e-11);
536 %!testif HAVE_ARPACK 536 %!testif HAVE_ARPACK
537 %! fn = @(x) A * x; 537 %! fcn = @(x) A * x;
538 %! opts.issym = 1; opts.isreal = 1; 538 %! opts.issym = 1; opts.isreal = 1;
539 %! d1 = eigs (fn, n, k, "lm", opts); 539 %! d1 = eigs (fcn, n, k, "lm", opts);
540 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); 540 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11);
541 %!testif HAVE_ARPACK 541 %!testif HAVE_ARPACK
542 %! fn = @(x) A \ x; 542 %! fcn = @(x) A \ x;
543 %! opts.issym = 1; opts.isreal = 1; 543 %! opts.issym = 1; opts.isreal = 1;
544 %! d1 = eigs (fn, n, k, "sm", opts); 544 %! d1 = eigs (fcn, n, k, "sm", opts);
545 %! assert (d1, d0(k:-1:1), 1e-11); 545 %! assert (d1, d0(k:-1:1), 1e-11);
546 %!testif HAVE_ARPACK, HAVE_UMFPACK 546 %!testif HAVE_ARPACK, HAVE_UMFPACK
547 %! fn = @(x) (A - 4.1 * eye (n)) \ x; 547 %! fcn = @(x) (A - 4.1 * eye (n)) \ x;
548 %! opts.issym = 1; opts.isreal = 1; 548 %! opts.issym = 1; opts.isreal = 1;
549 %! d1 = eigs (fn, n, k, 4.1, opts); 549 %! d1 = eigs (fcn, n, k, 4.1, opts);
550 %! assert (d1, eigs (A, k, 4.1), 1e-11); 550 %! assert (d1, eigs (A, k, 4.1), 1e-11);
551 %!testif HAVE_ARPACK, HAVE_UMFPACK, HAVE_CHOLMOD 551 %!testif HAVE_ARPACK, HAVE_UMFPACK, HAVE_CHOLMOD
552 %! AA = speye (10); 552 %! AA = speye (10);
553 %! fn = @(x) AA * x; 553 %! fcn = @(x) AA * x;
554 %! opts.issym = 1; opts.isreal = 1; 554 %! opts.issym = 1; opts.isreal = 1;
555 %! assert (eigs (fn, 10, AA, 3, "lm", opts), [1; 1; 1], 10*eps); 555 %! assert (eigs (fcn, 10, AA, 3, "lm", opts), [1; 1; 1], 10*eps);
556 %!testif HAVE_ARPACK 556 %!testif HAVE_ARPACK
557 %! [v1,d1] = eigs (A, k, "lm"); 557 %! [v1,d1] = eigs (A, k, "lm");
558 %! d1 = diag (d1); 558 %! d1 = diag (d1);
559 %! for i=1:k 559 %! for i=1:k
560 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11); 560 %! assert (max (abs ((A - d1(i)*speye (n))*v1(:,i))), 0, 1e-11);
660 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, speye (n), k, 4.1)), 1e-11); 660 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, speye (n), k, 4.1)), 1e-11);
661 %!testif HAVE_ARPACK, HAVE_UMFPACK 661 %!testif HAVE_ARPACK, HAVE_UMFPACK
662 %! assert (sort (imag (eigs (A, k, 4.1))), 662 %! assert (sort (imag (eigs (A, k, 4.1))),
663 %! sort (imag (eigs (A, speye (n), k, 4.1))), 1e-11); 663 %! sort (imag (eigs (A, speye (n), k, 4.1))), 1e-11);
664 %!testif HAVE_ARPACK 664 %!testif HAVE_ARPACK
665 %! fn = @(x) A * x; 665 %! fcn = @(x) A * x;
666 %! opts.issym = 0; opts.isreal = 1; 666 %! opts.issym = 0; opts.isreal = 1;
667 %! d1 = eigs (fn, n, k, "lm", opts); 667 %! d1 = eigs (fcn, n, k, "lm", opts);
668 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); 668 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11);
669 %!testif HAVE_ARPACK 669 %!testif HAVE_ARPACK
670 %! fn = @(x) A \ x; 670 %! fcn = @(x) A \ x;
671 %! opts.issym = 0; opts.isreal = 1; 671 %! opts.issym = 0; opts.isreal = 1;
672 %! d1 = eigs (fn, n, k, "sm", opts); 672 %! d1 = eigs (fcn, n, k, "sm", opts);
673 %! assert (abs (d1), d0(1:k), 1e-11); 673 %! assert (abs (d1), d0(1:k), 1e-11);
674 %!testif HAVE_ARPACK, HAVE_UMFPACK 674 %!testif HAVE_ARPACK, HAVE_UMFPACK
675 %! fn = @(x) (A - 4.1 * eye (n)) \ x; 675 %! fcn = @(x) (A - 4.1 * eye (n)) \ x;
676 %! opts.issym = 0; opts.isreal = 1; 676 %! opts.issym = 0; opts.isreal = 1;
677 %! d1 = eigs (fn, n, k, 4.1, opts); 677 %! d1 = eigs (fcn, n, k, 4.1, opts);
678 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); 678 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11);
679 %!testif HAVE_ARPACK 679 %!testif HAVE_ARPACK
680 %! [v1,d1] = eigs (A, k, "lm"); 680 %! [v1,d1] = eigs (A, k, "lm");
681 %! d1 = diag (d1); 681 %! d1 = diag (d1);
682 %! for i=1:k 682 %! for i=1:k
792 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, speye (n), k, 4.1)), 1e-11); 792 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, speye (n), k, 4.1)), 1e-11);
793 %!testif HAVE_ARPACK, HAVE_UMFPACK 793 %!testif HAVE_ARPACK, HAVE_UMFPACK
794 %! assert (sort (imag (eigs (A, k, 4.1))), 794 %! assert (sort (imag (eigs (A, k, 4.1))),
795 %! sort (imag (eigs (A, speye (n), k, 4.1))), 1e-11); 795 %! sort (imag (eigs (A, speye (n), k, 4.1))), 1e-11);
796 %!testif HAVE_ARPACK 796 %!testif HAVE_ARPACK
797 %! fn = @(x) A * x; 797 %! fcn = @(x) A * x;
798 %! opts.issym = 0; opts.isreal = 0; 798 %! opts.issym = 0; opts.isreal = 0;
799 %! d1 = eigs (fn, n, k, "lm", opts); 799 %! d1 = eigs (fcn, n, k, "lm", opts);
800 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); 800 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11);
801 %!testif HAVE_ARPACK 801 %!testif HAVE_ARPACK
802 %! fn = @(x) A \ x; 802 %! fcn = @(x) A \ x;
803 %! opts.issym = 0; opts.isreal = 0; 803 %! opts.issym = 0; opts.isreal = 0;
804 %! d1 = eigs (fn, n, k, "sm", opts); 804 %! d1 = eigs (fcn, n, k, "sm", opts);
805 %! assert (abs (d1), d0(1:k), 1e-11); 805 %! assert (abs (d1), d0(1:k), 1e-11);
806 %!testif HAVE_ARPACK, HAVE_UMFPACK 806 %!testif HAVE_ARPACK, HAVE_UMFPACK
807 %! fn = @(x) (A - 4.1 * eye (n)) \ x; 807 %! fcn = @(x) (A - 4.1 * eye (n)) \ x;
808 %! opts.issym = 0; opts.isreal = 0; 808 %! opts.issym = 0; opts.isreal = 0;
809 %! d1 = eigs (fn, n, k, 4.1, opts); 809 %! d1 = eigs (fcn, n, k, 4.1, opts);
810 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); 810 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11);
811 %!testif HAVE_ARPACK 811 %!testif HAVE_ARPACK
812 %! [v1,d1] = eigs (A, k, "lm"); 812 %! [v1,d1] = eigs (A, k, "lm");
813 %! d1 = diag (d1); 813 %! d1 = diag (d1);
814 %! for i=1:k 814 %! for i=1:k
1031 %! d1 = eigs (A, eye (n)(q,q), k, 4.1, opts); 1031 %! d1 = eigs (A, eye (n)(q,q), k, 4.1, opts);
1032 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); 1032 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11);
1033 %!testif HAVE_ARPACK 1033 %!testif HAVE_ARPACK
1034 %! assert (eigs (A, k, 4.1), eigs (A, eye (n), k, 4.1), 1e-11); 1034 %! assert (eigs (A, k, 4.1), eigs (A, eye (n), k, 4.1), 1e-11);
1035 %!testif HAVE_ARPACK 1035 %!testif HAVE_ARPACK
1036 %! fn = @(x) A * x; 1036 %! fcn = @(x) A * x;
1037 %! opts.issym = 1; opts.isreal = 1; 1037 %! opts.issym = 1; opts.isreal = 1;
1038 %! d1 = eigs (fn, n, k, "lm", opts); 1038 %! d1 = eigs (fcn, n, k, "lm", opts);
1039 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11); 1039 %! assert (d1, d0(end:-1:(end-k+1)), 1e-11);
1040 %!testif HAVE_ARPACK 1040 %!testif HAVE_ARPACK
1041 %! fn = @(x) A \ x; 1041 %! fcn = @(x) A \ x;
1042 %! opts.issym = 1; opts.isreal = 1; 1042 %! opts.issym = 1; opts.isreal = 1;
1043 %! d1 = eigs (fn, n, k, "sm", opts); 1043 %! d1 = eigs (fcn, n, k, "sm", opts);
1044 %! assert (d1, d0(k:-1:1), 1e-11); 1044 %! assert (d1, d0(k:-1:1), 1e-11);
1045 %!testif HAVE_ARPACK 1045 %!testif HAVE_ARPACK
1046 %! fn = @(x) (A - 4.1 * eye (n)) \ x; 1046 %! fcn = @(x) (A - 4.1 * eye (n)) \ x;
1047 %! opts.issym = 1; opts.isreal = 1; 1047 %! opts.issym = 1; opts.isreal = 1;
1048 %! d1 = eigs (fn, n, k, 4.1, opts); 1048 %! d1 = eigs (fcn, n, k, 4.1, opts);
1049 %! assert (d1, eigs (A, k, 4.1), 1e-11); 1049 %! assert (d1, eigs (A, k, 4.1), 1e-11);
1050 %!testif HAVE_ARPACK 1050 %!testif HAVE_ARPACK
1051 %! [v1,d1] = eigs (A, k, "lm"); 1051 %! [v1,d1] = eigs (A, k, "lm");
1052 %! d1 = diag (d1); 1052 %! d1 = diag (d1);
1053 %! for i=1:k 1053 %! for i=1:k
1154 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, eye (n), k, 4.1)), 1e-11); 1154 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, eye (n), k, 4.1)), 1e-11);
1155 %!testif HAVE_ARPACK 1155 %!testif HAVE_ARPACK
1156 %! assert (sort (imag (eigs (A, k, 4.1))), 1156 %! assert (sort (imag (eigs (A, k, 4.1))),
1157 %! sort (imag (eigs (A, eye (n), k, 4.1))), 1e-11); 1157 %! sort (imag (eigs (A, eye (n), k, 4.1))), 1e-11);
1158 %!testif HAVE_ARPACK 1158 %!testif HAVE_ARPACK
1159 %! fn = @(x) A * x; 1159 %! fcn = @(x) A * x;
1160 %! opts.issym = 0; opts.isreal = 1; 1160 %! opts.issym = 0; opts.isreal = 1;
1161 %! d1 = eigs (fn, n, k, "lm", opts); 1161 %! d1 = eigs (fcn, n, k, "lm", opts);
1162 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); 1162 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11);
1163 %!testif HAVE_ARPACK 1163 %!testif HAVE_ARPACK
1164 %! fn = @(x) A \ x; 1164 %! fcn = @(x) A \ x;
1165 %! opts.issym = 0; opts.isreal = 1; 1165 %! opts.issym = 0; opts.isreal = 1;
1166 %! d1 = eigs (fn, n, k, "sm", opts); 1166 %! d1 = eigs (fcn, n, k, "sm", opts);
1167 %! assert (abs (d1), d0(1:k), 1e-11); 1167 %! assert (abs (d1), d0(1:k), 1e-11);
1168 %!testif HAVE_ARPACK 1168 %!testif HAVE_ARPACK
1169 %! fn = @(x) (A - 4.1 * eye (n)) \ x; 1169 %! fcn = @(x) (A - 4.1 * eye (n)) \ x;
1170 %! opts.issym = 0; opts.isreal = 1; 1170 %! opts.issym = 0; opts.isreal = 1;
1171 %! d1 = eigs (fn, n, k, 4.1, opts); 1171 %! d1 = eigs (fcn, n, k, 4.1, opts);
1172 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); 1172 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11);
1173 %!testif HAVE_ARPACK 1173 %!testif HAVE_ARPACK
1174 %! [v1,d1] = eigs (A, k, "lm"); 1174 %! [v1,d1] = eigs (A, k, "lm");
1175 %! d1 = diag (d1); 1175 %! d1 = diag (d1);
1176 %! for i=1:k 1176 %! for i=1:k
1285 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, eye (n), k, 4.1)), 1e-11); 1285 %! assert (abs (eigs (A, k, 4.1)), abs (eigs (A, eye (n), k, 4.1)), 1e-11);
1286 %!testif HAVE_ARPACK 1286 %!testif HAVE_ARPACK
1287 %! assert (sort (imag (eigs (A, k, 4.1))), 1287 %! assert (sort (imag (eigs (A, k, 4.1))),
1288 %! sort (imag (eigs (A, eye (n), k, 4.1))), 1e-11); 1288 %! sort (imag (eigs (A, eye (n), k, 4.1))), 1e-11);
1289 %!testif HAVE_ARPACK 1289 %!testif HAVE_ARPACK
1290 %! fn = @(x) A * x; 1290 %! fcn = @(x) A * x;
1291 %! opts.issym = 0; opts.isreal = 0; 1291 %! opts.issym = 0; opts.isreal = 0;
1292 %! d1 = eigs (fn, n, k, "lm", opts); 1292 %! d1 = eigs (fcn, n, k, "lm", opts);
1293 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11); 1293 %! assert (abs (d1), abs (d0(end:-1:(end-k+1))), 1e-11);
1294 %!testif HAVE_ARPACK 1294 %!testif HAVE_ARPACK
1295 %! fn = @(x) A \ x; 1295 %! fcn = @(x) A \ x;
1296 %! opts.issym = 0; opts.isreal = 0; 1296 %! opts.issym = 0; opts.isreal = 0;
1297 %! d1 = eigs (fn, n, k, "sm", opts); 1297 %! d1 = eigs (fcn, n, k, "sm", opts);
1298 %! assert (abs (d1), d0(1:k), 1e-11); 1298 %! assert (abs (d1), d0(1:k), 1e-11);
1299 %!testif HAVE_ARPACK 1299 %!testif HAVE_ARPACK
1300 %! fn = @(x) (A - 4.1 * eye (n)) \ x; 1300 %! fcn = @(x) (A - 4.1 * eye (n)) \ x;
1301 %! opts.issym = 0; opts.isreal = 0; 1301 %! opts.issym = 0; opts.isreal = 0;
1302 %! d1 = eigs (fn, n, k, 4.1, opts); 1302 %! d1 = eigs (fcn, n, k, 4.1, opts);
1303 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11); 1303 %! assert (abs (d1), eigs (A, k, 4.1), 1e-11);
1304 %!testif HAVE_ARPACK 1304 %!testif HAVE_ARPACK
1305 %! [v1,d1] = eigs (A, k, "lm"); 1305 %! [v1,d1] = eigs (A, k, "lm");
1306 %! d1 = diag (d1); 1306 %! d1 = diag (d1);
1307 %! for i=1:k 1307 %! for i=1:k
1450 %! d = eigs (A, 4, "sm", opts); 1450 %! d = eigs (A, 4, "sm", opts);
1451 %! assert (d(4), NaN); 1451 %! assert (d(4), NaN);
1452 %!testif HAVE_ARPACK 1452 %!testif HAVE_ARPACK
1453 %! A = toeplitz ([-2, 1, zeros(1, 8)]); 1453 %! A = toeplitz ([-2, 1, zeros(1, 8)]);
1454 %! A = kron (A, eye (10)) + kron (eye (10), A); 1454 %! A = kron (A, eye (10)) + kron (eye (10), A);
1455 %! Afun = @(x) A * x; 1455 %! Afcn = @(x) A * x;
1456 %! opts.v0 = (1:100)'; 1456 %! opts.v0 = (1:100)';
1457 %! opts.maxit = 3; 1457 %! opts.maxit = 3;
1458 %! opts.issym = true; 1458 %! opts.issym = true;
1459 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local"); 1459 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local");
1460 %! d = eigs (Afun, 100, 4, "sm", opts); 1460 %! d = eigs (Afcn, 100, 4, "sm", opts);
1461 %! assert (d(3:4), [NaN; NaN]); 1461 %! assert (d(3:4), [NaN; NaN]);
1462 %!testif HAVE_ARPACK 1462 %!testif HAVE_ARPACK
1463 %! A = toeplitz ([-2, 1, zeros(1, 8)]); 1463 %! A = toeplitz ([-2, 1, zeros(1, 8)]);
1464 %! A = kron (A, eye (10)) + kron (eye (10), A); 1464 %! A = kron (A, eye (10)) + kron (eye (10), A);
1465 %! A(1, 2) = 10; 1465 %! A(1, 2) = 10;
1508 %! assert (d(10), NaN +1i*NaN); 1508 %! assert (d(10), NaN +1i*NaN);
1509 %! endif 1509 %! endif
1510 %!testif HAVE_ARPACK 1510 %!testif HAVE_ARPACK
1511 %! A = toeplitz ([0, 1, zeros(1, 8)], [0, -1, zeros(1, 8)]); 1511 %! A = toeplitz ([0, 1, zeros(1, 8)], [0, -1, zeros(1, 8)]);
1512 %! A = kron (A, eye (10)) + kron (eye (10), A); 1512 %! A = kron (A, eye (10)) + kron (eye (10), A);
1513 %! Afun = @(x) A * x; 1513 %! Afcn = @(x) A * x;
1514 %! opts.v0 = (1:100)'; 1514 %! opts.v0 = (1:100)';
1515 %! opts.maxit = 4; 1515 %! opts.maxit = 4;
1516 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local"); 1516 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local");
1517 %! d = eigs (Afun, 100, 4, "lm", opts); 1517 %! d = eigs (Afcn, 100, 4, "lm", opts);
1518 %! assert (d(3:4), [NaN+1i*NaN; NaN+1i*NaN]); 1518 %! assert (d(3:4), [NaN+1i*NaN; NaN+1i*NaN]);
1519 %!testif HAVE_ARPACK 1519 %!testif HAVE_ARPACK
1520 %! A = 1i * magic (100); 1520 %! A = 1i * magic (100);
1521 %! opts.v0 = (1:100)'; 1521 %! opts.v0 = (1:100)';
1522 %! opts.maxit = 1; 1522 %! opts.maxit = 1;
1530 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local"); 1530 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local");
1531 %! d = eigs (A, 10, "sm", opts); 1531 %! d = eigs (A, 10, "sm", opts);
1532 %! assert (d(9:10), [NaN+1i*NaN; NaN+1i*NaN]); 1532 %! assert (d(9:10), [NaN+1i*NaN; NaN+1i*NaN]);
1533 %!testif HAVE_ARPACK 1533 %!testif HAVE_ARPACK
1534 %! A = 1i * magic (100); 1534 %! A = 1i * magic (100);
1535 %! Afun = @(x) A * x; 1535 %! Afcn = @(x) A * x;
1536 %! opts.v0 = (1:100)'; 1536 %! opts.v0 = (1:100)';
1537 %! opts.maxit = 1; 1537 %! opts.maxit = 1;
1538 %! opts.isreal = false; 1538 %! opts.isreal = false;
1539 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local"); 1539 %! warning ("off", "Octave:eigs:UnconvergedEigenvalues", "local");
1540 %! d = eigs (Afun, 100, 6, "lm", opts); 1540 %! d = eigs (Afcn, 100, 6, "lm", opts);
1541 %! assert (d(6), NaN+1i*NaN); 1541 %! assert (d(6), NaN+1i*NaN);
1542 %!testif HAVE_ARPACK, HAVE_CHOLMOD 1542 %!testif HAVE_ARPACK, HAVE_CHOLMOD
1543 %! A = sparse (magic (10)); 1543 %! A = sparse (magic (10));
1544 %! B = sparse (magic (10)); # not HPD 1544 %! B = sparse (magic (10)); # not HPD
1545 %! fail ("eigs (A, B, 4)", "eigs: The matrix B is not positive definite") 1545 %! fail ("eigs (A, B, 4)", "eigs: The matrix B is not positive definite")
1565 %! A = sin (M); 1565 %! A = sin (M);
1566 %! B = cos (M); 1566 %! B = cos (M);
1567 %! B = B * B'; 1567 %! B = B * B';
1568 %! opts.v0 = (1:10)'; 1568 %! opts.v0 = (1:10)';
1569 %! [Evector, Evalues] = eigs (A, B, 4, "LM", opts); 1569 %! [Evector, Evalues] = eigs (A, B, 4, "LM", opts);
1570 %! Afun = @(x) A * x; 1570 %! Afcn = @(x) A * x;
1571 %! [Evector_f Evalues_f] = eigs (Afun, 10, B, 4, "LM", opts); 1571 %! [Evector_f Evalues_f] = eigs (Afcn, 10, B, 4, "LM", opts);
1572 %! assert (Evector, Evector_f); 1572 %! assert (Evector, Evector_f);
1573 %! assert (Evalues, Evalues_f); 1573 %! assert (Evalues, Evalues_f);
1574 %!testif HAVE_ARPACK 1574 %!testif HAVE_ARPACK
1575 %! M = magic (10); 1575 %! M = magic (10);
1576 %! A = sin (M); 1576 %! A = sin (M);
1577 %! B = cos (M); 1577 %! B = cos (M);
1578 %! B = B * B'; 1578 %! B = B * B';
1579 %! opts.v0 = (1:10)'; 1579 %! opts.v0 = (1:10)';
1580 %! [Evector, Evalues] = eigs (A, B, 4, "SM", opts); 1580 %! [Evector, Evalues] = eigs (A, B, 4, "SM", opts);
1581 %! [L, U, P] = lu (A); 1581 %! [L, U, P] = lu (A);
1582 %! Afun = @(x) U \ (L \ (P * x)); 1582 %! Afcn = @(x) U \ (L \ (P * x));
1583 %! [Evector_f Evalues_f] = eigs (Afun, 10, B, 4, "SM", opts); 1583 %! [Evector_f Evalues_f] = eigs (Afcn, 10, B, 4, "SM", opts);
1584 %! assert (Evector, Evector_f); 1584 %! assert (Evector, Evector_f);
1585 %! assert (Evalues, Evalues_f); 1585 %! assert (Evalues, Evalues_f);
1586 %!testif HAVE_ARPACK 1586 %!testif HAVE_ARPACK
1587 %! M = magic (10); 1587 %! M = magic (10);
1588 %! A = sin (M); 1588 %! A = sin (M);
1589 %! A = A * A'; 1589 %! A = A * A';
1590 %! B = cos (M); 1590 %! B = cos (M);
1591 %! B = B * B'; 1591 %! B = B * B';
1592 %! opts.v0 = (1:10)'; 1592 %! opts.v0 = (1:10)';
1593 %! [Evector, Evalues] = eigs (A, B, 4, "LM", opts); 1593 %! [Evector, Evalues] = eigs (A, B, 4, "LM", opts);
1594 %! Afun = @(x) A * x; 1594 %! Afcn = @(x) A * x;
1595 %! opts.issym = true; 1595 %! opts.issym = true;
1596 %! [Evector_f Evalues_f] = eigs (Afun, 10, B, 4, "LM", opts); 1596 %! [Evector_f Evalues_f] = eigs (Afcn, 10, B, 4, "LM", opts);
1597 %! assert (Evector, Evector_f); 1597 %! assert (Evector, Evector_f);
1598 %! assert (Evalues, Evalues_f); 1598 %! assert (Evalues, Evalues_f);
1599 %!testif HAVE_ARPACK 1599 %!testif HAVE_ARPACK
1600 %! M = magic (10); 1600 %! M = magic (10);
1601 %! A = sin (M); 1601 %! A = sin (M);
1603 %! B = cos (M); 1603 %! B = cos (M);
1604 %! B = B * B'; 1604 %! B = B * B';
1605 %! opts.v0 = (1:10)'; 1605 %! opts.v0 = (1:10)';
1606 %! [Evector, Evalues] = eigs (A, B, 4, "SM", opts); 1606 %! [Evector, Evalues] = eigs (A, B, 4, "SM", opts);
1607 %! [L, U, P] = lu (A); 1607 %! [L, U, P] = lu (A);
1608 %! Afun = @(x) U \ (L \ (P * x)); 1608 %! Afcn = @(x) U \ (L \ (P * x));
1609 %! opts.issym = true; 1609 %! opts.issym = true;
1610 %! [Evector_f Evalues_f] = eigs (Afun, 10, B, 4, "SM", opts); 1610 %! [Evector_f Evalues_f] = eigs (Afcn, 10, B, 4, "SM", opts);
1611 %! assert (Evector, Evector_f); 1611 %! assert (Evector, Evector_f);
1612 %! assert (Evalues, Evalues_f); 1612 %! assert (Evalues, Evalues_f);
1613 %!testif HAVE_ARPACK 1613 %!testif HAVE_ARPACK
1614 %! M = magic (10); 1614 %! M = magic (10);
1615 %! A = sin (M) + 1i * cos (M); 1615 %! A = sin (M) + 1i * cos (M);
1616 %! B = cos (M) + 1i * sin (M); 1616 %! B = cos (M) + 1i * sin (M);
1617 %! B = B * B'; 1617 %! B = B * B';
1618 %! opts.v0 = (1:10)'; 1618 %! opts.v0 = (1:10)';
1619 %! [Evector, Evalues] = eigs (A, B, 4, "LM", opts); 1619 %! [Evector, Evalues] = eigs (A, B, 4, "LM", opts);
1620 %! Afun = @(x) A * x; 1620 %! Afcn = @(x) A * x;
1621 %! opts.isreal = false; 1621 %! opts.isreal = false;
1622 %! [Evector_f Evalues_f] = eigs (Afun, 10, B, 4, "LM", opts); 1622 %! [Evector_f Evalues_f] = eigs (Afcn, 10, B, 4, "LM", opts);
1623 %! assert (Evector, Evector_f); 1623 %! assert (Evector, Evector_f);
1624 %! assert (Evalues, Evalues_f); 1624 %! assert (Evalues, Evalues_f);
1625 %!testif HAVE_ARPACK 1625 %!testif HAVE_ARPACK
1626 %! M = magic (10); 1626 %! M = magic (10);
1627 %! A = sin (M) + 1i * cos (M); 1627 %! A = sin (M) + 1i * cos (M);
1628 %! B = cos (M) + 1i * sin (M); 1628 %! B = cos (M) + 1i * sin (M);
1629 %! B = B * B'; 1629 %! B = B * B';
1630 %! opts.v0 = (1:10)'; 1630 %! opts.v0 = (1:10)';
1631 %! [Evector, Evalues] = eigs (A, B, 4, "SM", opts); 1631 %! [Evector, Evalues] = eigs (A, B, 4, "SM", opts);
1632 %! [L, U, P] = lu (A); 1632 %! [L, U, P] = lu (A);
1633 %! Afun = @(x) U \ (L \ (P *x)); 1633 %! Afcn = @(x) U \ (L \ (P *x));
1634 %! opts.isreal = false; 1634 %! opts.isreal = false;
1635 %! [Evector_f, Evalues_f] = eigs (Afun, 10, B, 4, "SM", opts); 1635 %! [Evector_f, Evalues_f] = eigs (Afcn, 10, B, 4, "SM", opts);
1636 %! assert (Evector, Evector_f); 1636 %! assert (Evector, Evector_f);
1637 %! assert (Evalues, Evalues_f); 1637 %! assert (Evalues, Evalues_f);
1638 1638
1639 %!testif HAVE_ARPACK <*57196> 1639 %!testif HAVE_ARPACK <*57196>
1640 %! x = ones (10, 10); 1640 %! x = ones (10, 10);