FDTD 1D simulation

1 次查看(过去 30 天)
igal
igal 2024-4-5
评论: nick 2024-4-15
hello guys
i got a task in my class about simulating 1D FDTD in matlab
this is the code i wrote and i need help with it
clear;close all
%% Define Simulation Based off Source and Wavelength
sampnum = 1000; % Number of time steps [unitless]
%% Spatial and Temporal System
Nx = 100; % Points in x [unitless]
dx = 0.1; % x increment [meter]
dt = dx;
Z0=1;
tx1 = num2str(Z0)+"\Omega transmission line";
%% Initialize Voltage and Current Vectors
Vx = zeros(1,Nx); % Voltage
Iy = zeros(1,Nx); % Current
%% Start loop
for t=0:sampnum
clf
%% Current field loop
Iy(1:Nx-1) = Iy(1:Nx-1)+(1/Z0)*diff(Vx);
%% Voltage field loop
Vx(2:Nx-1) = Vx(2:Nx-1)+Z0*diff(Iy(1:Nx-1));
%% Source
Vx(round(Nx/2)) = Vx(round(Nx/2)) + exp(-1*((t-4)/2)^2);
%% Plot
subplot(2,1,1)
plot(Vx); axis([1 Nx -1 1]);
title('Voltage Wave')
ylabel('Voltage [V]','FontSize',10, ...
'FontWeight','bold')
xlabel(tx1);
grid on
subplot(2,1,2)
plot(Iy,'r'); axis([1 Nx -1 1]);
title('Current Wave')
ylabel('Ampere [A]','FontSize',10, ...
'FontWeight','bold')
xlabel(tx1);
grid on
pause(0.001);
end
  1 个评论
nick
nick 2024-4-15
Hi igal,
Please mention the problem statement, the error in code written by you and expected output to help us better resolve your question.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by