Hey, Mom! The Explanation.

Here's the permanent dedicated link to my first Hey, Mom! post and the explanation of the feature it contains.

Thursday, March 15, 2018

Hey, Mom! Talking to My Mother #983 - Pi Day (a day later) - Review - Calculate Pi

Colorado Rockies - 3/14/2017 - calculate Pi to... well that's a lot of digits ...
Hey, Mom! Talking to My Mother #983 - Pi Day (a day later) - Review - Calculate Pi

Hi Mom,

I am working on a longer post charting my trip last weekend with Liesel, but it's not done yet. I took the time to copy over all this text and the imagery from WIRED that provides a nice review of how Pi is calculated, which is something I was doing just a year ago.

How did I have time to go to a class almost every day plus teaching two additional courses in Michigan? Are days longer there? Or isn't the time a constant, like Pi, but rather there's some change in how I use it? I still do not have this issue sussed, but like sussing Pi, it's a work in progress.

That's the thought for today.

Now, calculate Pi.

Oh yeah, and the picture up top. I had this from last year as the Colorado Rockies worked out Pi to, well, a lot of digits. I never shared the photo but isn't it cool?

FROM - https://www.wired.com/story/this-pi-day-calculate-the-value-of-pi-for-yourself


THIS PI DAY, CALCULATE THE VALUE OF PI FOR YOURSELF

ROBERT GRESHOFF/GETTY IMAGES


IT IS ONCE again Pi Day (March 14—which is like the first digits of pi: 3 and 14). Before getting into this year's celebration of pi, let me just summarize some of the most important things about this awesome number.
But today, I am going to calculate pi with a numerical integral. What does that even mean? Let me start with an example—how do you find the area of a half-circle?



The area of a circle is pi times the radius squared. This is half of a circle with a radius of 1 (no units) such that it would have an area of pi/2. If I find the area with some other method, I can just multiply this area by 2 and get pi. That's the plan.
But how do you find the area of some shape—or any shape for that matter? This is where calculus comes in handy. I can find the area of the half circle by adding up the area of a bunch of rectangles. It turns out that it's pretty easy to find the area of a rectangle. Let me just draw a few rectangles in that half-circle so you can see what I mean.

The area of each of these skinny rectangles can be found with the formula "base times height." A rectangle has a height of "y" and a base of "dx" where the dx is just some arbitrary length along the x-axis. I can find the actual value of the height because the top of the rectangle hits the circle where this height can be found from the equation of a circle.







Now I just need to add up all these rectangles—boom, that's the area of half a circle. I can write this as a sum of areas like this:







But wait! Isn't this a poor approximation to the actual area of a circle (half-circle)? Yes, that is indeed true—but it really depends on the width of these tiny area rectangles. In fact, if I take the limit as the width (dx) goes to zero then I will get the exact area. This is actually the definition of the integral in calculus—but I will save that for another day. Instead we will do a numerical calculation by simply adding up the area of a bunch of rectangles. You could of course do this by hand—but it might get boring. Instead, let's do this with a computer program. Yup.
Here is numerical calculation in python. You can go ahead and run the code by pressing the "play" button, but I will give some code comments below.




You can change the code if it makes you happy—here are a few things to consider.
  • This is a numerical calculation. That means the program only deals with numbers. Technically, the area should have units of m2 or something like that but not here. Only numbers.
  • For loops in python, it includes everything that is tab-indented as part of the loop. Once you dedent, it's no longer in a loop.
  • Line 18 should look weird because it is. If you consider this to be an algebraic equation, the A should cancel since it is on both sides of the equation—but this is not an equation. In python (and most other languages), the "=" means "make equal to". This line takes the old value of A, adds the new stuff and then makes it the new value of A.
This initial calculation has a dx of 0.1. That means there will be just 20 rectangles to add up and get the area of the half-circle. With this, I get an approximate pi value of 3.10452—which is clearly not exact pi. Of course I can make a better estimate by making smaller width rectangles. You should try this by changing the code above (hint: change the value for dx). However, since I can't let this go here is a plot of the value of pi for different step sizes.






Perhaps that's not the best plot—but it's good enough for now. If you want to check out the code for this plot, here you go. But in the end, the value does approach the expected value of pi. This method might not get you one million digits of pi, but maybe you at least can learn something about integration.


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Reflect and connect.

Have someone give you a kiss, and tell you that I love you, Mom.

I miss you so very much, Mom.

Talk to you tomorrow, Mom.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

- Days ago = 985 days ago

- Bloggery committed by chris tower - 1803.15 - 10:10

NEW (written 1708.27) NOTE on time: I am now in the same time zone as Google! So, when I post at 10:10 a.m. PDT to coincide with the time of your death, Mom, I am now actually posting late, so it's really 1:10 p.m. EDT. But I will continue to use the time stamp of 10:10 a.m. to remember the time of your death, Mom. I know this only matters to me, and to you, Mom.

No comments: