function A=anderson(m,w)

a =w*(rand(m^3,1)-.5);
addpath 'matlab/ilupack/' -begin

% 1D laplacian with periodic boundary conditions
% and random diagonal entries
T1=spdiags([-ones(m,1) 2*ones(m,1) -ones(m,1)],-1:1,m,m);
T1(1,m)=-1;T1(m,1)=-1;

% 2D laplacian as kronecker sum of 2  1D laplacians
A2D=kron(T1,speye(m))+kron(speye(m),T1);
% 3D laplacian as kronecker sum of 3  1D laplacians
A=kron(A2D,speye(m))+kron(speye(m^2),T1);

for i=1:m^3
    A(i,i)=a(i);
end % for i
