September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
19
Task/Monte-Carlo-methods/F-Sharp/monte-carlo-methods.fs
Normal file
19
Task/Monte-Carlo-methods/F-Sharp/monte-carlo-methods.fs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
let print x = printfn "%A" x
|
||||
|
||||
let MonteCarloPiGreco niter =
|
||||
let eng = System.Random()
|
||||
let action () =
|
||||
let x: float = eng.NextDouble()
|
||||
let y: float = eng.NextDouble()
|
||||
let res: float = System.Math.Sqrt(x**2.0 + y**2.0)
|
||||
if res < 1.0 then
|
||||
1
|
||||
else
|
||||
0
|
||||
let res = [ for x in 1..niter do yield action() ]
|
||||
let tmp: float = float(List.reduce (+) res) / float(res.Length)
|
||||
4.0*tmp
|
||||
|
||||
MonteCarloPiGreco 1000 |> print
|
||||
MonteCarloPiGreco 10000 |> print
|
||||
MonteCarloPiGreco 100000 |> print
|
||||
Loading…
Add table
Add a link
Reference in a new issue