function coef = CS368_P4M(n, m) 
    [x, y] = meshgrid(1:(n * m), 1:(n * m));
    coef = abs(mod(x - 1, m) - mod(y - 1, m)) + abs(floor((x - 1) / n) - floor((y - 1) / n)) == 1;
    coef = -coef ./ (sum(coef, 2) + [1; zeros(n * m - 2, 1); 1]);
    coef = coef + diag(ones(1, n * m));
end