%CH23     Program for Chapter 23  
%
% Backward time central space (BTCS) for heat eqn 

clf
%%%%%%%%%%%%% Parameters %%%%%%%%%%%%%%%
L = pi; Nx = 9; dx = L/Nx;
T = 3; Nt = 19; dt = T/Nt; nu = dt/dx^2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

B = (1+2*nu)*eye(Nx-1,Nx-1) - nu*diag(ones(Nx-2,1),1) - nu*diag(ones(Nx-2,1),-1);
U = zeros(Nx-1,Nt+1);
U(:,1) = sin([dx:dx:L-dx]');
for i = 1:Nt
    x = B\U(:,i);
    U(:,i+1) = x;
end
bc = zeros(1,Nt+1);
U = [bc;U;bc];

mesh(U')
xlabel('x','FontSize',20')
ylabel('t','FontSize',20')
