def __init__(self, npts): # Legendre poly lp = lambda x: mp.legendre(npts - 1, x) # Coefficients of lp cf = mp.taylor(lp, 0, npts - 1) # Coefficients of dlp/dx dcf = [i*c for i, c in enumerate(cf[1:], start=1)] self.points = [mp.mpf(-1)] + mp.polyroots(dcf[::-1]) + [mp.mpf(1)] self.weights = [2/(npts*(npts - 1)*lp(p)**2) for p in self.points]
def __init__(self, npts): # Legendre poly lp = lambda x: mp.legendre(npts, x) self.points = mp.polyroots(mp.taylor(lp, 0, npts)[::-1]) self.weights = [2/((1 - p*p)*mp.diff(lp, p)**2) for p in self.points]