1 function [Kb,Fb]=apply_boundary_conditions(K,F,X)
2 % apply zero dirichet boundary condition on sides and on top
6 % X X{1} has the size of the domain
13 [i1,i2,i3]=ind2sub(n,1:nn);
14 bc = i1==1 | i1 ==n(1) | i2 ==1 | i2 == n(2) | i3 == n(3); % sides and top only, bottom left alone
15 bx = sub2ind(n,i1(bc),i2(bc),i3(bc)); % matrix indices with zero boundary condition
16 % check number of nodes with boundary condition
17 nbc = (n(1)-2)*(n(2)-2)+2*(n(1)-1)*n(3)+2*(n(2)-1)*n(3);
19 error('wrong number of boundary nodes')
24 error('apply_boundary_conditions: inconsistent size K')
30 Kb(bx,bx)=big(diag(K))*speye(length(bx));