Syndicate this site: (RSS)

Calculating π

π is the ratio of the circumference of a circle to its diameter. The Greeks noticed that this ratio was the same for all circles, and named it. They also made efforts to calculate it, but the tools available in those times were too slow - you don't get enough digits for the calculation effort.

To give us some context to work in, we consider a unit circle. As the radius is
1, the diameter is 2, and the circumference 2π. Draw a line segment from the center of the circle to the circumference and beyond. This is the X axis, and we designate the intersection of the axis and the circle at (1,0) +X. A second line segment, perpendicular to the first gives a Y axis. The intersection of the Y axis and the circle is (0,1) +Y. Note that we also now have a natural direction around the circle - from +X to +Y, to -X, -Y, and back to +X.

Now, pick a point P on the circle. We designate theta to be the angle from P,
to the origin, and then to +X. The value theta is the length of the arc of the
circle from +X to P. So in Cartesian coordinates we describe the point P as
(cos(theta), sin(theta)). This is our definition of sin and cos for the purpose
of this exercise, and the definition is identical with the geometric definition
we are accustomed to.

Note that the distance from P to the origin is 1 (we are on the unit circle), and
from this we have the identity cos^2(theta) + sin^2(theta) = 1.

The arc length from +X to +X is 0, so +X = (1,0) = ( cos(0), sin(0) )

While we are at it, we'll define tan(theta) = sin(theta)/cos(theta), although we notice in passing that tan(theta) at +Y and -Y isn't all that well defined. But where tan(theta) is well defined, we can from it compute sin and cosine from it.
cos(theta) = 1 / (1 + tan^2(theta))^1/2
sin(theta) = tan(theta) / (1 + tan^2(theta))^1/2

Let's draw two more lines through the origin - one with a slope of 1, the other with a slope of -1. We have now divided the unit circle into eight equal arcs. If the circle is 2π around, each segment must be 1/8 of that. The intersection of the slope one line with the circle is π/4 from the origin. Because we are on the slope 1 line, sin(π/4) = cos(π/4). tan(π/4) = 1. Nothing new here.

Now imagine an inverse function for each of these functions. That is, an operation tan-1(y) = x implies tan(x) = y. So if we can find some function tan-1, then 4 tan-1(1) = π, and we are home free.

So we're looking for tan-1.

Enter Newton, and his formulation of the derivative of a function - used to
determine the slope of a function at a given point. Put simply, the derivative
is computed from the expression
[f(x+h)-f(x)] / h
taking the limit as h->0
Unfortunately, applying this to any of the trigonometric functions calls for
being able to compute f(x+h).

To get there, we start with the law of cosines. What is the distance from P to +X? The distance formula tells us this: [ ( 1 - cos(x))^2 + sin^2(x) ] ^ 1/2
Expanding...
[ 1 - 2cos(x) + cos^2(x) + sin^2(x) ] ^1/2
[ 2 - 2cos(x) ] ^1/2

Now consider two points, A (cos(a),sin(a)) and B (cos(b),sin(b)). What is the
distance from A to B? By the standard distance formulas
[ (cos(a)-cos(b))^2 + (sin(a)-sin(b))^2 ] 1/2
[ cos^2(a) - 2cos(a)cos(b) + cos^2(b) + sin^2(a) - 2 sin(a)sin(b) + sin^2(b) ] 1/2
[ 2 - 2( cos(a)cos(b) + sin(a)sin(b) ) ] ^ 1/2
And by the law of cosines
[ 2 - 2 cos(a-b)] ^ 1/2

So we get the identity
cos(a-b) = cos(a)cos(b) + sin(a)sin(b)

sin(a-b) = [ 1 - cos^2(a-b) ] ^ 1/2
= [ 1 - (cos(a)cos(b) + sin(a)sin(b))^2] ^1/2
= [ 1 - (cos^2(a)cos^2(b) + 2cos(a)cos(b)sin(a)sin(b) + sin^2(a)sin^2(b) ) ] ^1/2
= [ ( cos^2(a) + sin^2(a) ) * ( cos^2(b) + sin^2(b) )
- (cos^2(a)cos^2(b) + 2cos(a)cos(b)sin(a)sin(b) + sin^2(a)sin^2(b) ) ] ^1/2
= [ cos^2(a)cos^2(b) + cos^2(a)sin^2(b) + sin^2(a)cos^2(b) + sin^2(a)sin^2(b) )
- (cos^2(a)cos^2(b) + 2cos(a)cos(b)sin(a)sin(b) + sin^2(a)sin^2(b) ) ] ^1/2
= [ cos^2(a)sin^2(b) - 2cos(a)cos(b)sin(a)sin(b) + sin^2(a)cos^2(b) ] ^1/2
= [ ( sin(a)cos(b) - cos(a)sin(b) ) ^2 ] 1/2
= sin(a)cos(b) - sin(b)cos(a)

