Skip to content

Commit 045fb52

Browse files
Wesley-Arringtonleios
authored andcommitted
Updating Error Calculation for Monte Carlo in Javascript (#372)
1 parent 471fd95 commit 045fb52

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: contents/monte_carlo_integration/code/javascript/monte_carlo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function monteCarlo(n) {
2323
// 4*piCount/n instead
2424
// piEstimate = 4*piCount/n
2525
const piEstimate = 4 * piCount / n;
26-
console.log('Percent error is: %s%', 100 * (Math.PI - piEstimate) / Math.PI);
26+
console.log('Percent error is: %s%', 100 * Math.abs(piEstimate - Math.PI) / Math.PI);
2727
}
2828

2929
monteCarlo(100000000);

0 commit comments

Comments
 (0)