function A=buildA(m)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for multigrid
% 2nd order centered difference approximation to 
% -D^2 u = f(x) with u(0)=u(1)=0
%
% 2^m+1 points including boundary points.
%
% F. Waleffe, 11/15/2000 for Math 801
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

N=2^m+1; dx=1/(N-1);

A=2*diag(ones(N,1),0)-diag(ones(N-1,1),1)-diag(ones(N-1,1),-1);

% boundary conditions:

A(1,1)=1; A(1,2)=0; A(2,1)=0;
A(N,N)=1; A(N-1,N)=0; A(N,N-1)=0;

A=A/dx^2;



