FDTD 1D simulation
조회 수: 10 (최근 30일)
이전 댓글 표시
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
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개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!