Jump to content
IsaacAsimov

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?

Share this post


Link to post
Share on other sites

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

 

[math]3x^2[/math]

 

[math]\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}[/math]

 

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 this post


Link to post
Share on other sites

I have tried to use integrals to compute pi:

 

[math]\mathop A(n) \rightarrow{\int_a^b} f(x) dx[/math] as [math] n\mathop\rightarrow \infty[/math]

 

[math] = 2{\int\limits_{-1}^{1}}\sqrt{1-x^2}dx[/math]

 

From p. 209 of Freshman Calculus:

 

[math]\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 [/math]

 

a=1: [math]=\frac{1}{2}\arcsin{x}+\frac{x}{2}\sqrt{1-x^2}[/math]

 

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

 

[math] = 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] [/math]

 

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

 

[math] = 2 \bigg(\frac{\pi}{4}+\frac{\pi}{4}\bigg)[/math]

 

[math] = 2 \bigg(\frac{2\pi}{4}\bigg)[/math]

 

[math] = \frac{4\pi}{4}[/math]

 

[math] = \pi[/math]

 

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

Edited by IsaacAsimov

Share this post


Link to post
Share on other sites

Another fun formula (due to Wallis) is

 

 

[math]\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}} [/math]

 

What does the \mathop command do?

Share this post


Link to post
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 [math] to [Tex] or [iTex].

Share this post


Link to post
Share on other sites

Please note that the function

 

 

[math]y = \sqrt {(1 - {x^2})} [/math]

 

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 this post


Link to post
Share on other sites

Given:

[math]y=\sqrt{1-x^2}[/math]

=SQR(1-X*X)

 

a=0, b=1, n=10

 

[math] \Delta x = \frac{b-a}{n}=\frac{1-0}{10}=\frac{1}{10} = 0.1[/math]

 

[math] \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} [/math]

 

[math] \pi=\Delta x(T)(4)=0.1(8.26130)(4)=3.30452[/math]

Share this post


Link to post
Share on other sites

Given:

 

[math]y=\sqrt{1-x^2}[/math]

 

=SQR(1-X*X)

 

a=0, b=1, n=10

 

[math]\Delta x = \frac{b-a}{n}=\frac{1-0}{10}=\frac{1}{10} = 0.1[/math]

 

[math] \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} [/math]

 

[math]\pi=\frac{\Delta x}{2}(T)(4)=\frac{0.1}{2}(15.52259)(4) = 3.10452[/math]

 

This is fairly close to the actual value of pi.

Share this post


Link to post
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 this post


Link to post
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.

 

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

 

The area of the region [math]R[/math] can be approximated using [math]n[/math] rectangles such that:

 

[math]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)[/math]

 

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

 

[math] 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[/math]

 

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 this post


Link to post
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.

 

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

 

The area of the region [math]R[/math] can be approximated using [math]n[/math] rectangles such that:

 

[math]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)[/math]

 

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

 

[math] 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[/math]

 

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 this post


Link to post
Share on other sites

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

 

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

 

[math]4 \times R_1 \ = 4.000000000[/math]

[math]4 \times R_2 \ = 3.732050808[/math]

[math]4 \times R_3 \ = 3.584220045[/math]

[math]4 \times R_4 \ = 3.495709068[/math]

[math]4 \times R_5 \ = 3.437048829[/math]

[math]4 \times R_6 \ = 3.395316356[/math]

[math]4 \times R_7 \ = 3.364086195[/math]

[math]4 \times R_8 \ = 3.339818144[/math]

[math]4 \times R_9 \ = 3.320407605[/math]

[math]4 \times R_{10} = 3.304518326[/math]

[math]...[/math]

[math]4 \times R_{1000} = 3.143555467[/math]

 

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

 

fb7e2beeda91dc7b5ca2ee46371f1e8c.png

 

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:

 

97e0706f5d97298fd0f75e2b3022b776.png

Edited by Daedalus

Share this post


Link to post
Share on other sites

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

 

[math]\text{Rectangle and Trapezoid Methods:}[/math]

 

[math] \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} [/math]

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Another fun formula (due to Wallis) is

 

 

09de4de1c5cdc18899eef86ba57f9bf3-1.png

 

When I tried to use this formula, I got:

 

m=10:

 

[math]a=\frac{384(2(10)-2)}{945(2(10)-1)}\sqrt{2(10)}=\frac{384(18)}{945(19)}\sqrt{20}=1.72160[/math]

 

[math]a=\sqrt{\frac{\pi}{2}}[/math]

 

[math]a^2=\frac{\pi}{2}[/math]

 

[math]\pi=2a^2=2(1.72160)^2=5.92784[/math]

 

which is clearly wrong

 

m=100:

 

[math]a=\frac{384(2(100)-2)}{945(2(100)-1)}\sqrt{2(100)}=\frac{384(198)}{945(199)}\sqrt{200}=5.71777[/math]

 

[math]\pi=2a^2=2(5.71777)^2=65.38574[/math]

 

which is also clearly wrong

 

What am I doing wrong?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

By Arclength Approximation Riemann Form

 

[math] 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}}[/math]

 

 

 

[math] 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 [/math]

 

 

 

[math] \Delta x = \frac{b - a}{n} = \frac{1}{n} [/math]

 

[math] x_i^* = a + i \cdot \Delta x = \frac{i}{n} [/math]

 

[math] x_{i-1}^* = a + (i - 1) \cdot \Delta x = \frac{i - 1}{n} [/math]

 

[math] \bar{x} = \frac{x_i^* + x_{i-1}^*}{2} = \frac{(\frac{i}{n}) + (\frac{i - 1}{n})}{2} = \frac{2i - 1}{2n} [/math]

 

 

 

[math] 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 }}[/math]

 

 

 

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

Edited by Xittenn

Share this post


Link to post
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.

How about (2/3)(4/5)(6/7)..... instead of doing the numerator and denominator separately?

Share this post


Link to post
Share on other sites

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

Did you mean this one?

Share this post


Link to post
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 [math]I_n[/math] is the result using the trapezoidal method for n steps, then

[math]I_{2n} + \frac{I_{2n}-I_n}{3}[/math]

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.