% %this is a method of lines solution of the 1d heat equation % % u_t = u_xx % u=0 at x=0,1 % u=f(x)=sin(pi x) at t=0 % % (DMA, 5-29-08) % % This code also generates a movie (an avi file). Sometimes % problems can arise with the generation of the avi file if % Matlab encounters an error during the running of the code. % Don't expect this code to be foolproof!! %******************************************************* clear all; N=50; %define boundary values a=0; b=1; ua=0; ub=0; % boundary interval dx =(b-a)/N; x = linspace(a,b,N+1); % uinit = sin(pi*x); uin= uinit(2:N); tinit = 0; tfinal = 10; tspan = [tinit tfinal]; % RelTolVal=10^(-4); AbsTolVal=10^(-6); options = odeset ('RelTol',RelTolVal,'AbsTol',AbsTolVal); % [t,u] = ode23s (@heat_mol_RHS, tspan, uin,options, N,dx,ua,ub); % %[row, col] = size(u); % % % Movie % kframes = size(t); Frame = moviein(kframes); mov = avifile('heat_mol.avi','quality',100,'fps',5); for k = 1:kframes plot(x,[ua u(k,:) ub],'b');hold on; grid on; xlabel('Spatial x'); ylabel('u(x,t)'); axis([0,1,-0.08,1.0]); hold off Frames(:,k) = getframe; F = getframe; mov = addframe(mov,F); end movie(Frames,3,20); % movie(nameofmovie,# of times played, # of frames per second) mov=close(mov);