– | the corresponding approximate eigenvectors; |
– | an orthonormal basis for the associated approximate invariant subspace; |
– | both. |
None.
Open in the MATLAB editor: nag_sparseig_real_symm_proc_example
function nag_sparseig_real_symm_proc_example n = int64(100); nx = int64(10); nev = int64(4); ncv = int64(10); irevcm = int64(0); resid = zeros(100,1); v = zeros(100,20); x = zeros(100,1); mx = zeros(100,1); sigma = 0; % Initialisation Step [icomm, comm, ifail] = nag_sparseig_real_symm_init(n, nev, ncv); % Set Optional Parameters [icomm, comm, ifail] = nag_sparseig_real_symm_option('SMALLEST MAGNITUDE', icomm, comm); % Solve while (irevcm ~= 5) [irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ... nag_sparseig_real_symm_iter(irevcm, resid, v, x, mx, comm, icomm); if (irevcm == 1 || irevcm == -1) x = f12f_av(nx, x); elseif (irevcm == 4) [niter, nconv, ritz, rzest] = nag_sparseig_real_symm_monit(icomm, comm); fprintf('Iteration %d, No. converged = %d, norm of estimates = %16.8g\n', ... niter, nconv, norm(rzest(1:double(nev)),2)); end end % Post-process to compute eigenvalues/vectors [nconv, d, z, v, comm, icomm, ifail] = ... nag_sparseig_real_symm_proc(sigma, resid, v, comm, icomm); nconv, d(1:double(nconv)), ifail function [w] = f12f_av(nx, v) inx = double(nx); % nx is int64 w = zeros(inx*inx,1); h2 = 1/double((inx+1)^2); w(1:inx) = tv(inx, v(1:inx)); w(1:inx) = -v(inx+1:2*inx)+w(1:inx); for j=2:double(inx-1) lo = (j-1)*inx +1; hi = j*inx; w(lo:hi) = tv(inx, v(lo:hi)); w(lo:hi) = -v(lo-inx:lo-1)+w(lo:hi); w(lo:hi) = -v(hi+1:hi+inx)+w(lo:hi); end lo = (inx-1)*inx +1; hi = inx*inx; w(lo:hi) = tv(inx, v(lo:hi)); w(lo:hi) = -v(lo-inx:lo-1)+w(lo:hi); w = w/h2; function [y] = tv(inx,x) y = zeros(inx,1); dd = 4; dl = -1; du = -1; y(1) = dd*x(1) + du*x(2); for j=2:double(inx-1) y(j) = dl*x(j-1) + dd*x(j) + du*x(j+1); end y(inx) = dl*x(inx-1) + dd*x(inx);
Iteration 1, No. converged = 0, norm of estimates = 81.010211 Iteration 2, No. converged = 0, norm of estimates = 45.634095 Iteration 3, No. converged = 0, norm of estimates = 42.747772 Iteration 4, No. converged = 0, norm of estimates = 8.6106757 Iteration 5, No. converged = 0, norm of estimates = 0.71330195 Iteration 6, No. converged = 0, norm of estimates = 0.15050738 Iteration 7, No. converged = 0, norm of estimates = 0.015776765 Iteration 8, No. converged = 0, norm of estimates = 0.0038996544 Iteration 9, No. converged = 0, norm of estimates = 0.0004324447 Iteration 10, No. converged = 0, norm of estimates = 0.00011026365 Iteration 11, No. converged = 0, norm of estimates = 1.2358564e-05 Iteration 12, No. converged = 0, norm of estimates = 3.1712519e-06 Iteration 13, No. converged = 1, norm of estimates = 3.5636599e-07 Iteration 14, No. converged = 1, norm of estimates = 4.2416167e-08 Iteration 15, No. converged = 1, norm of estimates = 1.3069836e-08 Iteration 16, No. converged = 1, norm of estimates = 5.5204749e-10 Iteration 17, No. converged = 1, norm of estimates = 8.0102311e-11 Iteration 18, No. converged = 1, norm of estimates = 1.9788954e-10 Iteration 19, No. converged = 2, norm of estimates = 3.1175144e-09 Iteration 20, No. converged = 2, norm of estimates = 3.0499643e-08 Iteration 21, No. converged = 2, norm of estimates = 2.2545794e-08 Iteration 22, No. converged = 2, norm of estimates = 3.8803659e-09 Iteration 23, No. converged = 2, norm of estimates = 4.3299036e-10 Iteration 24, No. converged = 2, norm of estimates = 1.9559537e-10 Iteration 25, No. converged = 2, norm of estimates = 1.3956205e-12 Iteration 26, No. converged = 2, norm of estimates = 6.7447903e-13 Iteration 27, No. converged = 2, norm of estimates = 6.4140406e-14 Iteration 28, No. converged = 2, norm of estimates = 8.9020339e-15 Iteration 29, No. converged = 3, norm of estimates = 3.8266142e-15 Iteration 30, No. converged = 3, norm of estimates = 1.3296741e-16 nconv = 4 ans = 19.6054 48.2193 48.2193 76.8333 ifail = 0
Open in the MATLAB editor: f12fc_example
function f12fc_example n = int64(100); nx = int64(10); nev = int64(4); ncv = int64(10); irevcm = int64(0); resid = zeros(100,1); v = zeros(100,20); x = zeros(100,1); mx = zeros(100,1); sigma = 0; % Initialisation Step [icomm, comm, ifail] = f12fa(n, nev, ncv); % Set Optional Parameters [icomm, comm, ifail] = f12fd('SMALLEST MAGNITUDE', icomm, comm); % Solve while (irevcm ~= 5) [irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ... f12fb(irevcm, resid, v, x, mx, comm, icomm); if (irevcm == 1 || irevcm == -1) x = f12f_av(nx, x); elseif (irevcm == 4) [niter, nconv, ritz, rzest] = f12fe(icomm, comm); fprintf('Iteration %d, No. converged = %d, norm of estimates = %16.8g\n', ... niter, nconv, norm(rzest(1:double(nev)),2)); end end % Post-process to compute eigenvalues/vectors [nconv, d, z, v, comm, icomm, ifail] = f12fc(sigma, resid, v, comm, icomm); nconv, d(1:double(nconv)), ifail function [w] = f12f_av(nx, v) inx = double(nx); % nx is int64 w = zeros(inx*inx,1); h2 = 1/double((inx+1)^2); w(1:inx) = tv(inx, v(1:inx)); w(1:inx) = -v(inx+1:2*inx)+w(1:inx); for j=2:double(inx-1) lo = (j-1)*inx +1; hi = j*inx; w(lo:hi) = tv(inx, v(lo:hi)); w(lo:hi) = -v(lo-inx:lo-1)+w(lo:hi); w(lo:hi) = -v(hi+1:hi+inx)+w(lo:hi); end lo = (inx-1)*inx +1; hi = inx*inx; w(lo:hi) = tv(inx, v(lo:hi)); w(lo:hi) = -v(lo-inx:lo-1)+w(lo:hi); w = w/h2; function [y] = tv(inx,x) y = zeros(inx,1); dd = 4; dl = -1; du = -1; y(1) = dd*x(1) + du*x(2); for j=2:double(inx-1) y(j) = dl*x(j-1) + dd*x(j) + du*x(j+1); end y(inx) = dl*x(inx-1) + dd*x(inx);
Iteration 1, No. converged = 0, norm of estimates = 81.010211 Iteration 2, No. converged = 0, norm of estimates = 45.634095 Iteration 3, No. converged = 0, norm of estimates = 42.747772 Iteration 4, No. converged = 0, norm of estimates = 8.6106757 Iteration 5, No. converged = 0, norm of estimates = 0.71330195 Iteration 6, No. converged = 0, norm of estimates = 0.15050738 Iteration 7, No. converged = 0, norm of estimates = 0.015776765 Iteration 8, No. converged = 0, norm of estimates = 0.0038996544 Iteration 9, No. converged = 0, norm of estimates = 0.0004324447 Iteration 10, No. converged = 0, norm of estimates = 0.00011026365 Iteration 11, No. converged = 0, norm of estimates = 1.2358564e-05 Iteration 12, No. converged = 0, norm of estimates = 3.1712519e-06 Iteration 13, No. converged = 1, norm of estimates = 3.5636599e-07 Iteration 14, No. converged = 1, norm of estimates = 4.2416167e-08 Iteration 15, No. converged = 1, norm of estimates = 1.3069836e-08 Iteration 16, No. converged = 1, norm of estimates = 5.5204749e-10 Iteration 17, No. converged = 1, norm of estimates = 8.0102311e-11 Iteration 18, No. converged = 1, norm of estimates = 1.9788954e-10 Iteration 19, No. converged = 2, norm of estimates = 3.1175144e-09 Iteration 20, No. converged = 2, norm of estimates = 3.0499643e-08 Iteration 21, No. converged = 2, norm of estimates = 2.2545794e-08 Iteration 22, No. converged = 2, norm of estimates = 3.8803659e-09 Iteration 23, No. converged = 2, norm of estimates = 4.3299036e-10 Iteration 24, No. converged = 2, norm of estimates = 1.9559537e-10 Iteration 25, No. converged = 2, norm of estimates = 1.3956205e-12 Iteration 26, No. converged = 2, norm of estimates = 6.7447903e-13 Iteration 27, No. converged = 2, norm of estimates = 6.4140406e-14 Iteration 28, No. converged = 2, norm of estimates = 8.9020339e-15 Iteration 29, No. converged = 3, norm of estimates = 3.8266142e-15 Iteration 30, No. converged = 3, norm of estimates = 1.3296741e-16 nconv = 4 ans = 19.6054 48.2193 48.2193 76.8333 ifail = 0