Added function to convert stencils to matrices.