Monte Carlo Integration - π

author: Vinicius Placco (http://vmplacco.github.io/)


A very simple (and illustrative) exercise in estimating the value of π with a
Monte Carlo method. This contains 1.6 million points randomly generated inside a
square of size 1.0. The final accuracy is lower than 0.002%.


Made with R + bash + gnuplot + convert + ffmpeg
terminal one-liner to estimate π: > a=1000000 > paste <(jot -r -p 10 $a -0.5 0.5) \ <(jot -r -p 10 $a -0.5 0.5) | awk '($1^2+$2^2)<=0.5^2' | wc -l | xargs | awk -v a=$a '{print ($1*4)/(a)}' > 3.14176