Skip to content

Scripts Fun

Quadstronaut edited this page Jun 7, 2026 · 1 revision

Scripts: Fun

Scripts in Scripts/Fun/. Educational demonstrations and curiosities.


Get-PiApproximation.ps1

What it does: Approximates Pi using the Leibniz formula:

π/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - ...

More iterations produce a closer approximation, at the cost of CPU time.

Parameters:

Parameter Type Default Description
-Iterations int 1,000,000 Number of terms to sum

Usage:

# Default: 1,000,000 iterations
.\Scripts\Fun\Get-PiApproximation.ps1

# Higher accuracy (slower)
.\Scripts\Fun\Get-PiApproximation.ps1 -Iterations 10000000

Example output:

Pi is approximately 3.14159165358979 (after 1,000,000 iterations)
True Pi:            3.14159265358979323846...
Error:              9.99999994515327E-07

Notes on convergence:

The Leibniz formula converges very slowly. Each additional correct decimal digit requires roughly 10× more terms:

Iterations Correct digits (approx.)
1,000 ~3
1,000,000 ~6
1,000,000,000 ~9

For faster convergence, see:

Educational purpose: This script demonstrates iterative approximation, floating-point arithmetic, alternating series, and the relationship between series convergence rate and computational cost. It is not useful for computing Pi to high precision.

Clone this wiki locally