Here is the function DirichletMatrix.m and here is the script that I used to test it.

Here is the function NeumannMatrix1.m and here is the script that I used to test it.

Here is the function NeumannMatrix2.m and here is the script that I used to test it.

Here is the function NeumannMatrix3.m and here is the script that I used to test it.