function heateqex1
%Solves a sample Dirichlet problem for the heat equation in a rod
m = 0;
x = linspace(-5,5,20);
t = linspace(0,4,20);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
% A surface plot is often a good way to study a solution.
surf(x,t,u)    
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
% A solution profile can also be illuminating.
figure
plot(x,u(end,:))
title('Solution at t = 4')
xlabel('Distance x')
ylabel('u(x,4)')
% --------------------------------------------------------------
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = 1/2; %% c is the reciprocal of the thermal conductivity
f = DuDx;
s = 0;
% --------------------------------------------------------------
function u0 = pdex1ic(x)
u0 = 20+5*sign(x);
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
% q's are zero since we have Dirichlet conditions
% pl-0 at the left, pr=0 at the right endpoint
pl = ul-15;
ql = 0;
pr = ur-25;
qr = 0;