# Methods of Estimating Pi

## Recommended Posts

So what happened?

I remember reading a short story by your best friend Arthur C Clark.

The story was about a monastery in Tibet where the monks had been working for thousands of years to enumerate all the names of God.

Then they bought a computer and it was able to complete the task in hours.

Then......

But that would be telling!

Are you tring for the same thing with pi?

I've been trying to learn Latex all day on Sat. May 12, sometimes using a guide I got from the Net, and a lot of trial and error.

I figured out most of it, but I haven't figured out what the \mathop command does, or how to separate the formulas on different lines on the screen.

Can anybody help?

• Replies 122
• Created

#### Posted Images

If you want to separate formulas on different lines, do something like this:

$3x^2$

$\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$

Hit the Reply button on my post to see the code I used.

I've never used mathop, so I don't know what it does.

##### Share on other sites

I have tried to use integrals to compute pi:

$\mathop A(n) \rightarrow{\int_a^b} f(x) dx$ as $n\mathop\rightarrow \infty$

$= 2{\int\limits_{-1}^{1}}\sqrt{1-x^2}dx$

From p. 209 of Freshman Calculus:

$\mathop{\int}\sqrt{a^2-x^2}dx = \frac{a^2}{2}\arcsin{\frac{x}{a}}+\frac{x}{2}\sqrt{a^2-x^2}+C$

a=1: $=\frac{1}{2}\arcsin{x}+\frac{x}{2}\sqrt{1-x^2}$

$= \left. 2 \bigg(\right|_{-1}^{1}\bigg) \frac{1}{2}\arcsin x + \frac{x}{2}\sqrt{1-x^2}$

$= 2 \bigg[\bigg(\frac{1}{2}\arcsin1+\frac{1}{2}\sqrt{1-1}\bigg)-\bigg(\frac{1}{2}\arcsin-1-\frac{1}{2}\sqrt{1-1}\bigg)\bigg]$

$= 2 [((\frac{1}{2})(\frac{\pi}{2})+\frac{1}{2}(0))-((\frac{1}{2})(\frac{-\pi}{2})-(\frac{1}{2})(0))]$

$= 2 \bigg(\frac{\pi}{4}+\frac{\pi}{4}\bigg)$

$= 2 \bigg(\frac{2\pi}{4}\bigg)$

$= \frac{4\pi}{4}$

$= \pi$

I have found that the integral equates to pi, but the formula doesn't tell me the value of pi.

Edited by IsaacAsimov
##### Share on other sites

Another fun formula (due to Wallis) is

$\mathop {\lim }\limits_{m \to \infty } \frac{{2.4.6.8.\left( {2m - 2} \right)}}{{3.5.7.9.\left( {2m - 1} \right)}}\sqrt {2m} = \sqrt {\frac{\pi }{2}}$

What does the \mathop command do?

##### Share on other sites

Sorry I have absolutely no idea.

See my previous post it is a straight copy and paste.

Perhaps some one who knows about these things will help?

I think this forum uses something called MathML but I'm not sure - With the settings I now have in MathType to work in this website (SF) I ahve to edit the tags manually from $to [Tex] or [iTex]. ##### Link to comment ##### Share on other sites Please note that the function [math]y = \sqrt {(1 - {x^2})}$

Is the equation of a semicircle from x=-1 to x=+1.

So you should have deduced that the area of a semicircle of radius 1 and diameter 2 is pi/2 and indeed pi is twice this integral as you say.

Edited by studiot
##### Share on other sites

Given:

$y=\sqrt{1-x^2}$

=SQR(1-X*X)

a=0, b=1, n=10

$\Delta x = \frac{b-a}{n}=\frac{1-0}{10}=\frac{1}{10} = 0.1$

$\begin{matrix} I & X & Y & T \\ 0 & 0 & 1 & 1\\ 1 & 0.1 & 0.99499 & 1.99499\\ 2 & 0.2 & 0.97980 & 2.97478\\ 3 & 0.3 & 0.95394 & 3.92872\\ 4 & 0.4 & 0.91652 & 4.84524\\ 5 & 0.5 & 0.86602 & 4.84524\\ 6 & 0.6 & 0.8 & 6.51126\\ 7 & 0.7 & 0.71414 & 7.22541\\ 8 & 0.8 & 0.6 & 7.82541\\ 9 & 0.9 & 0.43589 & 8.26130 \end{matrix}$

$\pi=\Delta x(T)(4)=0.1(8.26130)(4)=3.30452$

