Abstract
An algorithm and a MATLAB implementation for computing the Kummer function U(a,b,x) and its derivative is given in this paper. The algorithm is efficient and accurate. Numerical tests show that the MATLAB algorithm allows the computation of the function with \(\sim 10^{-14}\) relative accuracy in the parameter region (a,b,x) ∈ (0,500) × (0,500) × (0,1000) in double-precision floating point arithmetic.
Similar content being viewed by others
Avoid common mistakes on your manuscript.
1 Introduction
Many applications in physics and engineering involve the computation of confluent hypergeometric functions or some of their particular cases (Airy and Bessel functions, Laguerre polynomials, parabolic cylinder functions etc.) See [1, 2, 8, 12] or [11, §13.28] for some examples of applications in physics. As an additional example, in recent work we have obtained expansions for the relativistic Fermi-Dirac integral and its derivatives (of great importance in stellar astrophysics) where confluent hypergeometric functions play a key role [3, 5].
In spite of their importance, few algorithms are available in double-precision floating point arithmetic for the computation of any of the standard solutions of the Kummer’s equation in the case of real or complex parameters. For the function M(a,b,x), some algorithms can be found in the literature (see [9, 10]); however, for the second solution U(a,b,x), no double-precision algorithms with good uniform accuracy seem to be available, as far as we know. For example, the SLATEC library [16] includes the Fortran 77 function dchu.f which implements the confluent Kummer function U(a,b,x) for real parameters a, b and argument x. However, one has to be careful when using dchu.f to compute U(a,b,x) when a or b are large in comparison to x because a significant loss of accuracy occurs in the computations. Another example of a double-precision implementation for the Kummer U(a,b,x) function which is not free of accuracy problems is the function hyperu included in the SCIPY [7] module scipy.special. Having accurate efficient double-precision implementations is of interest in, for example, applications where a large number of function evaluations are needed (such as in the condensed matter or astrophysical calculations). On the other hand, extended precision implementations are given in Mathematica, Maple or Arb [6].
In this paper, we describe an efficient and accurate algorithm implemented in MATLAB for computing the Kummer U(a,b,x) function and its derivative. The function U(a,b,x) satisfies the following integral representation
valid for Ra > 0, \(b \in \mathbb {C}\) and x > 0.
In the algorithm, we consider real positive values of the function arguments a,b,x. The algorithm uses series for small values of the parameters, asymptotic expansions for large values of the parameters and a double-precision implementation of the algorithm described in [14] in the rest of cases. Our numerical tests show that the resulting algorithm is both accurate and efficient.
2 Computation for small values of the parameters
For \(0 <a, b <\frac 12\) and 0 < x < 1, we use the series given in [4] for the Kummer function U(a,b,z) and its derivative
where the coefficients \({w_{m}^{d}}\) can be written in terms of the wm coefficients
The coefficients wm satisfy
where
with Am = Γ(m + 1)Γ(2 − b + m)Γ(a + m + 1) and Bm = z−bΓ(a − b + 1 + m)Γ(b + 1 + m)Γ(m + 2).
To compute wm for m = 1,2,... using (2.4), it is convenient to obtain a stable recursion for um when b is small. It is possible to verify that
where
The starting u0 value of the recursion given in (2.5) is computed as u0 = v0w0, where \(v_{0}=\frac {(1-b) \pi b}{\sin \limits (\pi b)}\) and for calculating w0, we use
where r = b − 1, \(\tilde {z}_{b}=-e^{q}\log z \frac {\sinh q}{q}\) with \(q=-\frac {b}{2}\log z\) and
with
For computing G(a,b), we use the series
where the first three c(k) coefficients are c(2) = 0.57721566490153286, c(3) = − 0.65587807152025388 and c(4) = − 0.04200263503409523. More c(k) coefficients are given in Table 1 of [4].
3 Algorithm based on the use of recurrences
One of the key ingredients in the algorithm described in [14] to evaluate U(a,b,x) is the use of three-term recurrence relations satisfied by the function with respect to the parameters a and b.
With respect to the a parameter, we have
and with respect to the b parameter,
As discussed for example in [13], the Kummer function U(a,b,x) is the minimal solution of the three-term recurrence relation (3.1). Therefore, the forward computation of the recursion is ill-conditioned and backward recursion should be applied. On the contrary, U(a,b,x) is a dominant solution of (3.2) and forward recursion is possible.
Briefly, the algorithm described in [14] uses a sophisticated version of the backward a-recursion to compute U(a,b,x) for 0 < b < 1. This recursion is computed using starting values given by asymptotic expansions in terms of Bessel functions (for small x) or Miller algorithm’s when x is not small. For b > 1, backward recursion (3.1) is first applied to a value \(\tilde {b}=b-[b]\) in the interval [0,1]; then, the forward b-recursion (3.2) is applied. Technical details can be seen in [14]. This algorithm works very well in extended precision; however, in double-precision floating point arithmetic, some loss of accuracy could appear when using the recursions for large values of the parameter a. This is the reason why it is better to use an alternative method of computation for large values of the parameters, such as the expansions described in the next section.
4 Asymptotic expansions for large values of the parameters
We consider the recent expansion given in [15]
where
with τ = t0/μ, β = b/z and μ = (b − a)/z.
The first coefficients of the expansion (4.1) are
4.1 Expansion for \({U^{\prime }(a,b+1,z)}\)
For obtaining the asymptotic expansion of \(U^{\prime }(a,b+1,z)\) we consider the relation
and use the integral (see (4.3) of [15])
where λ = b − a. We write this in the form
where, with μ = λ/z,
The function ϕ(t) is the same as used in [15, §3], and the saddle point t0 and the coefficients are the same as used in that section, up to a factor (− 1)n. We obtain the expansion
where
and
The saddle point t0 is given by
with expansion
The first few \(\widetilde {f}_{n}\) coefficients are \(\widetilde {f}_{0}=1\) and
5 Numerical testing and algorithm
The set of MATLAB functions implementing the methods used are:
-
1.
Uabxsmall(a,b,x). Implementation of the method given in Section 2.
-
2.
Uabxrec(a,b,x). Implementation of the method given in Section 3.
-
3.
Uabxexpan(a,b,x). Implementation of the method given in Section 4.
For testing the computation of U(a,b,x) and \(U^{\prime }(a,b,x)\) using the different methods, we consider the recurrence relations
Also, for testing the method in Section 2, we consider the following alternative relation
When using this relation, values \(a \sim b\) should not be included to avoid the loss of significant digits by cancellation. We have randomly generated 106 values in the parameter region (a,b,x) ∈ (0,0.5) × (0,0.5) × (0,1) for testing (5.2) using Uabxsmall(a,b,x). The results obtained show that for more of the \(\sim 98\%\) of the points, the obtained accuracy was better than 10− 14. Also, for the same parameter region, this method is more than a 20% faster than the method implemented in Uabxrec(a,b,x).
In Figs. 1 and 2, we show the accuracy obtained when using the expansion (4.1) and (4.8) implemented in the MATLAB function Uabxexpan(a,b,x) to approximate the values of U(a,b,x) and \(U^{\prime }(a,b,x)\). We take n = 5 terms in both expansions. We check the recurrence relations (5.1) for few fixed values of x in the region (a,b) = (0,500) × (0,1000) with 20,000 random points. The red crosses indicate points where the error obtained when testing the recurrence relations (5.1) is greater than 10− 12. The blue points correspond to function values very close or under the underflow limit in double precision. The green points correspond to function values very close or above the overflow limit in double precision. As can be seen, the expansions are not accurate, in general for a small or when x is small, for all values of a when the b-values are not large. As we have shown, the function Uabxsmall(a,b,x) works very well (a,b,x) ∈ (0,0.5) × (0,0.5) × (0,1). For other small parameter values, the algorithm implemented in Uabxrec(a,b,x) can be used. For x small, we have made a slight modification in the original algorithm and we use a scaled version of the a-recursion in order to avoid the loss of significant digits for large values of a when computed in double-precision floating point arithmetics.
Taking into account the results obtained in the different tests of the methods, the resulting computational scheme is given in Algorithm 1. This algorithm is implemented in the MATLAB function Uabxcomp.Footnote 1 The front factors in the expansions (4.1) and (4.8) are used in the full algorithm as an estimation of the function value to avoid possible overflow/underflow problems.
For testing the accuracy of the full algorithm for computing U(a,b,x), we have considered 108 random values in the parameter region (a,b,x) ∈ (0,500) × (0,500) × (0,1000). Of all the randomly generated points, 2.64 × 107 were points not in the underflow or overflow regions. The results show that at approximately 54% of these points, the accuracy is better than 10− 14, while at around 43% of the points the accuracy is between 10− 14 and 10− 13. The maximum error obtained was \(\sim 10^{-11}\), at a point for which the function value was close to the underflow limit. See also Fig. 3. Similar results were obtained for the derivative.
As an additional test, we have compared our function Uabxcomp against the intrinsic MATLAB function to evaluate the Kummer U(a.b,x) function which is called kummerU. This function, included in the symbolic math toolbox, provides also floating-point results for numeric arguments. When checking the accuracy obtained in comparison to our function, the tests reveal that for some parameters, the computations obtained with kummerU are not accurate. For example, in Fig. 4, we show that the calculation of U(a,b,x) using kummerU in MATLAB R2022b gives a negative number for certain values of the parameters (U(a,b,x) is non-negative for x > 0,a ≥ 0,b ∈R). With respect to computational efficiency, the computations with kummerU take much more time than those obtained with our algorithm, but this is expected since kummerU is part of a symbolic package. As an example, the computation of 500 function values with random arguments in the parameter region (a,b,x) ∈ (0,500) × (0,500) × (0,1000) took 9.410− 2s using Uabxcomp and 199s using kummerU. The results have been obtained using MATLAB R2022b in a PC with 8 GB RAM and Intel Core i5-4310U processor.
Notes
This function is available at http://personales.unican.es/gila/KummerUeval.zip
References
Felsen, L.B., Marcuvitz, N.: Radiation and scattering of waves. Wiley-IEEE Press (1994)
Gasaneo, G., Ancarani, L.U.: Two-body Coulomb problems with sources. Phys. Rev. A 82, 042706 (2010)
Gil, A., Odrzywołek, A., Segura, J., Temme, N.M.: Evaluation of the generalized Fermi-Dirac integral and its derivatives for moderate/large values of the parameters. Comput. Phys. Commun. 238, 108563 (2023)
Gil, A., Segura, J., Temme, N.M.: Computing the Kummer function U(a,b,z) for small values of the arguments. Appl. Math. Comput. 271, 532–539 (2015)
Gil, A., Segura, J., Temme, N.M.: Complete asymptotic expansions for the relativistic Fermi-Dirac integral. Appl. Math. Comput. 412, 126618 (2022)
Johansson, F.: Computing hypergeometric functions rigorously. ACM Trans. Math. Softw. 45(3), Art. 30, 26 (2019)
Jones, E., Oliphant, T., Peterson, P.: SciPy: Open Source Scientific Tools for Python (2001)
Mathews, W.N. Jr, Esrick, M.A., Teoh, Z.Y., Freericks, J.K.: A physicist’s guide to the solution of Kummer’s equation and confluent hypergeometric functions. Condensed Matter Phys. 25, 33203:,1–23 (2022)
Muller, K.E.: Computing the confluent hypergeometric function, M(a,b,x). Numer. Math. 90(1), 179–196 (2001)
Nardin, M., Perger, W.F., Bhalla, A.: Algorithm 707: CONHYP: A numerical evaluator of the confluent hypergeometric function for complex arguments of large magnitudes. ACM Trans. Math. Soft. 18, 345–349 (1992)
Olde Daalhuis, A.B.: Chapter 13, Confluent hypergeometric functions. In: NIST Handbook of Mathematical Functions, pp 321–349. Cambridge University Press, Cambridge (2010a). http://dlmf.nist.gov/13
Schweizer, W.: Confluent hypergeometric function. In: Special Functions in Physics with MATLAB, pp 91–99. Springer International Publishing (2021)
Segura, J., Temme, N.M.: Numerically satisfactory solutions of Kummer recurrence relations. Numer. Math. 111, 109–119 (2008)
Temme, N.M.: The numerical computation of the confluent hypergeometric function U(a,b,z). Numer. Math. 41(1), 63–82 (1983)
Temme, N.M., Veling, E.J.M.: Asymptotic expansions of Kummer hypergeometric functions with three asymptotic parameters a, b and z. Indag. Math. 33(6), 121–1235 (2022)
Vandevender, W.H., Haskell, K.H.: The SLATEC mathematical subprogram library. ACM SIGNUM Newsl. 17, 16–21 (1982)
Acknowledgements
The authors thank the reviewer for useful comments and suggestions. NMT thanks CWI Amsterdam for scientific support.
Funding
Open Access funding provided thanks to the CRUE-CSIC agreement with Springer Nature. The authors acknowledge financial support from project PGC2018-098279-B-I00 funded by MCIN/ AEI /10.13039/501100011033/ FEDER “Una manera de hacer Europa” and PID2021-127252NB-I00 funded by MCIN/AEI/10.13039/501100011033/ FEDER, UE.
Author information
Authors and Affiliations
Contributions
The authors contributed equally to the paper.
Corresponding author
Ethics declarations
Competing interests
The authors declare no competing interests.
Additional information
Publisher’s note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Rights and permissions
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.
About this article
Cite this article
Gil, A., Ruiz-Antolín, D., Segura, J. et al. Computation of the confluent hypergeometric function U(a,b,x) and its derivative for positive arguments. Numer Algor 94, 669–679 (2023). https://doi.org/10.1007/s11075-023-01515-y
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11075-023-01515-y