Skip to main content

5 Methods for Approximating Pi

Animated pi symbol
Happy super-π day! π-day falls on March 14 every year, because the month-day combination results in 3-14, which are the first 3 digits of π. But this π-day is particularly special: include the year, and you get 3-14-15, the first 5 digits of π. We won't get another π-day like this for another 100 years, so you better enjoy this one!

A particularly special time will be at 9:26:53 PM tonight, when we'll get 3-14-15 9:26:53, or the first 10 digits of π.

In honor of the occasion, I'm going to post 5 simple methods for approximating the value of π.


1. String and Tape Measure

Draw a circle with a diameter of 1 foot and put a piece of string around the edge. Cut the string until it's the right length, and then measure it with a tape measure. The string should be about π feet long.

This can be implemented more accurately using a computer program: take the arc length of √(1 - x2) on the interval (-1, 1). The result should be π.




2. Monte Carlo

Using the Monte Carlo method, the value for π can be approximated by drawing a square with a circle fitting perfectly inside it, and throwing rice high over the square. Let a equal the total number of grains that fall inside the square, and let b equal the number of grains that fall inside the circle. Assume the circle's radius is 1 unit, so the area of the circle is π square units. The square's area is 4 square units. On average, b / a = π / 4, so π = b * 4 / a.

This can also be implemented using a computer program. Pick random points with x-values between -1 and 1 and y-values between -1 and 1. Count the number of points within a distance of 1 from the origin, and proceed with the math as before.




3. cos(π/2) = 0

When most people talk about an angle, they use degrees - as in 90° (a right angle), 180° (a U-turn), and 360° (1 full turn, or very dizzy). But mathematicians use radians, which involves looking at the circumference of a unit circle, so instead of a full circle being 360°, it's equal to 2π (the circumference of a unit circle). A U-turn, or 180°, is equal to π, and a right-angle (90°) is equal to π/2.

Using radians, cosine of π/2 is equal to 0. So to figure out what π is, just plug some angles in and see what works. When you get an angle that works, multiply by 2 and you have π. (For my post about sine and cosine, click here.)

If you use an angle that is too big, the cosine is negative; if use an angle that's too small, cosine is positive. So, instead of making random guesses, you can actually improve your guesses over time.

In fact, because cosine is negative when the angle is too big, and cosine is positive when the angle is too small, the following method that I discovered works really well (where θ is the angle being tested):
A. Start with θ = 0
B. Add cos(θ) to θ
C. Go back to step B

After repeating those steps only 4 times, and multiplying your angle by 2, you'll get a surprisingly good approximation of π.

Alternatively, if you know the Taylor series for arcsin(x), you could use that to find the value for arcsin(1) and double it to get π.




4. Integral

We want to find the area of a circle, right? So why not just, well, find the area?

The formula for the top half of a circle is √(1 - x2). If we take the integral of that function from -1 to 1, and multiply by 2, then bingo! We get pi. (For those who haven't reached calculus, the integral is the area under the curve.) To do this, a numerical approximation works well: start with x = -1, and gradually increase x until it reaches 1; meanwhile, evaluate √(1 - x2) at each point, multiply by the step size, multiply by two, and add the values all together. (You can also use the indefinite integral, but that involves arcsin(x), which would require a Taylor series to solve.)

This technique works best when implemented using a computer program. In JavaScript, you would use some code like this (try changing "step" to something smaller than 0.1!):




5. Many-sided polygon

A circle is like a polygon with tons of sides, right? So if you can find the area of a 1000-sided polygon, that should be pretty close to π. Now how might we do this?

Suppose we have an n-sided polygon. The angle of a single sector of the polygon is equal to 360°/n degrees. Divide the sector into 2 right-angled triangles, and each triangle has an angle of 180°/n degrees. Now assume that the base of each triangle has a length of 1. We can get the area of each triangle by taking 1*tan(180°/n)/2. Since we divided each sector into 2 parts, we multiply by 2 to get the area of the sector: tan(180°/n). Multiply by the number of sectors to get n*tan(180°/n) for the area of the polygon.

But tan(θ) = sin(θ) as θ approaches zero, so the area of an n-sided polygon is equal to n*sin(180°/n).

Now, when x is very large, we can get a reasonable approximation for π. There's one problem, though. When a computer calculates sin(θ) in degrees, it converts to radians using a built-in value of π. In other words, our formula relies on somebody else's value of π in order to compute its own value of π. Which is stupid.

However, we can use geometry to prove that the value of sin(45°) = cos(45°) = 1/(√2). Based on that, we can use the half-angle formulas for sin and cos to compute values of sin(45/2°), sin((45/2)/2°), and smaller angles. To make sure our angles are half values of 45°, we can only work with polygons that have 8*2m sides (with m an integer).

I'll leave it at that.


New posts every month - subscribe for free!


Comments

Popular posts from this blog

Flipping Quarters

Here's an interesting puzzle involving chance: A man in a park asks you to play a game with him. It's a form of gambling. To play, you must pay the man $5, then flip a coin repeatedly until you get heads. As soon as you get heads, you stop flipping. If you only flipped the quarter once, he'll give you $1. If you flipped it twice, you get $2. Three times, $4. Four times, $8. Each extra flip gets you twice as much money, so the longer it takes before you get tails, the more money you get. Should you play, if you have a lot of time and the man will play as many games as you want? How much money, on average, would you gain (subtracting the $5 fee)? I will give the solution in a later post .

Pluto No Longer on the Horizon

This morning, New Horizons became the first spacecraft to make a flyby observation of the Pluto system. During the mission, the spacecraft captured the most detailed photographs of Pluto's surface we've ever had, and possibly ever will have. It also found many new properties including size, mass, atmosphere, and surface composition. In a period of a few hours, we discovered more about Pluto than we've found in the 85 years since Clyde Tombaugh captured its first photograph. Before After  (images credit: NASA) To complete this mission, the spacecraft flew for more than 9 years through the emptiness of space. This may sound like a long time, but it's actually amazingly quick. In fact, New Horizons set the record for the fastest speed at launch, and during the flyby, the spacecraft was moving at a rate of over 30,000 mph, or roughly 50 times the speed of sound. Picture an object twice as heavy as a grand piano moving 25 times faster than a bullet from a gun. Yikes. The man...

Should Tau Replace Pi?

The digits of π, organized in a very new way Happy π-day! And happy π-month! Today's month and day - that is, March 14 or 3.14 - includes the first 3 digits of π. And today's month and year - March 2014 or 3.14 - also includes the first 3 digits of π. We won't have another double-day for π for the next 100 years, so enjoy this one! For the special occasion, I'm posting two π-related posts - one for π-month, and the other for π-day. In both posts, I'm setting the font size to approximately π * π + π + π. This is the first post, for π-month; to see the second, go to http://greatmst.blogspot.com/2014/03/pi-month-pi-day-post-2-5-common-pi-myths.html . In this post, I am including an essay I wrote about whether π or τ is the more superior constant. This was written for people who know very little about math, so the basic idea should be easy to understand even for people who are not mathematically inclined. Should Tau Replace Pi? A constant is any number or value that ne...