1 function res = Amul_v(X,A,v)
2 % multiplies the penalty weight diagonal matrix and a vector
3 % the operation is res = A * v, where A is a diagonal matrix
6 % A matrix to multiply, must be diagonal
19 x = X{1}; y = X{2}; z = X{3};
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% A * v %%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 res(i + (j-1)*(nx+1) + (k-1)*(nx+1)*ny) = ...
26 A(i + (j-1)*(nx+1) + (k-1)*(nx+1)*ny,i + (j-1)*(nx+1) + (k-1)*(nx+1)*ny) * v(i + (j-1)*(nx+1) + (k-1)*(nx+1)*ny);
30 add_factor = (nx+1)*ny*nz;
34 res(add_factor + i + (j-1)*nx + (k-1)*nx*(ny+1)) = ...
35 A(add_factor + i + (j-1)*nx + (k-1)*nx*(ny+1),add_factor + i + (j-1)*nx + (k-1)*nx*(ny+1)) * v(add_factor + i + (j-1)*nx + (k-1)*nx*(ny+1));
39 add_factor = add_factor + nx*(ny+1)*nz;
43 res(add_factor + i + (j-1)*nx + (k-1)*nx*ny) = ...
44 A(add_factor + i + (j-1)*nx + (k-1)*nx*ny,add_factor + i + (j-1)*nx + (k-1)*nx*ny) * v(add_factor + i + (j-1)*nx + (k-1)*nx*ny);