# L-12 MCS 507 Mon 18 Sep 2023 : simpson4pi

"""
Script to illustrate the use of the Simpson rule of scipy
on the approximation of Pi/4 via the area under sqrt(1 - x^2)
above the x-axis.

Illustrates the slow convergence of the Simpson rule,
which gives a relatively intensive computation.
"""

from scipy.integrate import simps
from scipy import sqrt, linspace, pi
print('10**k      approximation       error')
for k in range(2, 9):
    x = linspace(0, 1, 10**k)
    y = sqrt(1-x**2)
    I = 4*simps(y, x)
    print('10**%d: %.15e, %.3e' % (k, I, abs(I-pi))) 
