%function exercise_1_6_6() % % Written by: % -- % John L. Weatherwax 2006-12-30 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- close all; nprime = 20; mprime = 15; A = gallery( 'wathen', nprime, mprime ); issparse(A) size(A) fprintf( 'The size of wathen(%d,%d), = (%d,%d)\n', nprime, mprime, size(A,1), size(A,2) ); fprintf( 'Number of non zeros of the matrix wathen = %d (=%f percent)\n', nnz(A), nnz(A)/prod(size(A)) ); % Part (a): % figure; spy(A); title( 'wathen' ); tic, R = chol(A); t=toc; fprintf('Time to directly Cholesky factor wathen = %f\n', t ); fprintf( 'Number of non zeros of the Cholesky factor of wathen = %d (=%f percent)\n', nnz(R), nnz(R)/prod(size(A)) ); figure; spy(R); title( 'Cholesky factor of wathen' ); pause; close all; % Part (b): % p = randperm(size(A,1)); arnd = A(p,p); figure; spy(arnd); title( 'Randomized version of wathen' ); tic, R = chol(arnd); t=toc; fprintf('Time to factor randomly Cholesky factor wathen = %f\n', t ); fprintf( 'Number of non zeros of the Cholesky factor of wathen = %d (=%f percent)\n', nnz(R), nnz(R)/prod(size(A)) ); figure; spy(R); title( 'Cholesky factor of randomized wathen' ); pause; close all; % Part (c): % p = symrcm(A); arcm = A(p,p); figure; spy(arcm); title( 'Reverse Cuthill-McKee ordered version of wathen' ); tic, R = chol(arcm); t=toc; fprintf('Time to factor the reverse Cuthill-McKee ordered Cholesky factor wathen = %f\n', t ); fprintf( 'Number of non zeros of the Cholesky factor of wathen = %d (=%f percent)\n', nnz(R), nnz(R)/prod(size(A)) ); figure; spy(R); title( 'Cholesky factor of reverse cuthill-McKee ordered wathen' ); pause; close all; % Part (d): % %p = symmmd(A); p = symamd(A); ammd = A(p,p); figure; spy(ammd); title( 'Minimum degree ordering of wathen' ); tic, R = chol(ammd); t=toc; fprintf('Time to factor the minimum degree ordering Cholesky factor wathen = %f\n', t ); fprintf( 'Number of non zeros of the Cholesky factor of wathen = %d (=%f percent)\n', nnz(R), nnz(R)/prod(size(A)) ); figure; spy(R); title( 'Cholesky factor of the minimum degree ordering of wathen' ); return;