function [Creal,matrix] = calccap(nx,ny)

% Permitivity of free space.
E_0 = 8.854187818E-12;

% Create panels for unit plate
[panels] = plategen(nx,ny);

%done = 'read input file'
display('done creating panels');

% Compute the panel centroids and areas (don't need the normals).
[centroids, ~, areas] = gencolloc(panels);

display('generated collocation points');

% Generate the collocation matrix
[matrix] = collocation(panels,centroids);

display('generated matrix');

% Create the rhs
[r,~] = size(matrix);
rhs = ones(r,1);

% Solve for the charge density vector
q = matrix \ rhs;

display('solved for charge');

% Integrate the charge over the surface to compute the capacitance.
% But first multiply the charge density by the panel area.
q = q .* areas.';
C = sum(q);

% Scale the capacitance by the free space dielectric permitivity and 4pi.
Creal = E_0 * 4 * pi * C;