These functions are checked by testing for identity when b = 0.

Applying the expression for the derivative
d/dx cos(x) = [ cos(x+h) - cos(x) ] / h
= [ cos(x)cos(h) + sin(x)sin(h) - cos(x) ] / h
= [ cos(x)(cos(h)-1) + sin(x)sin(h) ] / h
= cos(x) [(cos(h)-1)/h] + sin(x)[sin(h)/h]
= -sin(x)
d/dx sin(x) = [ sin(x+h) - sin(x) ] / h
= [ cos(x)sin(h) - sin(x)cos(h) - sin(x) ] / h
= cos(x)[sin(h)/h] + sin(x)[(cos(h)-1)/h]
= cos(x)

That sin(h) and cos(h)-1 have the required behaviors can be seen by staring at the graph for a bit, or by applying the pinching theorem. Less work is to consider the cosine function, which is smooth and continuous and has a maximum at 0, so the first derivative there is 0.
0 = [ cos(0+h) - cos(0) ] / h = [ (cos(h)-1)/h ]

Then applying this, with the identity sin(x) = [ 1 - cos^2(x) ] ^ 1/2
d/dx sin(x) = d/dx [ 1 - cos^2(x) ] ^1/2
= 1/2 [ 1 - cos^2(x)] ^-1/2 (-2cos(x)(-sin(x))
= 1/2 [ sin^2 ] ^ -1/2 (-2cos(x))(-sin(x)
= cos(x)

d/dx tan(x) can be computed from the above
d/dx tan(x) = d/dx [ sin(x)/cos(x) ]
= ( cos(x) d/dx [sin(x)] - sin(x) d/dx[cos(x)] ) / cos^2(x)
= ( cos^2(x) + sin^2(x) ) / cos^2(x)
= 1 / cos^2(x)

Now, an important point in computing the derivative of an inverse is to note
that an inverse is a reflection about the line with slope 1. In other words
dx/dy = 1 / (dy/dx)
Of course, these are evaluated at Y.

So, we can make some headway in defining tan-1
d/dy[ tan-1(y) ] = 1 / ( d/dx [tan] )
= 1 / ( 1/cos^2( tan-1 ) )
Now if tan-1(y) = x, this implies that cos(x) = 1 / ( 1 + y^2 )^1/2
and thus that
d/dy[ tan-1(y) ] = 1 / ( 1 + y^2 )

At this point, it is convenient to expand the right side.
( 1 + y^2 )^-1 = 1 - y^2 + y^4 - y^6....
= sum [ k:0 .. ] -1^k y ^(2k)

If we integrate both sides
tan-1(y) = sum[ k:0 .. ] ( -1^k y^(2k+1) / (2k+1) )
= y - y^3/3 + y^5/5 - Y^7/7 ....
As tan-1(1) = π/4, we are finished.

Except that this expansion is still too slow. Instead of using 1, we try to
break π/4 into into more convenient angles.

Applying the angle formulas again:
tan(a+b) = sin(a+b) / cos(a+b)
= ( sin(a)cos(b) + sin(b)cos(a) ) / ( cos(a)cos(b)-sin(a)sin(b) )
= ( sin(a)cos(b) + sin(b)cos(a) ) / cos(a)cos(b) ( 1 - tan(a)tan(b) )
= ( tan(a) + tan(b) ) / ( 1 - tan(a)tan(b) )

Why is this helpful? Because instead of waiting for tan-1(1) to converge,
we can instead compute tan-1( tan(a) ) = a and tan-1(tan(b)) = b, and then
add them to get π/4 - provided our choices of a and b are suitable.

1 = ( tan(a) + tan(b) ) / ( 1 - tan(a)tan(b) )
tan(a) = ( 1 - tan(b) ) / ( 1 + tan(b) )

One convenient choice is tan(b) = 1/2. tan(a) = 1/3.
π/4 = tan-1(1/2) + tan-1(1/3) and start adding terms.

The choice of 1/2 is arbitrary - we can use any number we like, noticing that
the convergence is going to depend on the larger of the two. Ideally, we might
look to tan(π/8) = 2^1/2 - 1. But this gets messy, as 2^1/2 is irrational, and our tan-1 function, dealing with odd powers of x, can't help us. Better to choose simple rational powers.

July 28, 2003 8:18 PM | TrackBack

Comments
Post a comment




Who are you?