Propagation and reflection of sinusoidal electromagnetic wavesBeijing Institute of Technology | Ming-Jian Li
The following MATLAB code is a companion code for the course on Artificial Intelligence and Simulation Science. It functions to calculate the propagation and reflection of a sinusoidal electromagnetic wave using the Finite-Difference Time-Domain (FDTD) method.
x
1clear; clc;2ke = 100;3% Position of the source4ks = 1;5% ks = ke / 2;6% Number of time steps7nsteps = 3000;8% Cell size and time stepping9c0 = 3.e8;10dz = 0.01;11dt = dz / (2 .* c0);12% Constants13cc = c0 * dt / dz;14% Initialize vector15ex = zeros(1, ke);16hy = zeros(1, ke);17space = zeros(1, ke);18for k = 1:ke19 space(k) = k*dz;20end21empty = zeros(1, ke);22% sine wave23amp = 0.5;24omg = 0.1;25for t = 1:nsteps26 % E field loop27 for k = 2:ke - 128 ex(k) = ex(k) + cc * (hy(k - 1) - hy(k));29 end30 % Source31 ex(ks) = amp* sin( omg* t );32 % H field loop33 for k = 1:ke - 134 hy(k) = hy(k) + cc * (ex(k) - ex(k + 1));35 end36 clf37 plot3(space,ex,empty, 'r', 'LineWidth', 5 ); 38 axis([0 1 -2 2 -2 2]);39 set(gcf,'Position',[200 200 1080 720]); 40 hold on41 plot3(space,empty,hy, 'b', 'LineWidth', 5 ); 42 pause(0.001);43endThe result is as follows.
