! From: "COMPUTATIONAL PHYSICS, 2nd Ed" ! by RH Landau, MJ Paez, and CC Bordeianu ! Copyright Wiley - VCH, 2007. ! Electronic Materials copyright: R Landau, Oregon State Univ, 2007; ! MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. ! Supported by the US National Science Foundation ! ! int - 10d.f90: Ten dimensional integration using Monte - Carlo Program int10d Implicit none Integer :: m = 16, k ! number of trials Real*8 :: s, integ(16) s = 0. Do k = 1, m call montecarlo(integ, k); s = s + integ(k) End Do write(*, *) s/m End Program int10d subroutine montecarlo(integ, k) Implicit none Integer :: i, j, k, max = 65536 Real*8 :: x, y, sum, ranDom, integ(16) x = 0. y = 0. sum = 0. Do i = 1, max x = 0 ! reset x ! sum 10 x values Do j = 1, 10 x = x + ranDom() End Do ! square and sum up y = y + x*x sum = sum + y/i; End Do integ(k) = sum/max write(*, *) k, integ(k) End