function pde1

' Solves the PDE using an in-built function PDEPE'

m = 0;
x = linspace(0,pi,200);   % spatial grid
t = linspace(0,3,151);     % output times


sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
u = sol(:,:,1);

subplot('position',[0.1 0.42 0.88 0.52])
%imagesc(x,t,u),axis xy
%contour(x,t,u,20)
contourf(x,t,u,20)
  colorbar
%pcolor(x,t,u),shading interp

title('Numerical solution computed with 200 mesh points');
xlabel('Position x');
ylabel('Time t');

ns=[1 3 7 21 51 151];
subplot('position',[0.1 0.09 0.4 0.23])
plot(x,u(ns,:),'b');
xlabel('Position x');
ylabel('u(x,t)');
axis([0 pi -inf inf])
text(1.,2.7,'t=0, 0.04, 0.12, 0.4, 1, 3')

subplot('position',[0.58 0.09 0.4 0.23])
plot(t,u(:,1),t,u(:,100));
xlabel('Time, t');
ylabel('u(0,t) and u(\pi/2,t)');
axis([0 t(end) -inf inf])

% --------------------------------------------------------------------------

function [c,f,s] = pdex1pde(x,t,u,DuDx)

c = 1;
f = DuDx;
s = 0;

% --------------------------------------------------------------------------

function u0 = pdex1ic(x)
  u0 = (pi-x).*x.*sin(x);
    
% --------------------------------------------------------------------------

function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)

pl = 0;
ql = 1;
pr = ur;
qr = 0;
  
