% Numerically calculate soln. to advection eqn. dq/dt + dq/dx = 0 on % domain 00); semilogy(M,abs(q0hat).^2,'r+',Mpos,cfit*Mpos.^(-2),'r--') xlabel('K_n/(2\pi)') ylabel('|qhat_n|^2') title('Power spectrum of q_0 with k^{-2} fit curve') subplot(2,2,3) qf = interpft(q,Nf); % Numerical solution on plotting grid plot([xf L],[q0f q0f(1)],'b-',[x L],[q q(1)],'r+',[xf L],[qf qf(1)],'r-') xlabel('x') ylabel('q') axis([0 1 -1.5 1.5]) title(['Spectral method, RK4, dt/dx = ',num2str(nu),', t = ' num2str(tf)]) legend('Exact','Gridpoints','Continuous') subplot(2,2,4) phasespeed = 1 - angle(qhat./q0hat)./(k*tf); plot(M,phasespeed,'+') xlabel('K_n/(2\pi)') ylabel('Numerical phase speed') title('Phase speed error vs. wavenumber')