% plot solution of example problem 1 (see Notes) 
%   boundary conditions u(0,t)=0, u(1,t)=0
%   initial condition   u(x,0)=1

c = @(j)  mod(j,2)*4/(j*pi);     % coefficient c(j)
lambda = @(j)  j^2*pi^2;         % eigenvalue lambda(j)
v = @(j,x)  sin(j*pi*x);         % eigenfunction v(j,x) 

N = 20;                          % use j=1:20
xv = 0:.01:1;                    % x-values for plotting
tv = 0:.01:.2;                   % t-values for plotting

[X,T] = ndgrid(xv,tv);
U = zeros(size(X));              % initialize U with zeros
for j=1:N
  U = U + c(j)*v(j,X).*exp(-lambda(j)*T);
end
colorcurves(X,T,U)

