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
Fdtd matlab simulation problem
Hi. Im trying to simulate a 4th order accurate in space equations but its not working. For 2nd order its working. Here is my code
len=100;
i=zeros(1,len+2);
v=zeros(1,len+2);
dz=0.01;
c=0.1;
l=250;
dt=dz*5;
for n=1:2000
t=n*dt;
for k=3:len+1
v(k)=v(k)-(dt/(c*24*dz))*(i(k-2)-(27*i(k-1))+(27*i(k))-i(k+1));
end
v(1)=sin(2*pi*t);
v(len)=0;
for k=2:len
i(k)=i(k)-(dt/(l*24*dz))*(v(k-1)-(27*v(k))+(27*v(k+1))-v(k+2));
end
plot(v);
axis([0 len -5 5]);
frame = getframe;
end
Anyone knows whats wrong or have a similar code to see it?
Hi. Im trying to simulate a 4th order accurate in space equations but its not working. For 2nd order its working. Here is my code
len=100;
i=zeros(1,len+2);
v=zeros(1,len+2);
dz=0.01;
c=0.1;
l=250;
dt=dz*5;
for n=1:2000
t=n*dt;
for k=3:len+1
v(k)=v(k)-(dt/(c*24*dz))*(i(k-2)-(27*i(k-1))+(27*i(k))-i(k+1));
end
v(1)=sin(2*pi*t);
v(len)=0;
for k=2:len
i(k)=i(k)-(dt/(l*24*dz))*(v(k-1)-(27*v(k))+(27*v(k+1))-v(k+2));
end
plot(v);
axis([0 len -5 5]);
frame = getframe;
end
Anyone knows whats wrong or have a similar code to see it?
Last edited: