The post is old but the question arises many times, so I post here my solution. It is a generalization of @Matt J solution. Suppose you have a matrix with unknowns partitioned in free x and dirichlet . And by chance the partition is such that the free variables come first The free unknowns can be obtained by solving the first block row:
The second block row is of no interest, since is known. In the general case when are not at the end of the unknown vector, but they are identified by the index vector idFix and the corresponding Dirichlet values xFix, you can write the function function x = solveproblem(A,b,idFix,xFix)
iFree = setdiff(1:n,idFix);
This method preserves the original properties of the original matrix (in particular if it's SPD). There is also an interesting way to include in this approach that a selection of the vector of unknowns has the same value, for example a floating potential of an equipotential object, but it goes beyond the original question