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