1 function y=restriction_3d(x)
5 % y bilinear average on twice coarser grid
6 % this is transpose of prolongation with weighting
9 % x=magic(2); restriction_3d(x)
11 % map vector to 3d grid with zero boundary
12 % average from neighbors with the same weights as prolongation
14 if any(mod(size(x),2))==0
15 error('restriction_3d: input dimensions must be odd')
17 tw=1/(1+6*1/2+12*1/4+8*1/8);
19 y = tw*x(2+i1:2:end-1+i1,2+i2:2:end-1+i2,2+i3:2:end-1+i3);
23 if (i1 ~=0) || (i2 ~=0) || (i3 ~=0)
24 w = tw/((1+abs(i1))*(1+abs(i2))*(1+abs(i3)));
25 y = y + w*x(2+i1:2:end-1+i1,2+i2:2:end-1+i2,2+i3:2:end-1+i3);