static void qc25c (gsl_function * f, double a, double b, double c, double *result, double *abserr, int *err_reliable) { double cc = (2 * c - b - a) / (b - a); if (fabs (cc) > 1.1) { double resabs, resasc; gsl_function weighted_function; struct fn_cauchy_params fn_params; fn_params.function = f; fn_params.singularity = c; weighted_function.function = &fn_cauchy; weighted_function.params = &fn_params; gsl_integration_qk15 (&weighted_function, a, b, result, abserr, &resabs, &resasc); if (*abserr == resasc) { *err_reliable = 0; } else { *err_reliable = 1; } return; } else { double cheb12[13], cheb24[25], moment[25]; double res12 = 0, res24 = 0; size_t i; gsl_integration_qcheb (f, a, b, cheb12, cheb24); compute_moments (cc, moment); for (i = 0; i < 13; i++) { res12 += cheb12[i] * moment[i]; } for (i = 0; i < 25; i++) { res24 += cheb24[i] * moment[i]; } *result = res24; *abserr = fabs(res24 - res12) ; *err_reliable = 0; return; } }
static void qc25f (gsl_function * f, double a, double b, gsl_integration_qawo_table * wf, size_t level, double *result, double *abserr, double *resabs, double *resasc) { const double center = 0.5 * (a + b); const double half_length = 0.5 * (b - a); const double omega = wf->omega ; const double par = omega * half_length; if (fabs (par) < 2) { gsl_function weighted_function; struct fn_fourier_params fn_params; fn_params.function = f; fn_params.omega = omega; if (wf->sine == GSL_INTEG_SINE) { weighted_function.function = &fn_sin; } else { weighted_function.function = &fn_cos; } weighted_function.params = &fn_params; gsl_integration_qk15 (&weighted_function, a, b, result, abserr, resabs, resasc); return; } else { double *moment; double cheb12[13], cheb24[25]; double result_abs, res12_cos, res12_sin, res24_cos, res24_sin; double est_cos, est_sin; double c, s; size_t i; gsl_integration_qcheb (f, a, b, cheb12, cheb24); if (level >= wf->n) { /* table overflow should not happen, check before calling */ GSL_ERROR_VOID("table overflow in internal function", GSL_ESANITY); } /* obtain moments from the table */ moment = wf->chebmo + 25 * level; res12_cos = cheb12[12] * moment[12]; res12_sin = 0 ; for (i = 0; i < 6; i++) { size_t k = 10 - 2 * i; res12_cos += cheb12[k] * moment[k]; res12_sin += cheb12[k + 1] * moment[k + 1]; } res24_cos = cheb24[24] * moment[24]; res24_sin = 0 ; result_abs = fabs(cheb24[24]) ; for (i = 0; i < 12; i++) { size_t k = 22 - 2 * i; res24_cos += cheb24[k] * moment[k]; res24_sin += cheb24[k + 1] * moment[k + 1]; result_abs += fabs(cheb24[k]) + fabs(cheb24[k+1]); } est_cos = fabs(res24_cos - res12_cos); est_sin = fabs(res24_sin - res12_sin); c = half_length * cos(center * omega); s = half_length * sin(center * omega); if (wf->sine == GSL_INTEG_SINE) { *result = c * res24_sin + s * res24_cos; *abserr = fabs(c * est_sin) + fabs(s * est_cos); } else { *result = c * res24_cos - s * res24_sin; *abserr = fabs(c * est_cos) + fabs(s * est_sin); } *resabs = result_abs * half_length; *resasc = GSL_DBL_MAX; return; } }
static void qc25s (gsl_function * f, double a, double b, double a1, double b1, gsl_integration_qaws_table * t, double *result, double *abserr, int *err_reliable) { gsl_function weighted_function; struct fn_qaws_params fn_params; fn_params.function = f; fn_params.a = a; fn_params.b = b; fn_params.table = t; weighted_function.params = &fn_params; if (a1 == a && (t->alpha != 0.0 || t->mu != 0)) { double cheb12[13], cheb24[25]; double factor = pow(0.5 * (b1 - a1), t->alpha + 1.0); weighted_function.function = &fn_qaws_R; gsl_integration_qcheb (&weighted_function, a1, b1, cheb12, cheb24); if (t->mu == 0) { double res12 = 0, res24 = 0; double u = factor; compute_result (t->ri, cheb12, cheb24, &res12, &res24); *result = u * res24; *abserr = fabs(u * (res24 - res12)); } else { double res12a = 0, res24a = 0; double res12b = 0, res24b = 0; double u = factor * log(b1 - a1); double v = factor; compute_result (t->ri, cheb12, cheb24, &res12a, &res24a); compute_result (t->rg, cheb12, cheb24, &res12b, &res24b); *result = u * res24a + v * res24b; *abserr = fabs(u * (res24a - res12a)) + fabs(v * (res24b - res12b)); } *err_reliable = 0; return; } else if (b1 == b && (t->beta != 0.0 || t->nu != 0)) { double cheb12[13], cheb24[25]; double factor = pow(0.5 * (b1 - a1), t->beta + 1.0); weighted_function.function = &fn_qaws_L; gsl_integration_qcheb (&weighted_function, a1, b1, cheb12, cheb24); if (t->nu == 0) { double res12 = 0, res24 = 0; double u = factor; compute_result (t->rj, cheb12, cheb24, &res12, &res24); *result = u * res24; *abserr = fabs(u * (res24 - res12)); } else { double res12a = 0, res24a = 0; double res12b = 0, res24b = 0; double u = factor * log(b1 - a1); double v = factor; compute_result (t->rj, cheb12, cheb24, &res12a, &res24a); compute_result (t->rh, cheb12, cheb24, &res12b, &res24b); *result = u * res24a + v * res24b; *abserr = fabs(u * (res24a - res12a)) + fabs(v * (res24b - res12b)); } *err_reliable = 0; return; } else { double resabs, resasc; weighted_function.function = &fn_qaws; gsl_integration_qk15 (&weighted_function, a1, b1, result, abserr, &resabs, &resasc); if (*abserr == resasc) { *err_reliable = 0; } else { *err_reliable = 1; } return; } }