---------------------------------------------------
% Monte Carlo computation of pi.
r = 5; % repearing time
count = 0;
n= 100;
for l =1:r,
for i=1:n,
x = rand ; y = rand ; % Generate random points
if (x-.5)^2 + (y-0.5)^2 <= .25, % general solution for any circle
count = count + 1;
end;
end;
pi_value = 4*(count/1000); % pi value
err = pi - pi_value,
x = [0:.100:100000];
plot(x,err,'rx');
n*10;
end;
%fprintf('\Error: %f' ,err);
fprintf('\nExtimated pi value : %f\n\n' ,pi_value)
------------------------------------------------
mcn mata oke n ta 100, 1000,10000,100000 oya agayan ena kota e eka eka situation eke pi value calculate wena one.
ita pase err eka hoyala plot this err against the value of n. mata mee cording eka modifi krala denawada?
Forward Message