Results 1 to 8 of 8

Thread: Pi

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Pi

    I want to make a function in which returns the value of PI.

    However, I do not want to limit it to just "3.14" or any numbers like that. I want to make it so the user can pass how many deciminal places they want the function to get to.

    So my question is, is there any mathmatical equations to create pi? I can't remember learning about any in high school or college math, so I don't even know how the hell pi is determined.

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Pi is the circumference of a circle divided by its diameter. I don't know of any function to find pi to x amount of decimals but you never need it to more than 5-6 anyway, as you can never measure the other variable to such a degree of accuracy.

    eg is you know pi to 30 decimals but the radius to only 2, then the circumference can only be worked out to the nearest two decimals (or at least should be rounded so).

    But to get a great value for pi, goto:
    http://3.141592653589793238462643383...0974944592.jp/
    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Acidic
    But to get a great value for pi, goto:
    http://3.141592653589793238462643383...0974944592.jp/
    Holy Hell!

    lol

    Is that all determined by an equation and generated on the fly?

  4. #4
    Lively Member
    Join Date
    Oct 2003
    Location
    Guildford, UK
    Posts
    91
    Pi can be expressed: pi = 4tan-11

    tan-1x = x - x3/3 + x5/5 - ...

    So,

    pi = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - ... )

    You could use a loop to go through a certain number of terms although that won't give you a given number of decimal places...

  5. #5
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    Other formulas for pi can be found on this page. It has algorithms that converge a lot quiker then the tan[sup]-1[.sup] method. IIRC the method desrcibed in formula 113 is the fastest known formula for calculating pi.

  6. #6
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    from your link
    D. Terr (pers. comm.) noted the curious identity
    (3,1,4) = (1,5,9) + (2,6,5) Mod 10
    that gives the first 9 digits of pi.
    Interesting, indeed!
    Why didn't they display the following:

    If we say A, B, and C are dimmed from 0 to 2, and
    A() = (3,1,4)
    B() = (1,5,9)
    C() = (2,6,5)

    that the individual sums which form a 4th set, D(), such that

    D(i) = A(i) + B(i) + C(i)

    then D(i) = (i+1)*D(0), ie...

    D(0) = A(0) + B(0) + C(0) => 3 + 1 + 2 = 6
    D(1) = A(1) + B(1) + C(1) => 1 + 5 + 6 = 12
    D(2) = A(2) + B(2) + C(2) => 4 + 9 + 5 = 18

    A Definite Linear Progression!



  7. #7
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    basically pi came from the funda of (circumference/diameter) of any circle.


    in VB u can use Math.PI and then round it to the number od decimals u need.

    but ofcourse there is a limit and that depends on the data type.....
    Regards

  8. #8
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    One interesting way to do it is to use a monte carlo method...

    imagine a square 1000 x 1000 pixels which is encompassing the lower-right quater of a circle (radius 1000)...





    The yellow region is a quarter of the total area of the circle. Generating random points (500000+ iterations) in the square will give the following ratio...

    (Number of random points falling in yellow region) : (Total number of random coordinates tried).

    This ratio is equal(ish) to ...

    (Area of yellow region) : (area of entire square)

    And since the square is 1000000 pixels^2 we can deduce the area of the yellow region. Multiply that by 4 to get the circle's area, and then rearrange

    Area = Pi * r^2 to get Pi!

    The accuracy is determined by the number of iterations. Its not very efficient but you are literally pulling pi out of thin air!!!
    I don't live here any more.

Posting Permissions

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



Click Here to Expand Forum to Full Width