Created
May 22, 2012 21:48
-
-
Save kirelagin/2771862 to your computer and use it in GitHub Desktop.
Teorver task1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Functor | |
import System.Random | |
import System.Random.Mersenne.Pure64 | |
import Text.Printf | |
import Statistics.Distribution (quantile) | |
import Statistics.Distribution.Normal | |
import Statistics.Distribution.Uniform | |
gamma = 0.98 | |
k = 6 | |
c = 13.8 | |
a = 4 | |
f = (a**) | |
fF = sum . map f | |
main = do | |
-- Хороший генератор случайных чисел (вихрь Мерсенна) | |
gen <- newPureMT | |
let n = 10^4 | |
points = take n $ randomPoints gen | |
vals = fF <$> points | |
s = (fromIntegral . length $ filter (<= c) vals) / (fromIntegral n) -- <- вероятность попадания (она же искомая площадь) | |
interval = (quantile standard ((gamma+1) / 2)) * (sqrt $ s*(1-s)) / (sqrt $ fromIntegral n) -- <- доверительный интервал | |
putStrLn $ printf "n = %d: %.4f ± %.4f (%.2f%%)" n s interval (interval/s * 100) | |
randomPoints :: RandomGen g => g -> [[Double]] | |
randomPoints gen = splitList $ randomRs (0, 1) gen | |
where splitList l = let (v, r) = splitAt k l in v : splitList r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment