Home
Insert
Update snippet 'Calculate PI using Monte Carlo'
Title
Description
Estimate the value of PI using a Monte Carlo simulation.
Source code
open Fmat.Numerics open Fmat.Numerics.MatrixFunctions open Fmat.Numerics.BasicStat let calcPi n = let x = rand [1;n] let y = rand [1;n] let d = x .* x + y .* y let circ = new Matrix(d .< 1.0) let m = sum(circ,1) float(m)/(float)n*4.0 let pi = calcPi 4000000
Tags
monte carlo
simulation
math
pi
monte carlo
simulation
math
pi
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update