% The whole K is participated in caculation. % So K(fixeddofs) should be 1 in diag and 0 otherwise function K = boundaryK(K, fixeddofs) K(fixeddofs, :) = 0; K(:, fixeddofs) = 0; for i = 1:size(fixeddofs, 2) dof = fixeddofs(i); K(dof, dof) = 1; end end