%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Solution to Homework 3, problem 2. % Solve the linear system Au=b where A is % 1. an adaptive finite element approximation to % -u_{xx} - u_{yy} = f(x,y) % in a circle with a slit cut from it % (generated by slit2.m) % or % 2. a uniform finite difference approximation to % - u_{xx} - u_{yy} -u_{zz} = f(x,y,z) % for (x,y,z) in (0,1) x (0,1) x (0,1), % with u = 0 on the boundary of the box. % % Use varying meshes, with h=1/(n+1), and solve using % various direct and iterative algorithms, recording % the resources consumed. % % Plot the time and memory required by the various % solution algorithms. % % problem2.m Dianne O'Leary 04-2005 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('Generating some test problems') [A1,b1,h1,A2,b2,h2] = slit2; [A3,b3,h3] = laplace3d(25); problems = ['Laplace equation on circle sector' 'Laplace equation on circle sector' 'Laplace equation on box, ']; droptol = .05; alg = [' Cholesky' 'Cholesky, R-Cuthill-McKee' 'Cholesky, minimum degree' ' GMRES, restart = 20' ' GMRES, restart = 100' ' CG, no precond' ' CG, diagonal precond' ' CG, Cholinc precond' ' CG, mindeg + Cholinc']; for i=1:3, if (i==1) A = A1; b = b1; h = h1; elseif (i==2) A = A2; b = b2; h = h2; else A = A3; b = b3; h = h3; end disp(' ') disp(sprintf('Solving %33s with n=%d and convergence tolerance = %5.2e', ... problems(i,:),length(b),.01*h^2)) [nz,cflag,ctime,iter,rnorm] = runmethods(A,b,.01*h^2,droptol); disp(' Algorithm storage flag time iterations residual_norm') for i=1:9, disp(sprintf('%25s %8d %8d %5.2e %5d %5.2e', ... alg(i,:),nz(i),cflag(i),ctime(i),iter(i),rnorm(i))) end end