20 @brief This script computes Gauss-Jacobi quadrature roots and weights using SciPy.
23 The script takes polynomial degree, alpha, beta, and number of digits
24 (precision) parameters to compute Gauss-Jacobi quadrature roots and weights. It
25 uses sympy.integrals.quadrature.gauss_jacobi for the calculations.
32 from sympy.integrals.quadrature
import gauss_jacobi
35 def main(n, alpha, beta, n_dig):
36 roots, weights =
gauss_jacobi(n=n, alpha=alpha, beta=beta, n_digits=n_dig)
37 for idx, root
in enumerate(roots):
38 sign =
" " if root >= 0
else ""
39 root_str = f
"{float(root):23.17E}"
40 weight_str = f
"{float(weights[idx].evalf()):23.17E}"
41 print(f
"Root:{sign} {root_str} Weight: {weight_str}")
44 if __name__ ==
"__main__":
45 parser = argparse.ArgumentParser(description=
"Compute Gauss-Jacobi quadrature.")
46 parser.add_argument(
"--npts", type=int, default=5, help=
"Degree of the polynomial.")
47 parser.add_argument(
"--alpha", type=float, default=0, help=
"Alpha parameter.")
48 parser.add_argument(
"--beta", type=float, default=12, help=
"Beta parameter.")
49 parser.add_argument(
"--n_dig", type=int, default=15, help=
"Precision.")
51 args = parser.parse_args()
53 main(args.npts, args.alpha, args.beta, args.n_dig)
subroutine gauss_jacobi(npts, alpha, beta, x, wts, method)
Compute the Gauss-Jacobi quadrature nodes and weights.
def main(n, alpha, beta, n_dig)