FDTD 1D simulation

3 ビュー (過去 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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by