% eigenvalue problem on square plane with side length a
% Dirichlet boundaries Ez(edge) = 0
% We should see multiples of wavelengths along each axis.


clear all 
close all

a = 1;
n = 100; % gridpoints per axis
% Analytical eigenmode
xn = linspace(-a, a, n);
yn = linspace(-a, a, n)';
[X Y] = meshgrid(xn, yn)

E0 = 1;

% Eigenmode indices
nx = 1;
ny = 1;


Eana = E0*sin(pi*nx/a*X).*sin(pi*ny/a*Y)

% Plot a few modes
for nx = 1:3
    for ny = nx:3
        Eana = E0*sin(pi*nx/a*X).*sin(pi*ny/a*Y);
        figure 
        pcolor(X, Y, Eana)
        view(2);
        shading interp;  % smooth shading
        colorbar;
        title(["Ez", num2str([nx, ny])])
        axis equal
    end
end