Does this code crash your matlab?

1 Ansicht (letzte 30 Tage)
Mikhail  Kandel
Mikhail Kandel am 20 Mär. 2013
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);

Akzeptierte Antwort

Friedrich
Friedrich am 20 Mär. 2013
Bearbeitet: Friedrich am 20 Mär. 2013
UPDATE
It seems to be related to the renderer. Setting the renderer to opengl makes it work fine. ZBuffer seems to have some troubles with big Z values. So add
figure('renderer','opengl')
before the for loop.
Yes crashes my 13a on Win7 too.
When uncommenting the zlim([-1 1]); part it works fine.
When using opengl neverselect and keeping that zlim part, MATLAB doesn't crash, it hangs.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 20 Mär. 2013
Yes, it crashes R2013a on my Mac, apparently after FDTD step 33.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by