– | the corresponding approximate eigenvectors; |
– | an orthonormal basis for the associated approximate invariant subspace; |
– | both. |
None.
Open in the MATLAB editor: nag_sparseig_complex_proc_example
function nag_sparseig_complex_proc_example n = int64(100); nx = int64(10); nev = int64(4); ncv = int64(20); irevcm = int64(0); resid = complex(zeros(100,1)); v = complex(zeros(100,20)); x = complex(zeros(100,1)); mx = complex(zeros(100,1)); sigma = complex(0); % Initialisation Step [icomm, comm, ifail] = nag_sparseig_complex_init(n, nev, ncv); % Solve while (irevcm ~= 5) [irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ... nag_sparseig_complex_iter(irevcm, resid, v, x, mx, comm, icomm); if (irevcm == 1 || irevcm == -1) x = f12_av(nx, x); elseif (irevcm == 4) [niter, nconv, ritz, rzest] = nag_sparseig_complex_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_complex_proc(sigma, resid, v, comm, icomm); % sort to avoid difference in order showing as an error function [w] = f12_av(nx, v) inx = double(nx); % nx is int64 w = complex(zeros(inx*inx,1)); h2 = double(-(inx+1)^2); w(1:inx) = tv(inx, v(1:inx)); w(1:inx) = h2*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) = h2*v(lo-inx:lo-1)+w(lo:hi); w(lo:hi) = h2*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) = h2*v(lo-inx:lo-1)+w(lo:hi); function [y] = tv(inx,x) y = zeros(inx,1); dd = double(4*(inx+1)^2); dl = double(-(inx+1)^2 - 0.5*100*(inx+1)); du = double(-(inx+1)^2 + 0.5*100*(inx+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 = 133.43269 Iteration 2, No. converged = 0, norm of estimates = 99.725711 Iteration 3, No. converged = 0, norm of estimates = 42.48146 Iteration 4, No. converged = 0, norm of estimates = 8.1805323 Iteration 5, No. converged = 0, norm of estimates = 1.7794793 Iteration 6, No. converged = 0, norm of estimates = 0.49794897 Iteration 7, No. converged = 0, norm of estimates = 0.12604717 Iteration 8, No. converged = 0, norm of estimates = 0.026883649 Iteration 9, No. converged = 0, norm of estimates = 0.0070182429 Iteration 10, No. converged = 0, norm of estimates = 0.0014438635 Iteration 11, No. converged = 0, norm of estimates = 0.00040007427 Iteration 12, No. converged = 0, norm of estimates = 0.0001059392 Iteration 13, No. converged = 0, norm of estimates = 2.803229e-05 Iteration 14, No. converged = 0, norm of estimates = 7.7343157e-06 Iteration 15, No. converged = 0, norm of estimates = 1.9579037e-06 Iteration 16, No. converged = 0, norm of estimates = 6.15616e-07 Iteration 17, No. converged = 0, norm of estimates = 1.2591405e-07 Iteration 18, No. converged = 0, norm of estimates = 3.7790713e-08 Iteration 19, No. converged = 2, norm of estimates = 8.3787181e-09 Iteration 20, No. converged = 2, norm of estimates = 1.8827432e-09 Iteration 21, No. converged = 2, norm of estimates = 1.6920778e-10 Iteration 22, No. converged = 2, norm of estimates = 2.299125e-11 Iteration 23, No. converged = 2, norm of estimates = 3.391976e-12 Iteration 24, No. converged = 2, norm of estimates = 5.5954988e-13
Open in the MATLAB editor: f12aq_example
function f12aq_example n = int64(100); nx = int64(10); nev = int64(4); ncv = int64(20); irevcm = int64(0); resid = complex(zeros(100,1)); v = complex(zeros(100,20)); x = complex(zeros(100,1)); mx = complex(zeros(100,1)); sigma = complex(0); % Initialisation Step [icomm, comm, ifail] = f12an(n, nev, ncv); % Solve while (irevcm ~= 5) [irevcm, resid, v, x, mx, nshift, comm, icomm, ifail] = ... f12ap(irevcm, resid, v, x, mx, comm, icomm); if (irevcm == 1 || irevcm == -1) x = f12_av(nx, x); elseif (irevcm == 4) [niter, nconv, ritz, rzest] = f12as(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] = f12aq(sigma, resid, v, comm, icomm); % sort to avoid difference in order showing as an error function [w] = f12_av(nx, v) inx = double(nx); % nx is int64 w = complex(zeros(inx*inx,1)); h2 = double(-(inx+1)^2); w(1:inx) = tv(inx, v(1:inx)); w(1:inx) = h2*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) = h2*v(lo-inx:lo-1)+w(lo:hi); w(lo:hi) = h2*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) = h2*v(lo-inx:lo-1)+w(lo:hi); function [y] = tv(inx,x) y = zeros(inx,1); dd = double(4*(inx+1)^2); dl = double(-(inx+1)^2 - 0.5*100*(inx+1)); du = double(-(inx+1)^2 + 0.5*100*(inx+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 = 133.43269 Iteration 2, No. converged = 0, norm of estimates = 99.725711 Iteration 3, No. converged = 0, norm of estimates = 42.48146 Iteration 4, No. converged = 0, norm of estimates = 8.1805323 Iteration 5, No. converged = 0, norm of estimates = 1.7794793 Iteration 6, No. converged = 0, norm of estimates = 0.49794897 Iteration 7, No. converged = 0, norm of estimates = 0.12604717 Iteration 8, No. converged = 0, norm of estimates = 0.026883649 Iteration 9, No. converged = 0, norm of estimates = 0.0070182429 Iteration 10, No. converged = 0, norm of estimates = 0.0014438635 Iteration 11, No. converged = 0, norm of estimates = 0.00040007427 Iteration 12, No. converged = 0, norm of estimates = 0.0001059392 Iteration 13, No. converged = 0, norm of estimates = 2.803229e-05 Iteration 14, No. converged = 0, norm of estimates = 7.7343157e-06 Iteration 15, No. converged = 0, norm of estimates = 1.9579037e-06 Iteration 16, No. converged = 0, norm of estimates = 6.15616e-07 Iteration 17, No. converged = 0, norm of estimates = 1.2591405e-07 Iteration 18, No. converged = 0, norm of estimates = 3.7790713e-08 Iteration 19, No. converged = 2, norm of estimates = 8.3787181e-09 Iteration 20, No. converged = 2, norm of estimates = 1.8827432e-09 Iteration 21, No. converged = 2, norm of estimates = 1.6920778e-10 Iteration 22, No. converged = 2, norm of estimates = 2.299125e-11 Iteration 23, No. converged = 2, norm of estimates = 3.391976e-12 Iteration 24, No. converged = 2, norm of estimates = 5.5954988e-13