#!/usr/bin/python3 # Gauss-Legendre quadrature def int_gauss(f, nodes, weights): result = 0.0 for x, w in zip(nodes, weights): result += w * f(x) return result # compute nodes and weights on [-1, 1] with gaussxw.gaussxw(): from gaussxw import gaussxw N = 100 x, w = gaussxw(N) # adapt x -> x' et w -> w' to integration domain [a, b]: a, b = 0, 1 xp = 0.5*(b - a)*x + 0.5*(b + a) wp = 0.5*(b - a)*w # integrate some function over [a, b]: from math import atanh print("Résultat:", int_gauss(atanh, xp, wp))