1 function y=nd_mult(K,x)
3 % multiply vector x by matrix K from nd_assembly
4 [n1,n2,n3,m1,m2,m3]=size(K);
5 if any([m1,m2,m3]~=3), error('K must be 3D stencil'),end
6 u=reshape(x,n1,n2,n3); % make x into grid vector
11 for i3=max(1,1-j3):min(n3, n3-j3)
13 for i2=max(1,1-j2):min(n2, n2-j2)
15 for i1=max(1,1-j1):min(n1, n1-j1)
17 % contribution of K(i,j)*x(j)
19 y(i1,i2,i3)=y(i1,i2,i3)+K(i1,i2,i3,2 + j1,2 + j2,2 + j3)*x(k1,k2,k3);