function L=mic0_3d(A,n);
% Makes a modified incomplete Cholesky factorization of A,
% A is the 3D discrete Laplacian matrix on a cube,
% no extra subdiagonal filled-in in L
nnn=n*n*n;;nn=n*n;nnnmn=nnn-n+1;nnnmnn=nnn-nn+1;
si=10;
bb=zeros(nnn,1);cc=zeros(nnn,1);aa=zeros(nnn,1);dd=zeros(nnn,1);
for i=1:nnn,
 as=A(i,i)*(1+si/nn);
 if i>1, as=as-bb(i-1)*(bb(i-1)+cc(i-1)+dd(i-1)); end
 if i>n, as=as-cc(i-n)*(cc(i-n)+bb(i-n)+dd(i-n)); end
 if i>nn as=as-dd(i-nn)*(dd(i-nn)+bb(i-nn)+cc(i-nn));end
 aa(i)=sqrt(as);
 if i<nnn, bb(i)=A(i,i+1)/aa(i); end
 if i<nnnmn, cc(i)=A(i,i+n)/aa(i); end
 if i<nnnmnn, dd(i)=A(i,i+nn)/aa(i);end
end
L=spdiags([dd cc bb aa], [-nn,-n,-1,0],nnn,nnn);
