function [mpi] = vypocet_pi2(N)

suma = 0;

t = 0:0.01:2*pi;
subplot(2,1,1)
plot(cos(t),sin(t))
axis equal
axis tight
hold on
chyba = ones(N,1)*NaN;

for i = 1:N
    x = rand*2 - 1;
    y = rand*2 - 1;
    if(abs(x^2+y^2) < 1)
        suma = suma + 1;
    end
    mpi = suma / i * 4;
    subplot(2,1,1)
    plot(x,y,'r.')
    title(['Aktualni hodnota pi je ' num2str(mpi)])
    drawnow
    subplot(2,1,2)
    chyba(i) = abs(mpi-pi);
    semilogy(chyba)
end

subplot(2,1,1)
hold off