What is T?

##### Share on other sites

What is T?

T is the total of all the y values up to that point.

##### Share on other sites

Given:

$y=\sqrt{1-x^2}$

=SQR(1-X*X)

a=0, b=1, n=10

$\Delta x = \frac{b-a}{n}=\frac{1-0}{10}=\frac{1}{10} = 0.1$

$\begin{matrix} I & X & Y & T \\ 0 & 0 & 1 & 1 \\ 1 & 0.1 & 1.98997 & 2.98997 \\ 2 & 0.2 & 1.95959 & 4.94957 \\ 3 & 0.3 & 1.90788 & 6.85745 \\ 4 & 0.4 & 1.83303 & 8.69048 \\ 5 & 0.5 & 1.73205 & 10.42253 \\ 6 & 0.6 & 1.6 & 12.02253 \\ 7 & 0.7 & 1.42829 & 13.45081 \\ 8 & 0.8 & 1.2 & 14.65081 \\ 9 & 0.9 & 0.87178 & 15.52259 \\ 10 & 1 & 0 & 15.52259 \\ \end{matrix}$

$\pi=\frac{\Delta x}{2}(T)(4)=\frac{0.1}{2}(15.52259)(4) = 3.10452$

This is fairly close to the actual value of pi.

##### Share on other sites

Your method is distorting things. You are using 10 points for 10 rectangles. You need to adjust the end points (using 1/2 the value). The result will be closer.

##### Share on other sites

I wouldn't call this a detailed analysis of 1/4 of a circle using rectangles when the underlying principle is based on the Riemann sum with only ten partitions.

$f(x)=\sqrt{1-x^2}, \ \ \ \ \Delta x = \frac{b-a}{n}, \ \ \ \ x_k = a + k \ \Delta x$

The area of the region $R$ can be approximated using $n$ rectangles such that:

$R_n = \sum_{k=0}^{n-1} f(x_k) \ \Delta x \ \ \ \ \text{or} \ \ \ \ R_n = \Delta x \ \sum_{k=0}^{n-1} f(x_k)$

Since integrating $f(x)=\sqrt{1-x^2}$ on the interval $[0, 1]$ is 1/4 the area of a circle with radius one, multiplying the above Riemann sum by 4 will approach the value $\pi$ as $n$ aproaches $\infty$:

$4 \times \lim_{n \to \infty} R_n \ = \ 4 \times \lim_{n \to \infty} \ \sum_{k=0}^{n-1} f(x_k) \ \Delta x \ = \ 4 \times \int_0^1 f(x) \ dx \ = \ 4 \times \frac{\pi}{4} \ = \ \pi$

You can use the mid-point rule, the trapezoidal rule, or Simpson's rule to get better approximations when dealing with a finite number of rectangles.

Edited by Daedalus
##### Share on other sites

I wouldn't call this a detailed analysis of 1/4 of a circle using rectangles when the underlying principle is based on the Riemann sum with only ten partitions.

$f(x)=\sqrt{1-x^2}, \ \ \ \ \Delta x = \frac{b-a}{n}, \ \ \ \ x_k = a + k \ \Delta x$

The area of the region $R$ can be approximated using $n$ rectangles such that:

$R_n = \sum_{k=0}^{n-1} f(x_k) \ \Delta x \ \ \ \ \text{or} \ \ \ \ R_n = \Delta x \ \sum_{k=0}^{n-1} f(x_k)$

Since integrating $f(x)=\sqrt{1-x^2}$ on the interval $[0, 1]$ is 1/4 the area of a circle with radius one, multiplying the above Riemann sum by 4 will approach the value $\pi$ as $n$ aproaches $\infty$:

$4 \times \lim_{n \to \infty} R_n \ = \ 4 \times \lim_{n \to \infty} \ \sum_{k=0}^{n-1} f(x_k) \ \Delta x \ = \ 4 \times \int_0^1 f(x) \ dx \ = \ 4 \times \frac{\pi}{4} \ = \ \pi$

You can use the mid-point rule, the trapezoidal rule, or Simpson's rule to get better approximations when dealing with a finite number of rectangles.

I know that the integral formula equates to pi, however I was trying to find the decimal value of pi.

##### Share on other sites

You can always use the Riemann sum to approximate $\pi$. Although, it may not be the most efficient method:

$R_n=\sum_{k=0}^{n-1} f(x_k) \, \Delta x \approx \pi$

$4 \times R_1 \ = 4.000000000$

