% m57_leapfrog2Dcheb.m - second-order wave eq. % in 2D via Chebyshev spectral % (compare m48_leapfrog2D.m, based on finite differences) % Grid and initial data: N = 32; [D,x] = cheb(N); D2 = D^2; D2p = D2'; x = x'; y = x'; k = 6/N^2; [xx,yy] = meshgrid(x,y); % Initial data and plot setup: vv = exp(-12.5*(xx.^2+yy.^2)); vvold = vv; vvnew = 0*vv; clf, shg plt = mesh(xx,yy,vv); view(-20,30) axis([-1 1 -1 1 -1.2 1.2]) colormap(1e-6*[1 1 1]), drawnow % Time-stepping by leap frog formula: plotgap = round(.01/k); I = 2:N; for n = 1:20/k if mod(n,plotgap)==0 set(plt,'zdata',vv) drawnow end uxx = vv*D2p; uyy = D2*vv; vvnew(I,I) = 2*vv(I,I) - vvold(I,I) + k^2*(uxx(I,I)+uyy(I,I)); vvold = vv; vv = vvnew; title(sprintf('t = %6.3f', n*k), 'fontsize',12) end