def gauss_laguerre(n): d = mp.matrix(mp.arange(1, 2 * n, 2)) e = mp.matrix(mp.arange(-1, -n - 1, -1)) z = mp.eye(n)[0, :] tridiag_eigen(mp, d, e, z) z = z.apply(lambda x: x**2) return d, z.T
def gauss_hermite(n): d = mp.matrix([mp.mpf('0.0') for _ in range(n)]) e = [mp.sqrt(k / 2) for k in mp.arange(1, n)] e.append(mp.mpf('0.0')) e = mp.matrix(e) z = mp.eye(n)[0, :] tridiag_eigen(mp, d, e, z) z = mp.sqrt(mp.pi) * z.apply(lambda x: x**2) return d, z.T
def gauss_legendre(n): d = mp.matrix([mp.mpf('0.0') for _ in range(n)]) e = [k / mp.sqrt(4 * k**2 - 1) for k in mp.arange(1, n)] e.append(mp.mpf('0.0')) e = mp.matrix(e) z = mp.eye(n)[0, :] tridiag_eigen(mp, d, e, z) z = 2 * z.apply(lambda x: x**2) return d, z.T
def gauss_genlaguerre(n, alpha): d = mp.matrix([i + alpha for i in mp.arange(1, 2 * n, 2)]) e = [-mp.sqrt(k * (k + alpha)) for k in mp.arange(1, n)] e.append(mp.mpf('0.0')) e = mp.matrix(e) z = mp.eye(n)[0, :] tridiag_eigen(mp, d, e, z) z = mp.gamma(alpha + 1) * z.apply(lambda x: x**2) return d, z.T
def gauss_gegenbauer(n, alpha): d = mp.matrix([mp.mpf('0.0') for _ in range(n)]) e = [ mp.sqrt(k * (k + 2 * alpha - 1) / ((2 * k + 2 * alpha - 1)**2 - 1)) for k in mp.arange(1, n) ] e.append(mp.mpf('0.0')) e = mp.matrix(e) z = mp.eye(n)[0, :] tridiag_eigen(mp, d, e, z) z = 2**(2 * alpha) * mp.beta(alpha + 1 / 2, alpha + 1 / 2) * z.apply(lambda x: x**2) return d, z.T
def _scheme_from_rc_mpmath(alpha, beta): # Create vector cut of the first value of beta n = len(alpha) b = mp.zeros(n, 1) for i in range(n - 1): b[i] = mp.sqrt(beta[i + 1]) z = mp.zeros(1, n) z[0, 0] = 1 d = mp.matrix(alpha) tridiag_eigen(mp, d, b, z) # nx1 matrix -> list of mpf x = numpy.array([mp.mpf(sympy.N(xx, mp.dps)) for xx in d]) w = numpy.array([mp.mpf(sympy.N(beta[0], mp.dps)) * mp.power(ww, 2) for ww in z]) return x, w
def gauss_jacobi(n, alpha, beta): d = mp.matrix([(beta**2 - alpha**2) / (2 * k + alpha + beta) / (2 * k + alpha + beta - 2) for k in mp.arange(1, n + 1)]) e = [ k * (k + alpha) * (k + beta) * (k + alpha + beta) / ((2 * k + alpha + beta)**2 - 1) for k in mp.arange(1, n) ] e = [ 2 / (2 * k + alpha + beta) * mp.sqrt(x) for k, x in zip(mp.arange(1, n), e) ] e.append(mp.mpf('0.0')) e = mp.matrix(e) z = mp.eye(n)[0, :] tridiag_eigen(mp, d, e, z) z = 2**(alpha + beta + 1) * mp.beta(alpha + 1, beta + 1) * z.apply(lambda x: x**2) return d, z.T
def _gauss_from_coefficients_mpmath(alpha, beta, decimal_places): mp.dps = decimal_places # Create vector cut of the first value of beta n = len(alpha) b = mp.zeros(n, 1) for i in range(n - 1): # work around <https://github.com/fredrik-johansson/mpmath/issues/382> x = beta[i + 1] if isinstance(x, numpy.int64): x = int(x) b[i] = mp.sqrt(x) z = mp.zeros(1, n) z[0, 0] = 1 d = mp.matrix(alpha) tridiag_eigen(mp, d, b, z) # nx1 matrix -> list of mpf x = numpy.array([mp.mpf(sympy.N(xx, decimal_places)) for xx in d]) w = numpy.array([ mp.mpf(sympy.N(beta[0], decimal_places)) * mp.power(ww, 2) for ww in z ]) return x, w