% Set the number of elements nx = 10;

% Compute the load vector F = zeros((nx+1)*(ny+1), 1); for i = 1:nx+1 for j = 1:ny+1 F((i-1)*(ny+1) + j) = f(i/nx, j/ny); end end

% Define the element stiffness matrix hx = 1/nx; % element size in x-direction hy = 1/ny; % element size in y-direction Ke = (1/4)*[2 -2 -1 1; -2 2 1 -1; -1 1 2 -2; 1 -1 -2 2]/ (hx*hy);

% Solve the linear system u = K\F;