$4 \times R_2 \ = 3.732050808$

$4 \times R_3 \ = 3.584220045$

$4 \times R_4 \ = 3.495709068$

$4 \times R_5 \ = 3.437048829$

$4 \times R_6 \ = 3.395316356$

$4 \times R_7 \ = 3.364086195$

$4 \times R_8 \ = 3.339818144$

$4 \times R_9 \ = 3.320407605$

$4 \times R_{10} = 3.304518326$

$...$

$4 \times R_{1000} = 3.143555467$

You might be interested in these methods:

http://en.wikipedia....tions_of_%CF%80

In 1910, the Indian mathematician Srinivasa Ramanujan found several rapidly converging infinite series of pi, including

which computes a further eight decimal places of pi with each term in the series. His series are now the basis for the fastest algorithms currently used to calculate pi.

...

In 1989, the Chudnovsky brothers correctly computed pi to over a 1 billion decimal places on the supercomputer IBM 3090 using the following variation of Ramanujan's infinite series of pi:

Edited by Daedalus
##### Share on other sites

$T_n=\frac{\Delta x}{2}[f(x_0)+2f(x_1)+2f(x_2)+...+2f(x_{n-1})+f(x_n)]$

$\text{Rectangle and Trapezoid Methods:}$

$\begin{matrix} \text{number of rectangles} & \text{value of pi} & \text{number of trapezoids} & \text{value of pi} \\ 10 & 3.30452 & 10 & 3.10452 \\ 100 & 3.16042 & 100 & 3.14042 \\ 1000 & 3.14356 & 1000 & 3.14156 \end{matrix}$

##### Share on other sites

Thank you for showing me those two approximation of pi formulas. I would use them, but my C64 computer doesn't have a factorial function.

I am very fond of pi, and I like calculating pi, as long as it's not too complicated.

Marlon S.

##### Share on other sites

Here's a program I wrote in Structured Basic on my C64 computer:

100 REM COMPUTING PI USING RECTANGLES

110 REM DOTS REPRESENT INDENTATIONS

120 CALL INIT

140 CALL MAIN

160 CALL OUTPUT

180 END

200 :

220 PROC INIT

240 .....TI$="000000" 260 .....A=0:B=1 280 .....N=10 300 ENDPROC 320 : 340 PROC MAIN 360 .....DX=(B-A)/N 380 .....PRINT:PRINT"DX =";DX 400 .....X=-DX 420 .....I=-1 440 .....PRINT:PRINT" I ";" X ";" Y ";" T ":PRINT 460 .....LOOP 480 ........I=I+1 500 ........X=X+DX 520 ........Y=SQR(1-X*X) 540 ........T=T+Y 560 ........PRINT I;X;Y;T 580 .....UNTIL I=N-1 600 .....PI=DX*T*4 620 ENDPROC 640 : 660 PROC OUTPUT 680 .....PRINT:PRINT"PI =";PI 700 .....PRINT:PRINT"TIME TAKEN = ";TI$

720 ENDPROC

##### Share on other sites

Thank you for showing me those two approximation of pi formulas. I would use them, but my C64 computer doesn't have a factorial function.

surely you could just make a factorial function for your C64, right?

thats the beauty of programming, if there isn't a function for it, just program one! computers are turing machines so they can perform any process (at more or less efficiency than others)

if you really really wanted to you could run global weather simulations on a C64. they'd be so slow as to be useless and the hardware would probably fail before the second iteration completed but you could get the exact same results as the super computers they run it on.

##### Share on other sites

Another fun formula (due to Wallis) is

When I tried to use this formula, I got:

m=10:

$a=\frac{384(2(10)-2)}{945(2(10)-1)}\sqrt{2(10)}=\frac{384(18)}{945(19)}\sqrt{20}=1.72160$

$a=\sqrt{\frac{\pi}{2}}$

$a^2=\frac{\pi}{2}$

$\pi=2a^2=2(1.72160)^2=5.92784$

which is clearly wrong

m=100:

$a=\frac{384(2(100)-2)}{945(2(100)-1)}\sqrt{2(100)}=\frac{384(198)}{945(199)}\sqrt{200}=5.71777$

$\pi=2a^2=2(5.71777)^2=65.38574$

which is also clearly wrong

What am I doing wrong?

##### Share on other sites

I can't seem to find the formula posted above as "Wallis' formula"

http://en.wikipedia.org/wiki/Wallis_product has a somewhat different form. Your formula looks like it may be missing some terms...

