How To Estimate Pi Numerically In Python

  Рет қаралды 21,090

Andrew Dotson

Andrew Dotson

6 жыл бұрын

This video has nothing to do with Good Will Hunting and/or Matt Damon. Just using random sampling and monte carlo to approximate pi.

Пікірлер: 61
@XanderGouws
@XanderGouws 6 жыл бұрын
*draws circle "This is a square"
@Eniro20
@Eniro20 5 жыл бұрын
It's an approximation!
@J.P.Nery.N.
@J.P.Nery.N. 5 жыл бұрын
Parker square!
@samkonstan5254
@samkonstan5254 4 жыл бұрын
Subduralempyema the new sinx=x
@TRex266
@TRex266 6 жыл бұрын
I wrote a parallel C++ version and ran this on my Uni's computing cluster across 1000 cores with 5*10^14 sample points in total (took just under 8 hours) and I only got the first 6 digits right. Looks like it doesn't scale as well as you thought :D
@someguy9046
@someguy9046 4 жыл бұрын
"how to estimate pi" Say the word "three" Job done
@lnhostetler
@lnhostetler 4 жыл бұрын
How I approximate pi in Python: import numpy as np print(np.pi) But sure, I suppose a Monte Carlo approach works too :D
@johnchristian5027
@johnchristian5027 6 жыл бұрын
One of the first things I did when learning how to code in python was approximating pi, its a good exercise! Great Video!
@calebwhales
@calebwhales 6 жыл бұрын
Thanks for this Andrew. As someone learning Python its great to see it's very casual usages, and the lines as thought out in real time. Numerical integration would be great.
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
Awesome! Good luck with python!
@josesierra8793
@josesierra8793 6 жыл бұрын
This is awesome andrew. I dont even know anything about coding, but i enjoy math, and you make it easy to understand whats going on with your work. Excellent job, man.
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
Means a lot! THank you!
@saavestro2154
@saavestro2154 6 жыл бұрын
>"Hi and welcome to numberphile" >camera zooms in on the fase of some sperglord already covered in sweat >"Today we are going to talk about the number five" >sperglord smiles the smile of a thousand suns >drops of sweat pouring from his forehead >he writes the number five on a paper >"The amazing thing about this number is that it is a part of you" >camera zooms in on his hand that is soaked in sweat and shaking uncontrolably >"As you can see my hand contains five fingers" >a tear falls from his eye >"I would not even know what to do with myself if not for five" >looks at the camera like he is seeing god >tears of joy raining down his cheeks >In a shaky voice he says: >"Without five I couldn't even count to six!" >begins to cry
@imadmorsli2871
@imadmorsli2871 4 жыл бұрын
Based and gay
@perigrinus3133
@perigrinus3133 4 жыл бұрын
lol i saw seen this meme a while ago. thank you for reminding me of it.
@CarlosKoji87
@CarlosKoji87 6 жыл бұрын
Using the Monte Carlo Method for numerical integration would seem like a really awesome video to make. I've seen it used for the Brachistochrone problem when I was doing an experimental physics project in MatLab a couple years back.
@sjgabhane
@sjgabhane 6 жыл бұрын
Great Video!! more videos like these please
@thiagocalomino276
@thiagocalomino276 2 жыл бұрын
Cool! Helped me a lot in Numerical Methods at college, thanks. I'm from Brazil!
@anshsrivastava1059
@anshsrivastava1059 5 жыл бұрын
I increased N to be around 100000000000000000000000000000 and my computer crashed.
@rahil_rehan
@rahil_rehan 5 жыл бұрын
As every point lies in a square, there shouldn't be an if else statement, coz the coordinates get added to square coordinates if they are not in a circle. But all the points do lie in the square, well the output would be right still as you tool float(N) at last computation.
@ajonautajo
@ajonautajo 6 жыл бұрын
Literally did the same project about a year ago. Lent itself to a some statistic analysis to improve the approximation. Good stuff though.
@natmath2576
@natmath2576 6 жыл бұрын
That was a real Parker Square
@ratulbanerjee8456
@ratulbanerjee8456 4 жыл бұрын
I think just use Ramanujan or any other fundamental series approx formulaes and will give digits upto ones will.
@UrsielHauke
@UrsielHauke 4 жыл бұрын
1:46 we can stop here, that's a good estimation
@BeLikeNexus
@BeLikeNexus 4 жыл бұрын
God this mans beard is perfect
@autid
@autid 6 жыл бұрын
First thought: Monte Carlo? 3:50 Monte Carlo!
@lyndonhanzpernites5860
@lyndonhanzpernites5860 3 жыл бұрын
same!
@aritraray2501
@aritraray2501 4 жыл бұрын
what if I take the random variables range as (0,2) for both x and y??..its not going to give the right value..but i cant understand why
@coltonhassel2529
@coltonhassel2529 6 жыл бұрын
Hey just wondering what packages would you recommend installing for these types of things in Jupyter
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
Can't go wrong with numpy, scipy, sympy, and matplotlib. But I also think those come with anaconda.
@zoltankurti
@zoltankurti 6 жыл бұрын
I think generating points in a grid like you had shown in the beginning and than counting them would be more accurate. Also, using only a quarter circle is 4 times faster but has the same precision. Then again, you could write a simple program to integrate sqrt(1-x^2) by divideing it into small rectangles. This could be a part two of this wideo, since it is very useful to see how numerical integration works. You can also better understand the definition of a Riemann integral by this example.
@expertnonexpert3826
@expertnonexpert3826 3 жыл бұрын
is there a book that covers this material. like what "append" means etc? I got "Doing Math With Python" but it seems very basic.
@electrikshock2950
@electrikshock2950 6 жыл бұрын
You can also get the root of the sum of 6/x^2 and you will get to pi at infinity (or pretty close with a very high number) or this pattern [ (-1)^(x+1)/2x-1 ]
@kamehamehaDdragon
@kamehamehaDdragon 6 жыл бұрын
Great video man, I'm looking foward to learn python, i only know how to code on Java a little, python looks very different but the kind I like.
@SolathPrime
@SolathPrime 3 жыл бұрын
God bless you
@carlosvargas2907
@carlosvargas2907 6 жыл бұрын
Great
@amandeep9930
@amandeep9930 3 жыл бұрын
What about using various infinite series representations of pi?
@Thegreatnintendolets
@Thegreatnintendolets 5 жыл бұрын
I think an easier way wouldve been to use the series for arctanx and have it iterate n amount of times to give an approximation
@jessicachaves3666
@jessicachaves3666 3 жыл бұрын
thanks :D
@uminum1
@uminum1 6 жыл бұрын
"..... Cool!"
@XanderGouws
@XanderGouws 6 жыл бұрын
Why couldn't you just use a for-loop? Also, could you do a vid implementing monte-carlo in python?
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
for loop, while loop, doesn't matter. And I'm thinking about it
@XanderGouws
@XanderGouws 6 жыл бұрын
Andrew Dotson ye but using a while loop there is _filthy_
@Econcrafter
@Econcrafter 5 жыл бұрын
@@XanderGouws Exactly my thoughts
@andree2062012
@andree2062012 4 жыл бұрын
Depends on the general length of the program you do but from an performance point of view, an for loop is much better. Also great video man but your coding style made me cringe a bit :))
@andrewtran6669
@andrewtran6669 6 жыл бұрын
When did you start learning Python?
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
Wow only a year ago now that I think about it.
@principia1372
@principia1372 3 жыл бұрын
14:55 CMBR???
@illumiyokai
@illumiyokai 6 жыл бұрын
First
@kathanshah8305
@kathanshah8305 3 жыл бұрын
Tl Dw answer is 3
@matron9936
@matron9936 4 жыл бұрын
If this is a square then pi equals to 4. Now i am know how engineers think.
@samkonstan2333
@samkonstan2333 4 жыл бұрын
I’ve got another way that’s a lot simpler. print(3)
@nirorit
@nirorit 4 жыл бұрын
Why throw darts at random? Can't you just spread the darts evenly to get an absolutely converging sequence?
@matron9936
@matron9936 4 жыл бұрын
Video start: This is a square. Close video.
@ISapTout
@ISapTout 6 жыл бұрын
Please, for the love of God, shave that beard. Great video.
@someaccount3438
@someaccount3438 5 жыл бұрын
This video is pointless. Everyone knows π = 3.
@chillfill4866
@chillfill4866 4 жыл бұрын
Stupidest thing I've ever seen. Non deterministicly approaches pi in 2*10^n multiplications where n is each digit of precision. Archimedes did it better 1000s of years ago.
Monte Carlo Integration In Python For Noobs
15:32
Andrew Dotson
Рет қаралды 150 М.
Coding Challenge 95: Approximating the Value of Pi
27:32
The Coding Train
Рет қаралды 632 М.
Amazing weight loss transformation !! 😱😱
00:24
Tibo InShape
Рет қаралды 67 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 56 МЛН
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 9 МЛН
Finding Zeros of Functions In Python (Bisection Method and Scipy)
15:26
Calculating Pi with Real Pies - Numberphile
3:14
Numberphile
Рет қаралды 952 М.
Lessons Learned During My PhD So Far
13:05
Andrew Dotson
Рет қаралды 152 М.
How To Graph In Python | Infinite Square Well
19:34
Andrew Dotson
Рет қаралды 15 М.
Using Excel to Calculate π Like Newton
24:34
The Art of Software Development
Рет қаралды 612
How is pi calculated to trillions of digits?
6:52
Mathemaniac
Рет қаралды 129 М.
D-Term Determined (Finally Writing The Paper)
17:46
Andrew Dotson
Рет қаралды 54 М.
Math I'm Using For My Theoretical Physics Internship
9:01
Andrew Dotson
Рет қаралды 112 М.
A really interesting formula for pi
15:59
Michael Penn
Рет қаралды 30 М.
A Simple Solution for Really Hard Problems: Monte Carlo Simulation
5:58