My Projects
π-Calculator
π-Calculator is a program written in Python 3 that can approximate the mathematical constant π (pi). This program has actually two versions:
1. Approximation of π by approximation of the integral from 0 to 1 of the function f(x)=root(2*x - x²) (conic section, where the conic is a circle). This integral has the same value as the area of a quarter of a circle with radius=1; integral = ¼*π*r² =¼*π*1²=¼*π. The output of the program therfore is 4 times the value of the integral.
2. Approximation of π by the Leibniz formula for π. The Leibniz formula states that 1-1/3+1/5-1/7+...=π/4. The program creates an array with the first n (input for iterations) odd numbers. The reciprocal of these numbers will be added to or subtracted from the output variable s=0, which will be multiplied by 4 at the end.
Results of both methods after 10 million iterations: 1.Method: 3.1415920535527864 (off by 0.000019%); 2. Method: 3.1415925535897915 (off by 0.0000032%).
DOWNLOAD 1. Method (Integral of conic section)
DOWNLOAD 2. Method (Leibniz Formula)
September 2016