• Lucid Dreaming - Dream Views




    Results 1 to 12 of 12
    1. #1
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      929

      How is pi calculated?

      My friend gave me the challenge of calculating pi, but I keep getting stuck. I keep getting pi defined in terms of itself. What am I doing wrong?

      Code:
      x^2 + y^2 = 1  - Equation for a circle when r = 1
      y = sqrt(1 - x^2)  - Move y to other side of equation
      A/4 =  ∫(0 to 1) (sqrt(1 - x^2))  - solving area under the curve for the positive x and y
      A/4 = (sqrt(1 − 1^2) * 1 + asin(1))/2 - (sqrt(1 − 0^2) * 0 + asin(0))/2 - definite integral
      A/4 = (1 + asin(1))/2 - FUCK asin(1) = pi/4
      I know I've done this before. Grrr.

    2. #2
      Member Achievements:
      1 year registered Veteran First Class 5000 Hall Points

      Join Date
      Sep 2004
      Gender
      Location
      Seattle, WA
      Posts
      2,503
      Likes
      217
      You can write Pi in terms of a taylor series. The more terms you tag on, the more precise your value for pi. If you can write Pi in terms of a trigonometric function (I think arctan is pretty standard for this), then all you need to do is replace "arctan(whatever)" with its taylor expansion, and you've got a way to numerically get at it.

      I am not sure how the 1000s of digits are calculated most efficiently, but it's definitely some iterative process similar to expanding a taylor series. Wikipedia article should have that answer.

    3. #3
      Member Achievements:
      1 year registered Veteran First Class 5000 Hall Points

      Join Date
      Sep 2004
      Gender
      Location
      Seattle, WA
      Posts
      2,503
      Likes
      217
      Ah here we go, I googled it and it came up with basically what I was saying:

      Math Forum - Ask Dr. Math

      EDIT: Here's some more fun: 1 Million Digits of Pi

      Code:
                    $|=3,141592;sub _
                {[email protected]_}sub o{_++$O[0
              ];_ 0for 1..$#O}sub O{$;=int
            $=/10,'0/^           ^';if($;<9)
           {_$_ for                 @O;;@O=()
          ;0}push                     @O,$;;0
         ,;[email protected]                       O,'.'if
         $^==1;                         0;if($;
         ==10){          print          ,o,@O=(
         )}}$?=         1000000         ;$-=10*
         (q/@O=       digits of pi      =10/,1)
         *int($?                       /3)+1;$
          [email protected]                     ,[0..$-]
           ,;for$^                   (1..$?){
           $"=$-;$O                 =0;until
             ($"<0){$/=          2*$"+1;$/=
              10if$/==1;$==10*$,[$"]+$O;$,
                [$"]=$=%$/;$O=int($=/$/
                     )*$"--,10}O}o
      I tested it on my box. It seems to work, though artificially slowly.
      Last edited by Replicon; 10-18-2010 at 03:02 AM.

    4. #4
      Banned
      Join Date
      Nov 2007
      Gender
      Posts
      1,674
      Likes
      200
      I did it once with a geometric figure, The number of itterations got one closer and closer, I do not remember if I kept it in the current version of The Delian Quest or not. I used Mathcad.

    5. #5
      Xei
      UnitedKingdom Xei is offline
      Banned
      Join Date
      Aug 2005
      Posts
      9,984
      Likes
      3082
      As pi can never be expressed precisely in decimal form, the best you can do is an approximation.

      There are many ways. You could do it by integration as you currently are; what you should be doing is trying to approximate the numerical value of the integral in some way, for example by approximating the area underneath the curve as a series of rectangles, trapezia, or quadratic curves (the last one is called Simpson's Rule and is very efficient).

      You could approximate a circle as a polygon of some sort and calculate its perimeter with the Cartesian length formula (it would probably be easiest to write the equation in parametric form, (cos(t), sin(t))).

      The problem with the above is that they are single calculations with a preordained degree of accuracy which don't allow for any further refinement.

      So you could as Replicon says use some infinite series. The classic way is the arctan integral, from 0 to 1 of (1 + x^2)^-1, which you do in two ways: the standard way gives you arctan(1) - arctan(0) = pi/4; for the second way you use the binomial theorem to express the integrand as an infinite polynomial, which you then integrate and end up with 1 - 1/3 + 1/5 - 1/7 ...

      Hence pi = 4 (1 - 1/3 + 1/5 - 1/7...) which is rather beautiful.

      However I don't think it converges very quickly. If the point of what you're doing is to understand what's going on then the above is the easiest option, but if you're after a fast iteration for some reason, I believe Wikipedia has a whole collection of them.

    6. #6
      Banned
      Join Date
      Nov 2007
      Gender
      Posts
      1,674
      Likes
      200
      Quote Originally Posted by Xei View Post
      As pi can never be expressed precisely in decimal form, the best you can do is an approximation..
      That is one of the differences between a tautologic, like common grammar, arithmetic, etc, versus a relatiologic, which is a geometric figure.

      It also tells one the meaning of irrational, which simply means the inability to acquire a name for something, by the conventions of that grammar, in a given logic system.

      What is irrational in arithmetic, is perfectly rational in geometry.

      One can see the effect on a lot of geometric figures.

    7. #7
      ICY BLUE BlueBlue's Avatar
      Join Date
      Oct 2010
      LD Count
      not enough
      Gender
      Location
      Rubidoux (say it like Ruby Dew)
      Posts
      42
      Likes
      3
      I think Taylor expansion is the best way

    8. #8
      Banned
      Join Date
      Sep 2010
      Gender
      Location
      Texas
      Posts
      1,362
      Likes
      613
      Deified is spelled the same way backwards as it is forwards. I'm not sure if that has anything to do with pi, but somehow it feels relevant to this thread as I have often compared its lack of conviction to that of Xei's inability to ban anyone thus far.

    9. #9
      Rational Spiritualist DrunkenArse's Avatar
      Join Date
      May 2009
      Gender
      Location
      Da Aina
      Posts
      2,941
      Likes
      1091
      Quote Originally Posted by greenhavoc View Post
      Deified is spelled the same way backwards as it is forwards. I'm not sure if that has anything to do with pi, but somehow it feels relevant to this thread as I have often compared its lack of conviction to that of Xei's inability to ban anyone thus far.
      Xei's "inability" to ban anyone could well be taken as just being generally awesome. I can't really see how palindromes are relevant to pi (although palindromic patterns are relevant to primes) but I could be wrong. There is certainly something circular about them. Maybe socially conservative politics is related to pi as well.

    10. #10
      Banned
      Join Date
      Sep 2010
      Gender
      Location
      Texas
      Posts
      1,362
      Likes
      613
      You're right, I am pretty clever. Absolute[ly] in fact.

    11. #11
      Rational Spiritualist DrunkenArse's Avatar
      Join Date
      May 2009
      Gender
      Location
      Da Aina
      Posts
      2,941
      Likes
      1091
      Quote Originally Posted by greenhavoc View Post
      You're right, I am pretty clever. Absolute[ly] in fact.
      xkcd: Words that End in GRY

      The fifth panel also applies to you.

    12. #12
      Banned
      Join Date
      Sep 2010
      Gender
      Location
      Texas
      Posts
      1,362
      Likes
      613
      ^[Ha] but whatever,the genius of my ignorance hasn't failed me yet, PhilosopherStoned.

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •