function [R] = calc_error(M) % Calculates the LINEAR mistake at each cell of F and G. % The difference between the equation and the actual cell value s = size(M) ; rows = s(1); cols = s(2); h = 1/(rows-1); R = zeros(s); % Error at F cells %================== for i= 2:2:rows - 1 for j = 2:2:cols - 1 R(i,j) = M(i,j) - (1/(2*h))*(M(i,j+1) - M(i,j-1) + M(i+1,j) - M(i-1,j)) ; end end % Error at G cells %==================== for i= 3:2:rows - 2 for j = 3:2:cols - 2 R(i,j) = M(i,j) - (1/(2*h))*(M(i+1,j) - M(i-1,j) - (M(i,j+1) - M(i,j-1))) ; end end