gjp_gw Module Reference

Module for computing Gauss-Jacobi quadrature nodes and weights using the Golub-Welsch (GW) method. More...

Functions/Subroutines

subroutine gauss_jacobi_gw (npts, alpha, beta, x, wts)
 Computes the zeros and weights for Gauss-Jacobi quadrature. More...
 

Detailed Description

Module for computing Gauss-Jacobi quadrature nodes and weights using the Golub-Welsch (GW) method.

The implementation is based on the Golub-Welsch method as used in chebfun (https://chebfun.org) and references: [1] G. H. Golub and J. A. Welsch, "Calculation of Gauss quadrature rules", Math. Comp. 23:221-230, 1969. [2] N. Hale and A. Townsend, "Fast computation of Gauss-Jacobi quadrature nodes and weights", SISC, 2012. [3] Kautsky, J., Elhay, S. Calculation of the weights of interpolatory quadratures. Numer. Math. 40, 407–422 (1982). https://doi.org/10.1007/BF01396453

Function/Subroutine Documentation

◆ gauss_jacobi_gw()

subroutine gjp_gw::gauss_jacobi_gw ( integer, intent(in)  npts,
real(dp), intent(in)  alpha,
real(dp), intent(in)  beta,
real(dp), dimension(npts), intent(out)  x,
real(dp), dimension(npts), intent(out)  wts 
)

Computes the zeros and weights for Gauss-Jacobi quadrature.

This subroutine computes the zeros (x) and weights (w) for Gauss-Jacobi quadrature by diagonalizing the Jacobi matrix. The solution involves finding the eigenvalues of the Jacobi matrix, which are the roots of the Jacobi polynomial. Since the Jacobi matrix is a symmetric tridiagonal matrix, the LAPACK DSTEQR routine is used, utilizing its specific form for tridiagonal matrices.

The Jacobi matrix is represented as: [ J = \begin{bmatrix} \alpha & \beta & 0 & \cdots & 0 \ \beta & \alpha & \beta & \cdots & 0 \ \vdots & \vdots & \ddots & \ddots & \vdots \ 0 & 0 & \cdots & \beta & \alpha \end{bmatrix} ]

Z is initialized as the identity matrix, and the eigenvectors are used to compute the wts.

Parameters
[in]nptsNumber of x
[in]alphaparameter for Jacobi polynomials
[in]betaparameter for Jacobi polynomials
[out]xZeros of Jacobi polynomials
[out]wtsweights for Gauss-Jacobi quadrature

Definition at line 59 of file gjp_gw.f90.

60  integer, intent(in) :: npts
61  real(dp), intent(in) :: alpha, beta
62  real(dp), intent(out) :: x(npts), wts(npts)
63  real(dp) :: zeroeth_moment
64  type(gjp_sparse_matrix) :: jacobi_mat
65  real(dp) :: diagonal_elements(npts), &
66  off_diagonal_elements(npts - 1), &
67  eigenvectors(npts, npts), &
68  workspace(2 * npts - 2)
69  integer :: computation_info, i
70 
71  jacobi_mat = jacobi_matrix(npts, alpha, beta)
72  zeroeth_moment = jacobi_zeroeth_moment(alpha, beta)
73 
74  ! Extract diagonal and off-diagonal elements
75  diagonal_elements = jacobi_mat%diagonal(1:npts)
76  off_diagonal_elements = jacobi_mat%off_diagonal(1:npts - 1)
77 
78  ! Initialize eigenvectors as identity matrix
79  eigenvectors = 0.0_dp
80  do i = 1, npts
81  eigenvectors(i, i) = 1.0_dp
82  end do
83 
84  ! Diagonalize the Jacobi matrix using DSTEQR.
85  call dsteqr('V', npts, diagonal_elements, off_diagonal_elements, &
86  eigenvectors, npts, workspace, computation_info)
87 
88  if (computation_info /= 0) then
89  write (*, *) 'Error in DSTEQR, info:', computation_info
90  error stop
91  end if
92 
93  ! The eigenvalues are the nodes
94  x = diagonal_elements
95  ! The weights are related to the squares of the first components of the
96  ! eigenvectors
97  wts = eigenvectors(1, :)**2 * zeroeth_moment
98