%EE3FI4, 2006
%Dr. Mohamed Bakr
%this file shows an animation of a plane wave propagating in the z
%direction with speed of light
Frequency=1.0e9;  %this is the frequency of the plane wave
Omega=2*pi*Frequency; %this is the angular frequency
C=3.0e8;  %this is the speed of light
Betta=Omega/C;  %this is the phase constant
Lambda=2*pi/Betta; %this is the wavelength
T=1/Frequency; %this is the periodic time
Eo=2.0; %amplitude of electric field
Mx=50;  %number of points in the x direction
Mz=50; %number of points in the z direction
dz=0.05*Lambda; %the increment in the z direction
dt=0.01*T;  %the time step between snapshots
NumberOfTimeSteps=1000; %this is the number of snapshots
Points=zeros(Mx,Mz); %array of z indices for points
for i=1:Mx  %repeat for all points in the x direction
    for j=1:Mz %repeat for all points in the z direction
        Points(i,j)=(j-1)*dz;  %store the value of z at the current grid point
    end
end

for k=1:NumberOfTimeSteps
    t=(k-1)*dt;  %the time of the current snapshot
    Data=Eo*cos(Omega*t-Betta*Points); %get the field at all points
    mesh(Data); %plot the filed
    view(30, 37); %set the view angle
    pause(0.1); %pause for 0.1 of a second
end


