Why is this integral so difficult to approximate?

  gaussian, integral, numerical-methods, python

i have made a program that makes an approximation of the integral with Gaussian Quadrature method. My code is:

import numpy as np

def gaussian_quadrature(f, n):
    x, A = np.array(np.polynomial.legendre.leggauss(n))
    a,b = 0,1
    result = 0
    for i in range(0, n):
       q = ((b-a)*x[i] + a + b)/2
       p = ((a-b)*x[i] + a + b)/2
       result = result + A[i]*(f(q)+f(p))
    result = (b-a)*result/4
    return result

def integr(x):
   return 1/(x**2+0.0001)

approx = gaussian_quadrature(integr, 25)
print(approx)

The question I got in my homework is why the integral in the function integr(x) from 0 to 1 is difficult to approximate? The value of approximation is around 156.08. I thought it had something to do with the range, but no matter if I set n to be 25 or 90, the output at the last iteration will always be around 156. Sorry if the question don’t belong here.

Source: Python Questions

LEAVE A COMMENT