function M = DirichletMatrix(N,L)

% with Dirichlet boundary conditions, the matrix has -2 on the diagonal
% and 1 above and below the diagonal.
h = L/N;
M = -2*eye(N-1);
for j=1:N-2
  M(j,j+1)=1;
end
for j=2:N-1
  M(j,j-1)=1;
end
M = M/h^2;

% note: this can be done quickly via
%
% M = toeplitz([-2 1 zeros(1,N-3)])/h^2;
