Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

FDTD Code In Matlab (HELP)

Status
Not open for further replies.

sara67

Banned
Member level 1
Joined
Dec 2, 2012
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
0
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
 
Last edited:

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top