% TIME_TEST % % test of solvers for % % -u'' + sigma u = f % % where the solution is u(x) = exp(x) sin(pi x) and % % f(x) = -2 pi exp(x) cos(pi x) + (pi^2 +sigma -1)u(x) % % We solve the problem on a sequence of grids and (I hope!) observe % the errors decrease by roughly a factor of 4 and the compute times % increase by roughly a factor of 2. % % Why are the increases in compute times so hard to measure? % % You can pick direct, or three flavors of FMG by editing the % commented out calls to the solvers. % global sigma sigma=10; lmin=5; lmax=10; ld=lmax-lmin+1; errdata=zeros(ld,5); for l=lmin:lmax nl=2^l; x=0:nl; x=x'/nl; h=1/nl; u=exp(x).*sin(pi*x); fe=-2*pi*exp(x).*cos(pi*x)+(pi^2 + sigma -1)*u; tin=cputime; % % Pick your favorite solver and compare errors and work as % the mesh is refined % % Do the solve many times to make sure you get something measurable. repeats=1000; % % for i=1:repeats; v=fmg1(fe,2,1,1); end % for i=1:repeats; v=fmg2(fe,3,3,3); end for i=1:repeats; v=fmg(fe,3,3,3); end % % repeats=1000; v=helmholtz(fe,repeats); tout=cputime-tin; errdata(l-lmin+1,1)=h; errdata(l-lmin+1,4)=tout; errdata(l-lmin+1,2)=norm(v-u,inf); end errdata(2:ld,3)=errdata(2:ld,2)./errdata(1:ld-1,2); errdata(2:ld,5)=errdata(2:ld,4)./errdata(1:ld-1,4)