function heatmovie(tf); % HEATMOVIE Produces "movie" of exact (Fourier) soln % of heat equation problem. % Example: % >> heatmovie(0.02) % >> heatmovie(0.0005) % ELB 2/21/05 xx=linspace(0,1,2000); MM=20; % number of movie frames for j = 1:MM+1 t=tf*(j-1)/MM; plot(xx,exactsoln(xx,t)) axis([0 1 -12 12]), xlabel x, ylabel u, grid on set(gca,'nextplot','replacechildren'); legend(['t= ' num2str(t)]) F(j) = getframe; end movie(F,2) % play the movie three times total function u=exactsoln(x,t); % subfunction to compute the exact soln N=500; m=1:N; a=zeros(1,N); a(3)=2/3; a(33)=10/3; mm=m((m~=3)&(m~=33)); temp=10*(sin((33-mm)*pi/3)./((33-mm)*pi)-sin((33+mm)*pi/3)./((33+mm)*pi)); a(mm)=temp+sin((3+mm)*pi/3)./((3+mm)*pi) - sin((3-mm)*pi/3)./((3-mm)*pi); pim=pi*(1:N); ae=a.*exp(-t*(pim.^2)); u=sum(repmat(ae',1,length(x)).*sin(pim'*x));