In the excellent
This uses a formula for
First, we need a Maclaurin series for
To find this, we need to know the derivative of
(To see this, let
So, back to our Maclaurin series, the relevant derivatives are:
Then the function values end up as:
So
I’m happy, for an approximation, to say
and
Finally,
I think it is neat to get agreement with the first five decimal places from only four terms.
The first time I did this example in a lecture, I started by joking “this is a long and complicated example. When I get to the end, I fully expect a round of applause”. When I finished, somewhat embarrassingly, I received one — along with ironic whoops from the back row!
To take this a little further, I wrote this quick Python code.
import decimal import math for loop in range(1,12): pivalue=0 firstterm=0 secondterm=0 for i in range(0, loop): firstterm = firstterm + decimal.Decimal((-1)**i * (1/5**(2*i+1))/(2*i+1)) secondterm = secondterm + decimal.Decimal((-1)**i * (1/239**(2*i+1))/(2*i+1)) pivalue = decimal.Decimal(16 * firstterm - 4 * secondterm) print("Using {} terms: {:.15f}".format(loop,pivalue)) print('math.pi: {:.15f}'.format(math.pi))
This gives the following values, showing that this finds 15 digits of
Using 1 terms: 3.183263598326360 Using 2 terms: 3.140597029326060 Using 3 terms: 3.141621029325035 Using 4 terms: 3.141591772182177 Using 5 terms: 3.141592682404400 Using 6 terms: 3.141592652615309 Using 7 terms: 3.141592653623555 Using 8 terms: 3.141592653588602 Using 9 terms: 3.141592653589836 Using 10 terms: 3.141592653589792 Using 11 terms: 3.141592653589793 math.pi: 3.141592653589793
Apparently Machin used his formula to compute 100 digits of
Hello Peter
My approach is
with many digits