Skip to content

Commit 1a34a46

Browse files
authored
fixing julia function to output pi estimate (#710)
1 parent 370f717 commit 1a34a46

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

contents/monte_carlo_integration/code/julia/monte_carlo.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ function monte_carlo(n::Int64)
2323
# The formula is pi = (box_length^2 / radius^2) * (pi_count / n), but we
2424
# are only using the upper quadrant and the unit circle, so we can use
2525
# 4*pi_count/n instead
26-
pi_estimate = 4*pi_count/n
27-
println("The pi estimate is: ", pi_estimate)
28-
println("Percent error is: ", signif(100 * abs(pi_estimate - pi) / pi, 3), " %")
26+
return 4*pi_count/n
2927
end
3028

31-
monte_carlo(10000000)
29+
pi_estimate = monte_carlo(10000000)
30+
println("The pi estimate is: ", pi_estimate)
31+
println("Percent error is: ", 100 * abs(pi_estimate - pi) / pi, " %")

0 commit comments

Comments
 (0)