Does this code crash your matlab?
이전 댓글 표시
The following code segaults Matlab x64 7.14.0.739 (R2012a) on my Linux x64 3.7.9 box.
The algorithm maybe wrong, but the segfault makes me sad.
I suspect it is due to crazy values i'm passing to the draw function.
Can somebody verify?
%%Simple 2D
clear all;
clc;
pml=1;
gridSx = 100;
gridSy = 110;
Ez = zeros(gridSx,gridSy);
Hx = zeros(gridSx,gridSy);
Hy = zeros(gridSx,gridSy);
denx = ones(gridSx,1);
deny = ones(1,gridSy);
S=0.50/(1/sqrt(2) + 1/sqrt(2));
n=377;
Cav=1;
Cbv=ones(gridSx,gridSy);
Dav=1;
Dbv=ones(gridSx,gridSy);
s=1000;
%%Settings
dx=1E-3;
dy=dx;
vlight=3*10^8;
epsilon = 8.854*10^-12;
mu_naught=4*(pi)*1E-7;
sigmaE = 0.001;
dt = 0.95 / (vlight * sqrt((1.0 / (dx*dx)) + (1.0 / (dy*dy) )));
Cav=Cav*1;
Cbv=Cbv*((dt / epsilon) / (1.0 + sigmaE * dt / (2.0 * epsilon)));
Dav=Cav*1;
Dbv=Dbv*(dt / mu_naught);
%%Process
%E sourounded by H
draw =1;
for i=1:s
%Update Ez
for x=1:(gridSx-1)
%left to right
Ez(x,:)=Cav*Ez(x,:)+(S*n)*Cbv(x,:).*deny.*(( Hy(x+1,:)- Hy(x+0,:) ));
end
for y=1:(gridSy-1)
%top to bottom
Ez(:,y)=Cav*Ez(:,y)+(S*n)*Cbv(:,y)'*denx.*(( Hx(:,y+0)- Hx(:,y+1) ));
end
%Update Hx
for y=2:(gridSy-0)%top to bottom
Hx(:,y)=Dav*Hx(:,y)+(S/n)*Cbv(:,y)'*denx.*(( Ez(:,y-1)- Ez(:,y+0) ));
end
%Update Hy
for x=2:(gridSx-0)
Hy(x,:)=Dav*Hy(x,:)+(S/n)*Cbv(x,:).*deny.*(( Ez(x+0,:)- Ez(x-1,:) ));
end
%%%%%%%%%%%%%%%%%%%%%%
type = 1;
source=0;
ramp =120;
switch(type)
case 1
source= exp(-((i-ramp)^2)/100);
case 2
source= sin(i*pi/ramp);
case 3
if (i<(ramp+1))
source= sin((i-1)*pi/ramp);
end
end
%
Ez(gridSx/2,gridSy/2) =Ez(gridSx/2,gridSy/2)+5*source;
%
if (draw==1)
surf(Ez); shading interp; lighting phong; colormap hot; axis off; zlim([-1 1]);
set(gcf,'Color', [0 0 0], 'Number', 'off', 'Name', sprintf('FDTD, step = %i', i));
title(sprintf('FDTD step = %i',i),'Color',[1 0 0],'FontSize', 22);
drawnow;
end
end
%plot(fun);
채택된 답변
추가 답변 (1개)
Walter Roberson
2013년 3월 20일
0 개 추천
Yes, it crashes R2013a on my Mac, apparently after FDTD step 33.
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!