% Homogeneous wave equation with dirichlet (PEC) boundaries. That is, no
% sources and E = 0 on boundaries.
clear all
c0 = 299792458;

 

n = 40;
e = ones(n, 1); % 40 unknown field terms along the x-axis.
a = 5; % Other boundary position
dx = a/(n+1); % 41 intervals for 42 grid points.
xAll = dx*(0:(n+1));

% We want to solve 

A_1d = -(1/dx^2) * spdiags([e, -2*e, e], -1:1, n, n); % FD stencil
[eMode, eValue] = eig(full(A_1d)); % Get eigenmode (ie. the field solution for each mode) and eigenvalue (ie. the coefficient for each mode, where eVal = w^2_n*eps0*mu0)

eValue = diag(eValue);


figure
hold on
for idx = 1:3
    plot(xAll, [0;eMode(:,idx);0])
end

