Monte Carlo methods: Difference between revisions

Content added Content deleted
Line 610: Line 610:
end program
end program


function pi(nsamples)
function pi(n)
integer :: nsamples
integer :: n
real(8) :: x(2,nsamples)
real(8) :: x(2,n),pi
real(8) :: pi
call random_number(x)
call random_number(x)
x = 2.d0*x - 1.d0
pi = 4.d0 * dble( count( hypot(x(1,:),x(2,:)) <= 1.d0 ) ) / n
pi = 4.d0 * dble( count( hypot(x(1,:),x(2,:)) <= 1.d0 ) ) / nsamples
end function
end function
</lang>
</lang>