%  Heat equation with Neumann BC on [0,1]
%
%
function pdex01
    m = 0;
    x = linspace(0,1,40);
    t = linspace(0,0.2,20);
  sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
%
%
%  Extract the first solution component as u.
%
u = sol(:,:,1);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Surface plot of u(x,t)
%
surf(x,t,u) 
title('Numerical solution: u(x,t)')
xlabel('x')
ylabel('t')
% Solution profile u(x,*) at last time.
figure
plot(x,u(end,:))
title('u(x,t) at t = 0.15')
xlabel('x')
ylabel('u(x,0.15)')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%          Defining the problem (m=0)
%
%   c(x,t,u,u_x) u_t = (f(x,t,u,u_x))_x + s(x,t,u,u_x)
%
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = 1;
f = 1*DuDx;
s = 0;
%        u(x,0)=u0(x)
%
function u0 = pdex1ic(x)
u0=2*exp(-(x-0.5)^2/(0.05));
%
%       p + q*f = 0          x=xl,xr
%
%  where f is the flux f declared in the PDE above
%  Since f=u_x above the BC declared below are 
%  u_x = 0 at x=0,1.
%
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = 0;
ql = 1;
pr = 0;
qr = 1;