% Solution of the Heat Equation Using a Forward Difference Scheme
% Using Matrices

% Initialize Data
%     Length of Rod, Time Interval
%     Number of Points in Space, Number of Time Steps

L=1;
T=0.1;
k=1;
N=10;
M=500;
dx=L/N;
dt=T/M;
s=k*dt/dx^2;

x=linspace(0,L,N+1)';
u0 = sin(pi*x);
A = (1-2*s)*diag(ones(N+1,1))+s*diag(ones(N,1),-1)+s*diag(ones(N,1),1);

plot(x,u0)
hold on
Nfig=10;
M10=M/Nfig;
for j=1:Nfig
   for j2=1:M10
     u1=A*u0;
     u1(1)=0;
     u1(N+1)=0;
     u0=u1;
   end
   plot(x,u0)
end
hold off
