📄 fdtd.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FDTD Finite-Difference Time-domain in free space no ABC
% FDTD(t) runs FDTD for time t.
%
% FDTD implenments the FDTD/staggered leapfrog scheme
% over time 0-max_time and space 0-max_space. This program
% simulates a gassian pulse in the grid specified with
% max_time and max_space. The pulse is sent from the center of
% the problem space and disperses in both directions
%-Kira Heater
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function FDTD = FDTD(time)
max_time = time;
max_space = 200; %must be divisible by two
eta = 1/2;
E = zeros(max_space,1); %Initialize Electric array
H = E; %Initialize Magnetic array
spread = 12; %width of pulse
center_problem_space = max_space/2;
t0 = 40; %center of pulse
%Outer loop steps through time -
%here E is 1/2 step behind since the pulse
%enters the problem space between the
%E and H loops.
for n = 1:max_time
%Inner Loop E - Increments electric wave in space
for k = 2:max_space
E(k) = E(k) + eta*( H(k-1)-H(k) );
end
pulse = exp( -.5*( (t0-n)/spread )^2 ); %Hard Source- imposes a value on the grid
E(center_problem_space) = pulse;
%Inner Loop H - Increments magnetic wave in space
for j = 1:max_space-1
H(j) = H(j) + eta*( E(j)-E(j+1) );
end
%Plots progression of the electric wave
figure(1)
plot(E)
axis([1 max_space -1.1 1.1])
title('FDTD Simulation of and Electric Pulse in Free Space')
xlabel('Problem Space')
ylabel('E_x')
pause(.05)
end
%Plots electric and magnetic feilds at max_time
figure(2)
subplot(2,1,1)
plot(E,'r')
title('Simulation of Electric Pulse')
ylabel('E_x')
axis([0 max_space -1.1 1.1])
subplot(2,1,2)
plot(H,'g')
ylabel('H_y')
title('Simulation of Magnetic Pulse')
axis([0 max_space -1.1 1.1])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -