Monte Carlo methods: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: give pc to three decimal places)
Line 1,515: Line 1,515:
<lang jq>def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
<lang jq>def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;


def percent: "\(10000 * . | round / 100)%";
def percent: "\(100000 * . | round / 1000)%";


def pi: 4* (1|atan);
def pi: 4* (1|atan);
Line 1,541: Line 1,541:
Iterations -> Approx Pi -> Error
Iterations -> Approx Pi -> Error
---------- ---------- ------
---------- ---------- ------
10 2.4 23.61%
10 2.8 10.873%
100 3.2 1.86%
100 3.28 4.406%
1000 3.192 1.6%
1000 3.172 0.968%
10000 3.1012 1.29%
10000 3.1456 0.128%
100000 3.14772 0.2%
100000 3.13316 0.268%
1000000 3.141632 0%
1000000 3.139956 0.052%
</pre>
</pre>