% script para calcular o pi por Monte Carlo
function [ pi_mc, x, y, D ] = pi_por_mc( N )

x = rand(N,1);
y = rand(N,1);
D = (x.^2 + y.^2);
pi_mc = 4 * sum( D<=1 ) / N;

if nargout==0
    figure
    plot( x(D<=1), y(D<=1), '*b' )
    hold on
    plot( x(D>1), y(D>1), '*r' )
    ang = 0:.01:pi/2;
    plot( cos(ang), sin(ang), '--k', 'linewidth', 3 )
    clear pi_mc
end