sympy_gauss_jac.py
Go to the documentation of this file.
1 # BEGIN_HEADER
2 # -----------------------------------------------------------------------------
3 # Gauss-Jacobi Quadrature Implementation
4 # Authors: Rohit Goswami <rgoswami[at]ieee.org>
5 # Source: GaussJacobiQuad Library
6 # License: MIT
7 # GitHub Repository: https://github.com/HaoZeke/GaussJacobiQuad
8 # Date: 2023-08-28
9 # Commit: c442f77
10 # -----------------------------------------------------------------------------
11 # This code is part of the GaussJacobiQuad library, providing an efficient
12 # implementation for Gauss-Jacobi quadrature nodes and weights computation.
13 # -----------------------------------------------------------------------------
14 # To cite this software:
15 # Rohit Goswami (2023). HaoZeke/GaussJacobiQuad: v0.1.0.
16 # Zenodo: https://doi.org/10.5281/ZENODO.8285112
17 # ---------------------------------------------------------------------
18 # END_HEADER
19 """!
20 @brief This script computes Gauss-Jacobi quadrature roots and weights using SciPy.
21 
22 @details
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.
26 
27 @author Rohit Goswami
28 @date 26-08-2023
29 """
30 import argparse
31 
32 from sympy.integrals.quadrature import gauss_jacobi
33 
34 
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}")
42 
43 
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.")
50 
51  args = parser.parse_args()
52 
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)