Hi, I was trying to use the hypergeometric function of the second kind from the GSL library, and I found that the current implementation has serious numerical errors.
The routines gsl_sf_hyperg_U_e and gsl_sf_hyperg_U_e10_e are not able to give correct answers when the argument a is chosen to be some numbers say {10, 11, 12, ..} in the short program. Instead, it outputs Inf’s in the short program below. I think this error is probably due to the numerical in-accuracy of the current implementation for the hypergeometric function of the second kind in the header file. I found that in MATLAB and Mathematica, I could get correct answers. I am wondering whether there is any way to fix this issue. * GSL version: 2.6 * Hardware and OS: Mac OS High Sierra * Compiler: g++ 5.1.0 * short program // g++ -Wall -o Ubug.o Ubug.cpp -I/usr/local/include -lgsl -lcblas #include<iostream> #include<iomanip> #include <gsl/gsl_sf_hyperg.h> #include <gsl/gsl_errno.h> using namespace std; double HypergeometricU(double a, double b, double x){ gsl_sf_result_e10 result; gsl_set_error_handler_off(); //gsl_sf_hyperg_U_e(a, b, x, &result); gsl_sf_hyperg_U_e10_e(a, b, x, &result); return result.val; } int main(){ double a1[9] = {8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0}; double a2[9] = {8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5}; double b=0.5, z=0.1; double out1[9]={9999.0}; double out2[9]={9999.0}; cout<<setw(25)<<"U[a1,b,z]"<<setw(35)<<"U[a2,b,z]"<<"\n"; for(int k=0; k<9; k++){ out1[k] = HypergeometricU(a1[k],b,z); out2[k] = HypergeometricU(a2[k],b,z); cout<<"a1="<<a1[k]<<setw(20)<<out1[k]<<setw(20)<<"a2="<<a2[k]<<setw(15)<<out2[k]<<"\n\n"; } return 0; } Thanks, Pulong ----------------------------------------------------------------- Pulong Ma Postdoctoral Fellow Statistical and Applied Mathematical Sciences Institute 4051 Research Commons, Suite 300 79 T.W. Alexander Drive, P.O. Box 110207 Durham, NC 27709 Email: pulong...@duke.edu<mailto:pulong...@duke.edu> Phone: (513) 652-2159 URL: https://pulongma.github.io