Let's play with a special number. Pi

Pi is a constant indicated with π, used in maths and physics, and it’s an irrational transcendent number, which means that its decimal figure don’t return periodically.

Pi is a constant indicated with π, used in maths and physics, and it’s an irrational transcendent number, which means that its decimal figure don’t return periodically.

In the plane geometry, π is defined as the ratio between the length of the circumference and the length of the diameter of the circle, or as the area of a circle whose radius is 1.

We want to create a program which calculates, with the Archimede’s method, an approximation of Pi, the nearest possible to its real value.

Archimede’s method, used for the first time by the mathematician in the III century b.C., expects to calculate Pi considering the length of a circumference, suitably chosen, and the perimeters of the polygon inscribed in it.

Look at this video to understand the method of Archimede, a Sicilian mathematician.

festadelpigreco

Pi is a constant indicated with π, used in maths and physics, and it’s an irrational transcendent number, which means that its decimal figure don’t return periodically.

In the plane geometry, π is defined as the ratio between the length of the circumference and the length of the diameter of the circle, or as the area of a circle whose radius is 1.

We want to create a program which calculates, with the Archimede’s method, an approximation of Pi, the nearest possible to its real value.

Archimede’s method, used for the first time by the mathematician in the III century b.C., expects to calculate Pi considering the length of a circumference, suitably chosen, and the perimeters of the polygon inscribed in it.

 

Archimede’s method provides to calculate Pi, considering the measure of a circumference(1) suitably chosen (radius = ½) and the perimeters of the regular polygon(2) inscribed in it.

The circumference is calculated as , therefore substituting the measure of the radius which is ½, the length of the circumference is equal to π.

Considering a polygon inscribed in the circumference, it is noted that the more the number of its sides increases, the more the value of its perimeter approaches that of the circumference, in this case π.

To calculate the perimeter of a regular polygon with an arbitrary number of sides (n).

A segment (AD) is constructed that starts from A and is perpendicular to the side BC so that it divides it in half (BD = DC).

We consider the right triangle in the figure: the segment BD (a) is equal to half the side and, thanks to trigonometry(3), we can deduce that sinΘ(4) is 2a, which is also the measure of the side.

The perimeter of a regular polygon is calculated as the number of sides for their length, therefore it is equal to

P = n * 2a

At this point, with all the substitutions, the perimeter is equal to

P = n sin(θ)

Reasoning about the angle, it is noted that it is equal to the full angle (360°) divided by twice the number of sides (a = ½ side).

P = n sin((360°)/2n) = n sin((180°)/n)

Therefore:

π = n sin((180°)/n)

 

Code

package pigreco;
public class Pigreco {
public static void main(String[] args) {

double p;/** initialization of a double variable;
* double variables, unlike int,
* represent decimal numbers with many digits after the comma */

int lati;/** the number of sides is an integer,
* because there can’t be a polygon with, for example, 6.7 sides */

for(lati=3;lati<=10000;lati++)/** the for loop allows to repeat the
* function that is inside the curly braces for a number of
* times such that the number of sides of the polygon goes from 3 to 10000 */

{

p = lati*(Math.sin(Math.toRadians(180/lati)));/** formalization
* of the operation pi = sides x sin (180/sides) */

System.out.println("number of sides= " + lati + " value of pi = " + p + " ");/** displays on video number of sides = … value of pi = … */

}

}
}

On the video will appear 10000 values of sides and the corresponding approximations of the value of pi

[…]

number of sides = 174 value of pi = 3.036718720087331
number of sides = 175 value of pi = 3.0541711265246145
number of sides = 176 value of pi = 3.071623532961898
number of sides = 177 value of pi = 3.0890759393991813
number of sides = 178 value of pi = 3.106528345836465
number of sides = 179 value of pi = 3.1239807522737486
number of sides = 180 value of pi = 3.141433158711032

[…]

 

Conclusions

It is demonstrated that, as the number of sides of the inscribed polygon increases, the value of pi becomes more and more precise.

The use of a calculator allows to perform elementary operations between numbers in very short times, offering the possibility to solve complex calculations through the use of algorithms; however, the calculator, being a finite machine, is forced to operate with numbers having a finite number of digits, therefore the result will be transcribed through a truncation or an approximation. In general, a real number introduced into the calculator is approximated through a machine number.

This means that, executing an algorithm on a calculator, there is a creation and propagation of errors, therefore the result obtained from the algorithm differs from the exact result, i.e. from what would be obtained working with real numbers.

 

Legend

1) Circumference: geometric place of the points equidistant from a fixed point called center.

2) Regular polygon: convex portion of the Euclidean plane bounded by a closed broken line, formed by a succession of segments of equal length (called sides), which form equal angles between them.

3) Trigonometry: part of the math