Late to the party but here's a simple monte carlo simulation visualized

using Reactive, Interact, Compose
randpoint() = (rand(), rand())
isin(x, y) = 0.25 > (x-0.5)^2 + (y-0.5)^2
Compose.set_default_graphic_size(8inch, 8inch)

@manipulate for switch=false,
    t=fpswhen(switch, 10),
    point=lift(x -> randpoint(), t),
    points=foldl(push!, Any[randpoint()], point),
    incount=foldl((x, y) -> x + isin(y...), 1, point),
    count = foldl((x, y) -> x+1, 1, point)

    compose(context(),
        (context(), text(0, 0.1, "π ≊ $(4*incount/count)")),
        [(context(), fill("red"), circle(x, y, 0.005)) for (x, y) in
points]...,
        (context(), fill("lightblue"), circle()))
end

Also http://arxiv.org/pdf/1404.1499v2.pdf ;)

On Sun, Mar 15, 2015 at 6:01 AM, David P. Sanders <dpsand...@gmail.com>
wrote:

>
>
> El sábado, 7 de marzo de 2015, 11:59:47 (UTC-6), Alan Edelman escribió:
>>
>> With about a week left, I'd love to find out how many digits of  π  we
>> can get only from Julia.
>>
>> Perhaps we can coordinate a worldwide distributed computation this week.
>>
>>
>>
> In a different direction, it seems not to be well known that we can
> calculate *rigorous bounds*
> on π using just floating-point aritmetic. I have made an example notebook
> that may be viewed here:
>
> http://nbviewer.ipython.org/gist/dpsanders/3e69e4a2d4f5b5727258
>
> [Comments of course welcome!]
>
> Best,
> David.
>
>
>

Reply via email to