Coding Challenge 95: Approximating the Value of Pi

preview_player
Показать описание


References:

Videos:

Related Coding Challenges:

Timestamps:
0:00 Approximating PI
0:48 Suggestion from akraus53
1:43 Methodology
7:31 Let's code!
13:30 Determine number of "darts" in the circle
18:20 Casting to doubles to increase precision
22:07 Keep track of current best estimate
26:30 Suggestions and conclusion

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

#montecarlo #estimatingpi #processing
Рекомендации по теме
Комментарии
Автор

24:50
Ah yes.
Pi.
1.415926.
That's the one.

snaskkartong
Автор

TCT at 01:50: "I can't draw circles"
TCT at 02:00: * _draws a surprisingly good circle_ *

Nice, you reverse-jinxed it!

achtsekundenfurz
Автор

If you're only checking the individual pixels, you only need to test 160, 000 positions for pi (400x400). So nest a counting loop for X (1 to 400) inside a counting loop for Y (1 to 400) and test each pixel in only 160, 000 iterations.

No need for random numbers.

LeroyWiley
Автор

It is actually called "Monte Carlo method"

anatoliikorol
Автор

You could have tried to increase number of pixels. I think the randomness actually gave better results. In fact 400x400 = 160000 pixels, if all the pixels are counted (without randomness) the number of pixels inside the circles are 160000 / pi ~= 50.929 so the error of the ratio is 160000/50929 = 3.1416 already at the fourth figure. But I don't know I didn't tried XD

skid
Автор

The fact that he has to get this deep into pi just for a video is phenomenal. Keep it up dude.

justinflowers
Автор

13:12 Float is actually not a floating point decimal number, it is a floating point binary number. Most of the time, the behavior of binary numbers is ok for what we use them for. But sometimes, it is not (banks do not use binary numbers for example, they actually use computed decimal algebraic numbers). In this last case however, computing speed of such numbers is really slower than computing speed of binary numbers.

axelpaccalin
Автор

I wonder if your estimations would have been marginally closer if you had used "if (d <= r * r)" instead. For instance, if the radius is 200 and you pick a point exactly 200 distance away from the origin, then that point would be ON the perimeter of the circle since it is exactly radius units away. That makes me thing that your estimation could be slightly improved, but only by a fairly inconsequential amount.

Keirathi
Автор

We practise this in my university, it's a Monte Carlo simulation about this same problem, we have to program it in C and make it multithreading using OpenMP.

ganstabreakincity
Автор

You can do this but remove the randomness. Compute y for each x on 1/4 of the unit circle. The more values of x you compute for (at regular intervals the more accurate your result. It is not random and always converges. You could perform recursive interlaced sampling to progressively refine your answer without discarding results. Note it is the average ratio of y/1 that you're looking for (equivalent of area on the unit square). I think this a kind of Newton's method, especially if your recursively refine (interlace over x). 1/4 circle will speed convergence unlike the Monte Carlo sampling.

dorbie
Автор

"If you were to look up"
*looks up*
"circumference of a circle"
We've been tricked, we've been backstabbed and we've quite possibly been bamboozled

RubyPiec
Автор

Soo you used pi to calculate pi accurately ... Nice.

sujaankumar
Автор

You are my favorite guy on the internet. I wish I knew you personally. I’d suspect you’d make any of my days brighter. You = 👍

ryanbrown
Автор

You could also use area of a polygon to approximate the area of a circle and increase the number of sides.

paherbst
Автор

Send astronauts to the moon using the results of this estimation. If they live, you win!

kevnar
Автор

The fact that he explain me this in a unicorn shirt makes me even more comfortable

hellboy
Автор

THIS IS EXACTLY WHAT I WANTED!!! Thank you so much

pixelgames
Автор

Oh boy, I was just working on a monte carlo approximation (for a hard double integral) and I just knew by looking at the thumbnail that you were using it !!!

Monte carlo is a cool method, plus I always feel like I'm some sort of rich gambler at a casino roulette while working on it :p

furrane
Автор

Man, this channel is incredible. Thanks! Watching all your videos! You're so fun.

JesseLokaum
Автор

Another approach that just came in to my mind would be to "draw" a triangle where sides A and B are equal to R, and gamma (the angle between A and B) would be 360/X where X equals any multiple of 360 (x1, x2, .. x5, .. x100, ... depending on how you would like your accuracy/resolution). After that you find the length of missing side C and multiply it by X getting an estimated circumference of your circle (think of drawing an octagon but with way more sides). From there you can calculate estimated PI.

aidennymes