FDTD 1D simulation

조회 수: 10 (최근 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