微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微波和射频技术 > 电磁仿真讨论 > FDTD Code In Matlab (HELP)

FDTD Code In Matlab (HELP)

时间:03-30 整理:3721RD 点击:
Hi friends

I wrote a matlab code for a microstrip antenna
where i wrote Ex , Ey , Ez
i have errors
i dont know why this error occured
plz if u know , help me


my code just for this section

for ie=1:Nx;
for je=1:Ny;
for ke=1:Nz;
Ex(ie+0.5,je,ke)=cc.*Ex(ie+0.5,je,ke)+cy2.*(Hz(i+0 .5,je+0.5,k)-Hz(ie+0.5,je-0.5,k))-cz2.*(Hy(ie+0.5,j,ke+0.5)-Hy(ie+0.5,j,ke-0.5))
Ey(ie,je+0.5,ke)=cc*Ey(ie,je+0.5,ke)+cz2*(Hx(ie,je ,ke+0.5)-Hx(ie,je,ke-0.5))-cx2*(Hz(ie+0.5,je,ke)-Hz(ie-0.5,je,ke))
Ez(ie,je,ke+0.5)=cc*Ez(ie,je,ke+0.5)+cx2(Hy(ie+0.5 ,je,ke)-Hy(ie-0.5,je,ke))-cy2*(Hx(ie,je+0.5,ke)-Hx(ie,je-0.5,ke))
end
end
end


my error :
? Attempted to access Ex(1.5,1,1); index must be a positive integer or logical.

Error in ==> FDTDlast at 82
Ex(ie+0.5,je,ke)=cc.*Ex(ie+0.5,je,ke)+cy2.*(Hz(i+0 .5,je+0.5,k)-Hz(ie+0.5,je-0.5,k))-cz2.*(Hy(ie+0.5,j,ke+0.5)-Hy(ie+0.5,j,ke-0.5))
>>

Hi sara.
answer is very simple.in MATLAB index is integer!
in FDTD by MATLAB you must change "+/- 0.5" to "1/0 ",depend on your field (E or H).
for example you must to write:

Ex(ie,je,ke)=cc.*Ex(ie,je,ke)+cy2.*(Hz(ie,je,ke)-Hz(ie,je-1,ke))-cz2.*(Hy(ie,je,ke)-Hy(ie,je,ke-1))

also,I recommend that if you want to learn FDTD,don't use from matlab!
because matlab is very slower than c,c++ and fortran.
good luck
ghasem

Hi ghasem
tnks a lot for your help
I think i get it
I've applied the changes but got same error


for ie=1:Nx;
for je=1:Ny;
for ke=1:Nz;
Ex(ie,je,ke)=cc*Ex(ie,je,ke)+cy2.*(Hz(ie,je,ke)-Hz(ie,je-1,ke))-cz2.*(Hy(ie,je,ke)-Hy(ie,je,ke-1))
Ey(ie,je,ke)=cc*Ey(ie,je,ke)+cz2*(Hx(ie,je,ke)-Hx(ie,je,ke-1))-cx2*(Hz(ie,je,ke)-Hz(ie-1,je,ke))
Ez(ie,je,ke)=cc*Ez(ie,je,ke)+cx2*(Hy(ie,je,ke)-Hy(ie-1,je,ke))-cy2*(Hx(ie,je,ke)-Hx(ie,je-1,ke))
end
end
end

error :
Attempted to access Hz(1,0,1); index must be a positive integer or logical.

Error in ==> FDTDlast2 at 82
Ex(ie,je,ke)=cc*Ex(ie,je,ke)+cy2.*(Hz(ie,je,ke)-Hz(ie,je-1,ke))-cz2.*(Hy(ie,je,ke)-Hy(ie,je,ke-1))

good luck

dear sara
this is very simple,too.
in MATLAB index start with i=1,2,3,....in MATLAB in contrast to c,c++ and fortran we can't use from "0" as index.
you have to write as following to update E fields:

Ex(:,2:Ny,2:Nz)=cc*Ex((:,2:Ny,2:Nz)+cy2.*(Hz((:,2: Ny,2:Nz)-Hz((:,1:Ny-1,2:Nz))-...
cz2.*(Hy((:,2:Ny,2:Nz)-Hy((:,2:Ny,1:Nz-1));
where , : = 1:Nx-1 and Nx,Ny and Nz are number of point in x,y,z directions,respectively.
also,never use from for-loop in MATLAB.this is very time-consuming.
best wishes...
ghasem

Hi dear
tnx for your help
i get it :)

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top