% Compute capacitance from potential.

function cap = gauss(n,m,h,f)
% Arguments:
%   n    = number of points in the x-direction (horizontal)
%   m    = number of points in the y-direction (vertical)
%   h    = cell size
%   f    = 2D-array with solution
% Returns:
%   cap = capacitance per unit length [pF/m]

EM_constants; % Import constants.

q = 0; % Charge per unit length.
for i = 1:n
    q = q + 0.5*(f(i,m) + f(i+1,m)); % integrate along upper boundary.
end

for j = 1:m
    q = q + 0.5*(f(n,j) + f(n,j+1)); % integrate along right boundary.
end

cap = q*4*e0*1e12; % Scaling by 1e12 gives pF/m.

end