%espde3.m
xspan=[0,1]; tspan=[0,1];
mu=1; f=@(x,t)[-sin(t)*sin(x)+sin(x)*cos(t)];
u0=@(x)[sin(x)];
g=@(x,t)[sin(x)*cos(t)];
 
nstep_x=500; Err_be=[]; 
nstep_t=[20,40,80,160,320];
for k=1:5
    nstep=[nstep_x,nstep_t(k)];
    [xh,uh]=heat_be(xspan,tspan,nstep,mu,...
               u0,g,f);
    
uex=g;
err=max(abs(uex(xh,tspan(2))-uh));
Err_be=[Err_be;err];
 
end
Deltat=1./nstep_t;
loglog(Deltat,Err_be,Deltat,Deltat);
legend('Err','Deltat')
grid on