Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:25:50+00:00 2026-05-22T02:25:50+00:00

I have an FDTD assignment, it’s not going well. Whenever I put a source

  • 0

I have an FDTD assignment, it’s not going well. Whenever I put a source in and let the simulation run for a bit (Note – if you test you have to use the debugger and step through the loop increments otherwise there will be a hefty overflow).

In most of the simulations I’ve seen, people break Ex and Ey into separate parts, I put them into one large E matrix and used the index offset (seen in Ep(u,v+1) and E(u+1,v) to calculate Ey and Ex independently).

The sources I used for reference were:
http://fdtd.wikispaces.com/
and
http://www.mathworks.com/matlabcentral/fileexchange/21000-tiny-fdtd-v1-0
That one is acoustics, but works well.

    close all;


    %% Some user modifiable parameters
    mu0 = pi*4E-7; % pH/µm
    e0 =   8.854187E-12; % Picofarads/micron
    c = 1/sqrt(mu0*e0);

    cellsizeX = 100;      % Size of Yee-Cell in microns
    cellsizeY = 100;      % Size of Yee-Cell in microns
    numX = 100; % Number of cells in X direction
    numY = 100; % Number of cells in Y direction
    lambda = 700*10^-9;
    dx = lambda/20;
    dy = lambda/20;
    dt =  (c*sqrt(dx^-2+dy^-2))^-1;

    t0 = 100;       %index time of gaussian pulse peak
    width = 10;     %peakyness of gaussian pulse

    %% Initialise the H and E array
    H = zeros(2*numX, 2*numY);       
    Hp = zeros(2*numX, 2*numY);
    E = zeros(2*numX+1,2*numY+1);    
    Ep = zeros(2*numX+1,2*numY+1);    
    Etemp = zeros(2*numX+1,2*numY+1);
    Htemp = zeros(2*numX, 2*numY);
    P = zeros(2*numX+1,2*numY+1);
    Pp = zeros(2*numX+1,2*numY+1);

    % Scaling factors for H and E fields

    CEx = dt/(dx*mu0);
    CEy = dt/(dy*mu0);
    CHx = dt/(dy*e0);
    CHy = dt/(dx*e0);
    x = 2:2:2*numX; %2*numX-2;

    %Initialize Permibilities
    Perm = ones(2*numX+1,2*numY+1);


    %% FDTD loop
for n = 1:1500;

    if(n < 200)
        E(numX-10:2:numX+10,numY+1) =  1E-19*sin(2*pi*428E12*n*dt);    %exp(-.5 * ((n-t0)/width).^2); %insert hard source
    end;

    for u = 2:2:2*numX-1
        for v = 2:2:2*numY-1
            Hp(u,v) = H(u,v) + (dt/mu0)*( -(E(u+1,v) - E(u-1,v))/dx) + ( E(u,v+1) - E(u,v-1)/dy ); % Solving for Hplus
            Ep(u,v+1) = E(u,v+1) + (dt/(dy*e0))*(Hp(u,v+2) - Hp(u, v)); % Solving for Ex plus
            Ep(u+1, v) = E(u+1, v) - (dt/(dx*e0))*(Hp(u+2, v) - Hp(u, v)); % Solving for Ey plus

        end
    end;


    % Dirichlet Boundary Conditions
    Ep(1,:) = 0;
    Ep(:,1) = 0;
    Ep(2*numX+1,:) = 0;
    Ep(:,2*numX+1) = 0;

    % Plotting
    surf(Ep); shading interp; lighting phong; colormap hot; axis off; zlim([0 1]);
    set(gcf,'Color', [0 0 0], 'Number', 'on', 'Name', sprintf('FDTD Project, step = %i', n));
    %title(sprintf('Time = %.2f microsec',n*dt*1e12),'Color',[1 0 0],'FontSize', 22); 
    drawnow;

    E = Ep;
    H = Hp;



end;

end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:25:51+00:00Added an answer on May 22, 2026 at 2:25 am

    2 things:

    1 – is Ep(:,2*numX+1,:) = 0; correct? (i.e. should it be Ep(:,2*numX+1) = 0;?)

    2 – at the very end, I think you may want to change the code to

    if (max(max(Ep)) > 1e-3)
          E = Ep/max(max(Ep));
    else E = Ep;
    end
    if (max(max(Hp)) > 1e-3)
        H = Hp/max(max(Hp));
    else H = Hp;
    end
    

    as max(Ep) will give you a 1×100 matrix. 1e-3 is for protection, you can lower it to whatever value you choose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you guys had any experiences (positive or negative) by placing your source code/solution
Have any one run into trouble when running dotLess and having hacks on your
Have not done this before, so obviously I suck at it. Here 64 pixels
Have not done this before ( except in java , look how Steve McLeod
Have run into a bug with glibc's malloc(): http://sourceware.org/bugzilla/show_bug.cgi?id=4349 and am thinking a work
Have you ever been frustrated by Visual Studio not re-evaluating certain watch expressions when
Have a bit of problem with the jQuery clone() functionality. Basically I have a
Have added the following code to my SQL query: (Note cut down version) DECLARE
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.