Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.Random
- import Control.Monad (forM)
- import Text.Printf (printf)
- gamma = 0.98
- tGamma = 2.326
- a = 7
- k = 6
- c = 6.85
- fk x = log (1 + a * x)
- f x = if ((sum (fmap fk x)) <= c) then 1.0 else 0.0
- mc :: [a] -> (a -> Double) -> Double
- mc lst func = sum (fmap func lst) / fromIntegral (length lst)
- splitEvery :: Int -> [a] -> [[a]]
- splitEvery _ [] = []
- splitEvery n ls = (fst sp):(splitEvery n (snd sp)) where
- sp = splitAt n ls
- countVolume :: Int -> IO ()
- countVolume n = do
- putStrLn $ printf "n = %d" n
- let p = mc (take n $ splitEvery k (randoms (mkStdGen 42) :: [Double])) f
- putStrLn $ printf "p_n = %.8f" p
- let d = tGamma * sqrt(p * (1 - p) / fromIntegral n)
- putStrLn $ printf "d_n = %.8f" d
- putStrLn $ printf "Interval = [%.8f, %.8f]" (p - d) (p + d)
- main = mapM countVolume [10 ^ 4, 10 ^ 6]
Advertisement
Add Comment
Please, Sign In to add comment