Welcome, guest | Sign In | My Account | Store | Cart

Pi is a constant, an irrational number and its notation represent the sixteenth letter of the Greek alphabet, though its value is equal to the ratio of a circle’s circumference to its diameter.

However, a Muslim scientist Abu-Abdullah Muhammad Ibn Musa al-Khwarizmi the founder of algebra ( derived from the Arabic word El-Jabr ), arithmetic, and trigonometry, an astronomer, and a geographer C850 studied and proved Pi’s irrationality.(algorithm is derived from his name Khwarizmi ).

I used the circle equation x²+y² = 1 of radius 1 centred at (0,0) and the circle area’s formula to approximate Pi value. y²= 1-x² and y = √(1-x²) is the upper semicircle which will extend from x = -1 to x = 1 and the rectangle method is used to approximate this area of an interval [-1,1].

The area of a circle is A = πr², thus the semicircle of radius 1 will have an area A = ½ π(1²).

Using my Pi_Approximation program allows you to represent Pi to infinity of digits, and this will depend of the project type and the precision needed, though space programs require to approximate pi at its maximum precision.

And my Pi_Approximation program allows you to make a better Pi’s approximation than the scientific Calculators

Python, 153 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#On the name of ALLAH and may the blessing and peace of Allah 
#be upon the Messenger of Allah Mohamed Salla Allahu Aliahi Wassalam.
#Author : Fouad Teniou
#Date : 23/02/10
#version :2.6

"""
Pi_approximation uses the subinterval_length function and return
its value and yield all the points values while using the subinterval_point
function and Pi function compute Pi approximation with 16 decimal places
the greater the value of the number the more precise is Pi value 
"""

class Pi_Approximation(object):
    """
    Class that represent Pi approximation
    """
    def __init__(self, number):
        """
        Pi_Approximation constructor takes the number constant
        """
        self.number = number
        
    def subinterval_length(self):
        """
        Compute subinterval_length 
        """
        sub_length = 2/float(self.number)
        return sub_length
    
    def subinterval_point(self):
        """
        Compute the value of each point 
        """

        #attempt to yield all the Xk points values using the subinterval_point        
        try:
            for item in range(1,self.number + 1):
                sub_point = -1 + ((item - 1/2.0)* Pi_Approximation.subinterval_length(self))
                yield sub_point
        
        #Raise TypeError if input is not numerical
        except TypeError:
            print "\n<The entered value is not a number"
    
    def Pi(self):
        """
        Computing Pi value.
        """

        #attempt to Approximate Pi for a given value        
        try:
 
            my_sum = 0    #Set my_sum to 0
            
            # using subinterval_point function to compute Pi approximation.
            # the greater the value of the number the more accurate result
            for self.point in Pi_Approximation.subinterval_point(self):
            
                self.pi_X = pow((1-self.point**2),0.5)
                my_sum += self.pi_X
                pi = (my_sum * Pi_Approximation.subinterval_length(self))*2
                yield repr(pi)
                
        #Raise TypeError if input is not numerical
        except TypeError:
            print  "\n<The entered value is not a number" 

if __name__ == '__main__':
    for arg in xrange(600000,2700000,300000):
    
        pi = Pi_Approximation(arg)
        for i in pi.Pi():
            pass
        print i

#######################################################################
# FT python "C:\Users\Pi1.py"
#
# 3.1415926556860203
# 3.1415926547308004
# 3.1415926543309367
# 3.1415926541200871
# 3.1415926539930723
# 3.141592653909842
# 3.14159265385199
##########################################################################################

#Version : Python 3.2

#class Pi_Approximation(object):
#    """
#    Class that represent Pi approximation
#    """
#    def __init__(self, number):
#        """
#        Pi_Approximation constructor takes the number constant
#        """
#        self.number = number
#        
#    def subinterval_length(self):
#        """
#        Compute subinterval_length 
#        """
#        sub_length = 2/float(self.number)
#        return sub_length
#    
#    def subinterval_point(self):
#        """
#        Compute the value of each point 
#        """
#
#        #attempt to yield all the Xk points values using the subinterval_point        
#        try:
#            for item in range(1,self.number + 1):
#                sub_point = -1 + ((item - 1/2.0)* Pi_Approximation.subinterval_length(self))
#                yield sub_point
#        
#        #Raise TypeError if input is not numerical
#        except TypeError:
#            print("\n<The entered value is not a number")
#    
#    def Pi(self):
#        """
#        Computing Pi value.
#        """
#
#        #attempt to Approximate Pi for a given value       
#        try:
# 
#            my_sum = 0    #Set my_sum to 0
#            
#            # using subinterval_point function to compute Pi approximation.
#            # the greater the value of the number the more accurate result
#            for self.point in Pi_Approximation.subinterval_point(self):
#            
#                self.pi_X = pow((1-self.point**2),0.5)
#                my_sum += self.pi_X
#                pi = (my_sum * Pi_Approximation.subinterval_length(self))*2
#                yield ascii(pi)
#                
#        #Raise TypeError if input is not numerical
#        except TypeError:
#            print("\n<The entered value is not a number") 
#
#if __name__ == '__main__':
#  
#    for j in range(600000,2700000,300000):
#        pi = Pi_Approximation(j)
# 
#        for i in pi.Pi():
#            pass
#        print (i)

3 comments

Fouad Teniou (author) 11 years, 8 months ago  # | flag
Fouad Teniou (author) 10 years, 4 months ago  # | flag

A switch to C# and a new link

http://archive.msdn.microsoft.com/fouadteniou