% Math 3150 Fall 2012
% Example 3.5.1 - heat equation

toprint = 0; % 1 create print quality plots, 0 animate
N=20;        % number of terms to use in the partial sums, increase to get
             % more accurate solutions
c=1;         

% space variable
x = linspace(0,pi);

% time variable will take values in this array
ts=linspace(0,1,21); % 21 equally spaced points from 0 to 1, included
		     % depending on c you may need to change this

figure(1); clf;
if (toprint) hold on; end; % do not erase previous plots
for it=1:length(ts), % for every time
 t = ts(it);
 s = zeros(size(x)); %initialize partial sum to zero
 for n=1:N,
  bn = 200*(1-cos(n*pi))/n/pi;
  % uncomment to add high frquency mistake
  %if (n>=10) bn = bn+2; end; 
  s = s + bn*exp(-n^2*t)*sin(n*x);
 end;
 plot(x,s); % plot the partial sum
 axis([0 pi 0 120]); % adjust axis so that all plots are on the same scale
 pause; % wait for user input
end;
if (toprint) hold off; end; % erase previous plots
