Help with FDTD (2,4) program

Status
Not open for further replies.

kotsoss

Newbie level 4
Joined
Apr 20, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
Hi, I think that my fdtd program doesnt work properly. It is 4th order in space and 2nd order in time.
In 2th order in space my programworks correct.

Code:
L=100;
i=zeros(1,L);
v=zeros(1,L;

dz=0.01;
c=0.1;
l=250;


dt=dz*sqrt(l*c);




for n=1:2000
   t=n*dt;

    
    for k=1:L-1   
        if k==1
           v(k)=v(k)-dt/(c*dz)*(i(k+1)-i(k));
        elseif k==L-1
            v(k)=v(k)-dt/(c*dz)*(i(k+1)-i(k));
        
        else
            v(k)=v(k)-(((6/7)*dt)/(c*24*dz))*(i(k-1)-(27*i(k))+(27*i(k+1))-i(k+2));
        end
    end
    
    

    v(1)=sin(2*pi*t);
 
    v(st)=0;          
  
  
    for k=2:L
        if k==2
            i(k)=i(k)-dt/(l*dz)*(v(k)-v(k-1));
        elseif k==st
            i(k)=i(k)-dt/(l*dz)*(v(k)-v(k-1));
        else
            i(k)=i(k)-(((6/7)*dt)/(l*24*dz))*(v(k-2)-(27*v(k-1))+(27*v(k))-v(k+1));
        end
    end
    

    plot(v);
    axis([1 L -3 3]);
    
    frame = getframe;
   
end


Anyone knows whats wrong?

Anyone have a 4th order in space fdtd code? I searched and I didnt find anything.

Here is the results (in the red circle u can see the error):
 

Attachments

  • χωρίς τίτλο.JPG
    12.3 KB · Views: 71

Anyone have a 4th order fdtd code?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…