Happy Pi Day! Animated with: The Manim Community Developers. (2021). Manim - Mathematical Animation Framework (Version v0.12.0) [Computer software]. www.manim.community/
Пікірлер: 277
@nubdotdev2 жыл бұрын
A number of people have asked to see the code for this approximation, so here's an implementation in Python: from random import random total = 3141 count = 0 for i in range(total): x = random() y = random() if x*x + y*y
@piedepew2 жыл бұрын
You from which university bro?
@mainios126bobeats42 жыл бұрын
A one liner I made (with some code to print the result nicely): from random import random from math import pi total = 1000000 def approximate_pi(total): return 4 * sum(random() ** 2 + random() ** 2
@__lasevix_2 жыл бұрын
@@mainios126bobeats4 you should implement the function as a lambda
@mainios126bobeats42 жыл бұрын
@@__lasevix_ When I said one-liner I wasn’t referring to the whole approximate_pi, I meant the code inside. But here: from random import random approximate_pi = lambda total: 4 * sum(random() ** 2 + random() ** 2
@aronbucca67772 жыл бұрын
By the fundamental theorem of engineering pi is equal to three, it's simple
@natedor77392 жыл бұрын
i am completely amazed at the fact that this is not extremely popular considering how clean this editing and explanation is
@nubdotdev2 жыл бұрын
Thanks a lot!
@quintium12 жыл бұрын
@@jay1373 Not the method, but the video
@dfsgjlgsdklgjnmsidrg2 жыл бұрын
thats because there is no way without a quantum computer to generate true random numbers, therefore this experiment is always biased
@direwolf272 жыл бұрын
Newton did it better with calculus and Pascal's triangle
@LymiaKanokawa2 жыл бұрын
@@dfsgjlgsdklgjnmsidrg Most modern CPUs contain a hardware RNG that uses quantum mechanical effects to generate the raw randomness. This is demonstrably false, and a lot of our current internet security relies on the fact that this is demonstrably false.
@joebykaeby2 жыл бұрын
“A bit over 3,000,” you say. That wouldn’t be 3,141 by chance?
@lyrimetacurl02 жыл бұрын
4000 would have been better since then the result should be ~ 3142/4000 (it rounds up)
@rupert_14912 жыл бұрын
You actually counted it
@flotzle36852 жыл бұрын
@@rupert_1491 No, that's what pi is lol
@silenceisgolden17582 жыл бұрын
0:44 top left shows it
@almostperfectbruh35172 жыл бұрын
bro did you just count all of them
@rjms062 жыл бұрын
"A bit over 3000" I see what you've done here
@nubdotdev2 жыл бұрын
;)
@johnchristian77882 жыл бұрын
Can someone please explain the joke?
@realmarce2 жыл бұрын
@@johnchristian7788 Pi is a bit over 3 Its not that hard to understand
@maiq_68212 жыл бұрын
@@realmarce your reason for lacking bitches is also not hard to understand
@vari15352 жыл бұрын
@@johnchristian7788 They used 3141 points, which is the integer part of 1000π
@abdullahaddous70812 жыл бұрын
That's great. One thing I find interesting is how points are meant to be dimension less, yet we use them to approximate area.
@pigmounterboardriver28392 жыл бұрын
It's not area it's a ratio
@xGOKOPx2 жыл бұрын
@@pigmounterboardriver2839 Yes, ratio of areas.
@milaanvigraham86642 жыл бұрын
That's kind of like saying dy/dx has two dimensionless entities (both numerator and denominator) but we use it to know the rate of change/slope of a real quantity. Interesting thought you brought up, but it's quite intuitive. It's not the dimensions of the point that matters - it's the probability that it will lie within the area vs out - the point's dimensions don't matter, but these areas'
@MattMcIrvin3 ай бұрын
It's interesting to think about. The points are dimensionless, but the probability density has "per unit area" units, and that's where the area comes in.
@QwertierMannier-yp2hbАй бұрын
Infinite points make lines, infinite lines make area. Limiting to infinite points approximated area
@mrK290112 жыл бұрын
I may be a lil bit of a geek. But I still do this from time to time just for fun. Especially on Pi day even though I am a medical student now my passion for mathematics has never faded😂. Subscribed🙂🙂🙂
@vishwarao60644 ай бұрын
Woah its the opposite for me
@primenumberbuster4042 жыл бұрын
This is basic Monte carlo sampling.
@primenumberbuster4042 жыл бұрын
@@coreyhollaway7368 Math is suppose to be hard and nothing to feel embarassed. It keeps getting hard as you climb the ladder. Just give enough time. Also, I don't always recommend self study for Math because in most cases you get to miss a lot of interesting problem solving techniques, intuition and proper mindset. This could be avoided if you get yourself a very good mentor. Think this like a olympic mental sport. That's why Math Olympiad coaches exist.
@panzerkampfwagentigerausfb63782 жыл бұрын
You did a great job Justin! It's always cool to learn something random here and there, I already can see myself telling this to a random friend at a party lmao.
@playify55382 жыл бұрын
POV: you were trying to find some anime videos but you get this in your Recommended
@pafnutiytheartist2 жыл бұрын
We actually coded this for CS class a few years back. Good times
@drenz15232 жыл бұрын
How is this channel and the video not that popular already?
@revenevan112 жыл бұрын
Just found your channel and subscribed, I hope you keep making stuff like this from time to time!
@yuma93252 жыл бұрын
commenting for the algorithm, this is some amazing stuff!
@frankineskinecense2 жыл бұрын
This is how schools should teach maths. They have to visualize it and explain how a certain formula is made.
@randomguyeverywhere65352 жыл бұрын
Props to those people who actually counted the dots.
@clashoclan33712 жыл бұрын
The computers counts it.
@janni45412 жыл бұрын
It would be also very interesting to see this method compared to a method using evenly spaced dots and comparing them! This would also raise the question at what number of points one is more exact than the other.
@FM12342 жыл бұрын
This was actually a challenge to approximate pi in python during my first year first semester class on programming
@thecandybarbandit68872 жыл бұрын
Imagine losing count of your dots
@corbi06Ай бұрын
you can also get rid of a random: count = 0 rad = 1000 total = (rad*2)**2 for x in range(rad*2): for y in range(rad*2): if (x-rad)**2 + (y-rad)**2
@garrettrhoads63292 жыл бұрын
I saw this and thought “huh, I could code that…” and then I did… it’s been four hours
@kienthanhle62302 жыл бұрын
you sucks at implementation then lol
@mhmd-mc1132 жыл бұрын
If you want help, I'll gladly do
@garrettrhoads63292 жыл бұрын
Nah thx tho I managed to make it with turtle and a pure math one that’s much more efficient, this also lead me to make a reimman sums pi approximation which dispute not being as cool is much more accurate and practical
@mhmd-mc1132 жыл бұрын
@@garrettrhoads6329 if you want fun ways to calculate pi, find the probability of 2 random numbers being coprime (coprime meaning with a gcd -greatest common factor- of 1)
@garrettrhoads63292 жыл бұрын
@@mhmd-mc113 wouldn’t you need a nested for loop to do that? is there a way that’s more efficient using recursion or something?
@chayanaggarwal34312 жыл бұрын
Well umm you could this by just integraring on a quarter unit circle and equate it with binomial expanded form of the same integral and then you could calculate pie on any order you want (I know what he did in the video was kind of integration only )
@aarnavsood282 жыл бұрын
Title says "random way to calculate pi", not the best way. There are many many ways to approximate its value and what you're saying is exactly what Newton did.
@davidtatum86822 жыл бұрын
I was with you for like 5 seconds. Then my brain liquefied and ran out of my nose
@jurekis91772 жыл бұрын
THIS kind of stuff should be in my school on Pi Day
@clashoclan33712 жыл бұрын
I don't think you should give computer science topics in highschool, they probably don't even know pre-calc.
@GynxShinx2 жыл бұрын
Yeah, I did this in an Excel spreadsheet when I had nothing to do at work.
@zachwaldron71462 жыл бұрын
I wish i knew what he was talking about. Understanding maths seems cool
@danielttk86822 жыл бұрын
I'm subscribed, I need more math in my life
@gregfeneis6092 жыл бұрын
Totally appropriate that the Pi-thagoras' theorem is used for this.
@cy832 жыл бұрын
Theres actually a full lengthed video made by Joma that talks about this!
@SophieJMore2 жыл бұрын
Do points have to be randomly distributed? What if they're just arranged in a grid? Would the approximation be better this way?
@thegodsofai38452 жыл бұрын
Justin cracked at math!?!?!
@gangstaflower22622 жыл бұрын
Amazing Video !
@gamechip062 жыл бұрын
That's really cool
@clxse12 жыл бұрын
Yes , I totally agree with you.
@diegovera49622 жыл бұрын
Two weeks ago, I had to do just this, but in Matlab, for a university class XDDDDD. We started with 1,000 points, then 10,000, 100,000... It was satisfying to see how "our pi" got closer and closer to the real value
@nonstopdude1211 Жыл бұрын
i had a very wonderful pi day.. you have a wonderful pi day my "points" fella
@rajubhaimarwadi95152 жыл бұрын
But you actually count those points??? 🤯
@nubdotdev2 жыл бұрын
Well, my computer did :)
@Astromath2 жыл бұрын
He wrote a script selecting a random x and y coordinate lying inside the square. Then for every point, the code checks if x²+y²
@shanewalsch2 жыл бұрын
Write a program
@viveck12792 жыл бұрын
@@nubdotdev need that program code
@prathamkalgutkar75382 жыл бұрын
@@viveck1279 Check the Pinned Comment
@Matthew_Klepadlo2 жыл бұрын
One interesting way that I like is Fracious Viete’s method: Taking 2, plus 2 over the square root of 2, plus 2 over the square root of 2 plus the square root of 2, plus 2 over the square root of 2 plus the square root of 2 plus the square root of 2, and yadda-yadda-yadda.
@JustaReadingguy2 жыл бұрын
My calculator has a better appreciation with a single button.
@misamisamisamisa2 жыл бұрын
Cool. I figured out it won't be accurate from the start. It's too random but it's pretty close.
@Thamios2 жыл бұрын
It's more of an estimation rather a calculation
@chingchenhanji2 жыл бұрын
I remember We did this in computer science class in high school But in excel Also Joma Tech also made an explanatory video about it Wonderful, late, Pi day everyone
@ryantony55862 жыл бұрын
This is a programing interview question 😂😂😂
@_Unknown420_2 жыл бұрын
Me: yes maths My brain: 1+1=11
@VestinVestin2 жыл бұрын
Fucking implicit type conversion...
@fabriziobrutti12052 жыл бұрын
At the end, the famous Pi pie
@riceisbetterthanyou50772 жыл бұрын
wow! this is very impressive
@Doctor_Drew2 жыл бұрын
great video!
@maevesilvestrys56002 жыл бұрын
Love ❤ the video
@jfd7090Ай бұрын
No it is not close... The central limit theorem shows that these Monte Carlo methods are a fast but dirty and therefore approximate way of calculating multi dimensional integrals.
@ripleyxo6312 жыл бұрын
Pi? Numbers? What are you talking about lets get some bananas
@henrique71492 жыл бұрын
wow, thats so cool
@fatitankeris63272 жыл бұрын
Remember 3Blue1Brown making a video about this.
@cipherxen22 жыл бұрын
Denominator is already 3141
@nubdotdev2 жыл бұрын
I just chose that number because it’s pi day but you could use any sufficiently large number of points and get the same result.
@cipherxen22 жыл бұрын
@@nubdotdev Yeah. I know.
@alexp15-2 жыл бұрын
i thought it was peas in the thumbnail XD
@akankshasharma74982 жыл бұрын
I did study this in my Design and Analysis of Algorithms class
@SophiePastelz2 жыл бұрын
Very cool,
@Loading-lg6hs2 жыл бұрын
awesome vid
@Loading-lg6hs2 жыл бұрын
5.62
@abdou4alg2 жыл бұрын
I am surprised neither the video nor the comments mention that this is called Monte Carlo method
@tofaa36682 жыл бұрын
Here is another calculation of pi. Create a perfect world where no energy is lost on collision and have 1 wall and 2 blocks 1 x times heavier than the other, count how many back and forth collisions it makes and the number should be a x amount of digits of pi
@pujanmodha27492 жыл бұрын
I took just one point and i got value of pi from parallel universe
@mlembleh54512 жыл бұрын
Just in case if anyone want the code for this algorithm, it's written in javaScript so you can run the code in browser console . var n = 1000000; var ins = 0, outs = 0; for(var i = 0; i < n ;i++){ var x = Math.random(); var y = Math.random(); var z = Math.sqrt(x*x + y*y); if(z
@Siwphlhths2 жыл бұрын
should i do it on the maths finals now?
@alexvitkov2 жыл бұрын
i mean, you could just pick points uniformly, there's no need to introduce the RNG variance
@ImZyron2 жыл бұрын
I know i'm like two months late but theres a video by The Coding Train on youtube about this where he describes all this and how to code it as proof
@yoursleepparalysisdemon18282 жыл бұрын
would this be better if the points were in rows, or completely random?
@terrsus76762 жыл бұрын
I think its funny that i knew what the method would be by looking at the thumbnail 😁
@kienthanhle62302 жыл бұрын
Can I make a video about testing the accuracy of this algorithms, as well as doing some optimization on it? (I will leave the credit)
@nubdotdev2 жыл бұрын
Yeah, of course! That should be pretty interesting.
@kienthanhle62302 жыл бұрын
@@nubdotdev Thank you so much!
@lerkabishhhit2 жыл бұрын
This method isn't new, it calls Monte Carlo method, and it's accuracy is pretty bad, because method error is random value, but amounts of implantations are interesting
@kienthanhle62302 жыл бұрын
@@lerkabishhhit yeah, I've tested it with the sample size of 10^9 and the output was an astonishing 4 correct digits. Like did I do anything wrong?
@Llamaful2 жыл бұрын
How is it random? It literally uses a circle as the main calculation.
@garrettrhoads63292 жыл бұрын
The points are placed randomly in the square
@omarel-nemr65062 жыл бұрын
Cool
@oli43ssen2 жыл бұрын
I lost you after you added the dots
@jontedeakin19862 жыл бұрын
3blue1brown influence
@Bob782 жыл бұрын
Nice video, but why do they need to be in random places? Why not a uniform grid. Surely that would be even closer to pi?
@fuyalasmit2 жыл бұрын
ahh I'll better use 22/7 😌
@onelivingsoul29622 жыл бұрын
I have tried this in matlab and it took about 80,000 points to get to 4 digit accuracy
@atharvapatil6003 Жыл бұрын
Veritasium and physics girl did this experiment with using darts eight years ago They published video on 14 march 2015 And the result was shocking 3.139 with almost 0.1% of approximation error Also he did with drifting a car and using physics which is not dependent on area or circumference property of circle. That's cool though. Do anyone know any other method then tell
@Sasoon20062 жыл бұрын
This depends on how good is "random" method implementation.
@jeevankahlon55702 жыл бұрын
i love pi
@F1NALEXD2 жыл бұрын
He is speaking the Language of gods
@deepasrip95192 жыл бұрын
Him : we have to calculate pi by counting these dots . Me : π = circumference / diamerer
@Exisist51512 жыл бұрын
Aka my CS assignment last week
@oldboyiscool40402 жыл бұрын
Why is pi so ducking versatile, plop you there and put you there and dat shiz works for some reason
@JwalinBhatt10 ай бұрын
Does the numbers being "random" have any significance? What if we just took the points uniformly?
@darkzonegaming9169Ай бұрын
I think by random he meant uniform, I think what I means to be uniform is if the area and the number of dots in that area are directly proportional
@itsroman21122 жыл бұрын
Crazy
@goofybidoofie2 жыл бұрын
monte carlo moment
@DerB232 жыл бұрын
Why does the distribution have to be random? Would the result be different when using a completely even distribution in a geometric pattern?
@tempname82632 жыл бұрын
No.
@yes-mu4gr2 жыл бұрын
cool
@Dark_Matter27 ай бұрын
I see doggo in points
@--22 жыл бұрын
Now we need a proof ;)
@leothesleepingdog60552 жыл бұрын
I think i went s bit overboard putting in 69420 dots in there 😳
@chickenmonger1232 жыл бұрын
What stops the “randomization” from being derived from pi in the first place? Which is easily resolved in reverse to derive pi?
@spiderduckpig2 жыл бұрын
The randomization is not derived by pi. You can check if a point is in the circle by just seeing if x^2 + y^2 < 1 (if the radius of the circle is 1, and the center of the circle is (0, 0)).
@Shad0wWarr10r2 жыл бұрын
Why would you even need to randomize the points instead of just making a mesh with every point 0.001 between eachother
@easysolutions3312 Жыл бұрын
Now do this but the dots are people.
@elitememes72682 жыл бұрын
Did this around a year ago in computational science class tenth grade
@megamaz1082 жыл бұрын
Tried it out myself and averaged out at 2.9 no matter the amount of points :/ nvm I forgot decimals existed.
@BruH-xg5eo2 жыл бұрын
Pi pie...
@gaviningrave17312 жыл бұрын
Im just Justin Justin time for a random way to calculate pi
@sjk74672 жыл бұрын
Shouldn't similar things work for literally any shape? Draw a square, put any shape in, see what ratio of points fall in it, now you can calculate the area.
@succathog59062 жыл бұрын
Lmao I thought it was grass
@ilham-t9y2 жыл бұрын
Pie
@julianbrudka98212 жыл бұрын
lol my brother just made it as college project
@UberBossPure2 жыл бұрын
Why you use x square and y square? For what it stands? I understood r square is the circle. x*x or y*y are both getting the surface of an square. But why we use it 2 times?