Furthermore, I think that 2*4*6*8*...*(2m-2) means that you multiple every even number together until you get to 2m-2

i.e. if m = 20, 2m-2 = 38, so the numerator is 2*4*6*8*10*12*14*16*18*20*22*24*26*28*30*32*34*36*38.

The denominator looks the same, just with odd numbers.

Edited by Bignose
##### Share on other sites

Thank you for clearing that up. I guess I'll have to use a computer instead of a calculator.

I can't seem to find the formula posted above as "Wallis' formula"

http://en.wikipedia..../Wallis_product has a somewhat different form. Your formula looks like it may be missing some terms...

Furthermore, I think that 2*4*6*8*...*(2m-2) means that you multiple every even number together until you get to 2m-2

i.e. if m = 20, 2m-2 = 38, so the numerator is 2*4*6*8*10*12*14*16*18*20*22*24*26*28*30*32*34*36*38.

The denominator looks the same, just with odd numbers.

My calculator can handle numbers up to 69!, or 9.999...E+99, but using a calculator for the above even-odd formula is too time-consuming.

I wrote a program for the even-odd formula on my C64 computer, and I got it right the first time!

The only problem is that my computer can only handle numbers up to 1.7014E+38, or 33!, so I'm limited to m=10 for the even-odd formula, k=8 for the Ramanujan formula, and k=5 for the Chudnovsky formula.

##### Share on other sites

By Arclength Approximation Riemann Form

$f(x) = \sqrt { 1 - x^2 }\, ; \; f'(x) = - \frac{x}{\sqrt{1-x^2}}\, ; \; f''(x) = - \frac{1}{\sqrt{(1-x^2)^3}}\, ; \; f'''(x) = - \frac{3x}{\sqrt{(1-x^2)^5}}$

$S = \frac {\pi}{2} = \int_{0}^{1} \sqrt { 1 + [f'(x)]^2 } \, dx = \int_{0}^{1} \sqrt { 1 + [- \frac{x}{\sqrt{1-x^2}}]^2 } \, dx = \int_{0}^{1} \sqrt { 1 + \frac{x^2}{1-x^2} } \, dx$

$\Delta x = \frac{b - a}{n} = \frac{1}{n}$

$x_i^* = a + i \cdot \Delta x = \frac{i}{n}$

$x_{i-1}^* = a + (i - 1) \cdot \Delta x = \frac{i - 1}{n}$

$\bar{x} = \frac{x_i^* + x_{i-1}^*}{2} = \frac{(\frac{i}{n}) + (\frac{i - 1}{n})}{2} = \frac{2i - 1}{2n}$

$M_n \approx \sum_{i=1}^n f( \bar{x} ) \cdot \Delta x = \sum_{i=1}^n \sqrt { 1 + \frac{(\bar{x})^2}{1-(\bar{x})^2} } \cdot \frac{1}{n} = \frac{1}{n} \sum_{i=1}^n \sqrt { 1 + \frac{(\frac{2i - 1}{2n})^2}{1-(\frac{2i - 1}{2n})^2} } = \frac{1}{n} \sum_{i=1}^n \sqrt{\frac{4n^2}{4n^2 - 4i^2 + 4i - 1 }}$

$error = |S - M_n| \, ; \; K_2 = max | f''(x) | \, ; \; 0 \leq n = \sqrt{\frac{K_2(b - a)^3}{24(|S - M_n|)}}$

Edited by Xittenn
##### Share on other sites

Thank you for clearing that up. I guess I'll have to use a computer instead of a calculator.

My calculator can handle numbers up to 69!, or 9.999...E+99, but using a calculator for the above even-odd formula is too time-consuming.

I wrote a program for the even-odd formula on my C64 computer, and I got it right the first time!

The only problem is that my computer can only handle numbers up to 1.7014E+38, or 33!, so I'm limited to m=10 for the even-odd formula, k=8 for the Ramanujan formula, and k=5 for the Chudnovsky formula.

##### Share on other sites

Another fun formula (due to Wallis) is....

Did you mean this one?

##### Share on other sites

You can use the mid-point rule, the trapezoidal rule, or Simpson's rule to get better approximations when dealing with a finite number of rectangles.

Also Richardson extrapolation is worth mentioning here. If $I_n$ is the result using the trapezoidal method for n steps, then

$I_{2n} + \frac{I_{2n}-I_n}{3}$

..will give super-duper accuracy compared to $I_{2n}$ alone. Good way to improve results without too much added coding.

## Create an account

Register a new account