% TP 1 par A.Mokraoui
% Listing 1
% Ondes plane dans le vide (structure fermée)
function fdtd
% Constantes physiques
c = 3e8;
eps0 = 1/(4*pi*9e9);
mu0 = 4*pi*1e-7;
% Constantes du problème
N=100;
fmax = 1e9;
l0 = c / fmax;
dz = l0 / 10;
dt = dz/c/2;
an = dt/eps0/dz;
bn = dt/mu0/dz;
% Initialisation
Ex = zeros(1,N);
Hy = zeros(1,N);
% Propriété de la source
spread = 12;
t0 = 40;
k=0;t=0;
while k<2000,
t=t+dt;
k=k+1; % indice étape!!!
Ex(2:N) = Ex(2:N) - an*(Hy(2:N) - Hy(1:N-1));
pulse = exp(-0.5*((t0-k)/spread)^2);
Ex(N/2) = pulse;
Hy(1:N-1) = Hy(1:N-1) - bn*(Ex(2:N)-Ex(1:N-1));
subplot(211)
plot((1:N)*dz,Ex,'b');xlabel('z');ylabel('Ex');
axis([0 N*dz -2 2]);grid;
subplot(212);
plot((1:N)*dz,Hy,'r');xlabel('z');ylabel('Hy');
axis([0 N*dz -.005 .005]);
grid;
drawnow;
tpause = clock;
while etime(clock,tpause)<0.02,
pause(0);
end
end