2016-12-14 52 views
0

我想计算不在圆圈内的外部点数。但我有这个问题。我的圈子是单位圈。我的错误是:外部临时变量将在parfor循环的每个迭代 开始时被清除。使用带有临时变量的parfor

function [ ] = girkoson(N,n) 
%UNTİTLED Summary of this function goes here 
% Detailed explanation goes here 
hold on 
outside = 0; 
parfor i=0:N 
    E=ones(N,n); 
    karekok = sqrt(n); 
    E = [E, eig(randn(n))/karekok]; 
    a=real(E); 
    b= imag(E); 
    plot(a,b,'.r'); 
     if (a>= -1) | (a<=1) | (b>=-1) | (b<=1) 
     outside = outside +1; 
     fprintf('%f',outside); 
     end 
end 

derece=0:0.01:2*pi; 
xp=1*cos(derece); 
yp=1*sin(derece); 
x=0;y=0; 
plot(x+xp,y+yp,'-b'); 
hold off 
end 
+0

什么问题?你只是在这里丢弃你的代码。你的问题是什么? – Adriaan

+0

我刚刚编辑 – Bertug

回答

0

它看起来像你试图把outsideparforreduction变量。循环期间无法访问还原变量的中间值 - 只能执行还原。换句话说,行fprintf('%f', outside)是造成这个问题,你必须删除这个parfor循环工作。

另请注意,在您的parfor循环体上操作的工作人员无法在桌面上显示图形,因此您的plot调用不会在屏幕上显示任何内容。 (如果您愿意,您可以使用print将图形发送到文件)。

+0

我没有使用打印,因为情节可以显示圆和点。 – Bertug