0
votes

I want to calculate count of outside points which are not in the circle. But I got this problem. My circle is unit circle.My Error is this : The temporary variable outside will be cleared at the beginning of each iteration of the parfor loop.

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
1
What problem? You just dumped your code here. What is your question? - Adriaan
I have just edited - Bertug

1 Answers

0
votes

It looks like you're trying to treat outside as a parfor reduction variable. You cannot access the intermediate values of reduction variables during the loop - you can only perform the reductions. In other words, the line fprintf('%f', outside) is causing the problem, you must remove this for the parfor loop to work.

Also note that workers operating on the body of your parfor loop cannot display graphics to your desktop, so your plot calls will not show anything on-screen. (You can use print to emit graphics to a file if you wish).