def compute_gauss_jacobi_points(a, b, m): """Computes the m roots of P_{m}^{a,b} on [-1,1] by Newton's method. The initial guesses are the Chebyshev points. Algorithm implemented in Python from the pseudocode given by Karniadakis and Sherwin""" x = [] eps = 1.e-8 max_iter = 100 for k in range(0, m): r = -math.cos((2.0 * k + 1.0) * math.pi / (2.0 * m)) if k > 0: r = 0.5 * (r + x[k - 1]) j = 0 delta = 2 * eps while j < max_iter: s = 0 for i in range(0, k): s = s + 1.0 / (r - x[i]) f = jacobi.eval_jacobi(a, b, m, r) fp = jacobi.eval_jacobi_deriv(a, b, m, r) delta = f / (fp - f * s) r = r - delta if math.fabs(delta) < eps: break else: j = j + 1 x.append(r) return x
def compute_gauss_jacobi_points(a, b, m): """Computes the m roots of P_{m}^{a,b} on [-1,1] by Newton's method. The initial guesses are the Chebyshev points. Algorithm implemented in Python from the pseudocode given by Karniadakis and Sherwin""" x = [] eps = 1.e-8 max_iter = 100 for k in range(0, m): r = -math.cos((2.0 * k + 1.0) * math.pi / (2.0 * m)) if k > 0: r = 0.5 * (r + x[k - 1]) j = 0 delta = 2 * eps while j < max_iter: s = 0 for i in range(0, k): s = s + 1.0 / (r - x[i]) f = jacobi.eval_jacobi(a, b, m, r) fp = jacobi.eval_jacobi_deriv(a, b, m, r) delta = f / (fp - f * s) r = r - delta if math.fabs(delta) < eps: break else: j = j + 1 x.append(r) return x
def compute_gauss_jacobi_rule(a, b, m): xs = compute_gauss_jacobi_points(a, b, m) a1 = math.pow(2, a + b + 1) a2 = math.gamma(a + m + 1) a3 = math.gamma(b + m + 1) a4 = math.gamma(a + b + m + 1) a5 = math.factorial(m) a6 = a1 * a2 * a3 / a4 / a5 ws = [a6 / (1.0 - x**2.0) / jacobi.eval_jacobi_deriv(a, b, m, x)**2.0 for x in xs] return xs, ws
def compute_gauss_jacobi_rule(a, b, m): xs = compute_gauss_jacobi_points(a, b, m) a1 = math.pow(2, a + b + 1) a2 = math.gamma(a + m + 1) a3 = math.gamma(b + m + 1) a4 = math.gamma(a + b + m + 1) a5 = math.factorial(m) a6 = a1 * a2 * a3 / a4 / a5 ws = [a6 / (1.0 - x**2.0) / jacobi.eval_jacobi_deriv(a, b, m, x)**2.0 for x in xs] return xs, ws