15static int lmmc_quad_tanh_sinh_arguments(
18 if (!isfinite(a) || !isfinite(b) || a >= b) {
21 if (!isfinite(abs_tol)) {
24 if (abs_tol < 1e-15 || abs_tol > 1e-1) {
27 return max_nodes >= 1 && max_nodes <= 1000000;
34 return pi_half * cosh(t) * 4.0 * exp(-2.0 * u);
37 return pi_half * cosh(t) / (cosh_u * cosh_u);
44 const lmmc_real_t tanh_u = u > 6.0 ? 1.0 - 2.0 * exp(-2.0 * u) : tanh(u);
47 const size_t needed = (size_t)(xp != state->
b) + (size_t)(xn != state->
a);
61 if (!isfinite(fp) || !isfinite(fn)) {
80 if (!isfinite(fmid) || !isfinite(sum)) {
83 for (
size_t j = 1; ; ++j) {
88 weight = lmmc_quad_tanh_sinh_weight(t, u);
89 if (!isfinite(weight)) {
92 if (weight < 1e-50)
break;
93 const lmmc_status_t status = lmmc_quad_tanh_sinh_pair(state, u, weight, &sum);
98 *integral = completed;
106 int have_complete = 0;
110 for (
size_t level = 0; level < 10; ++level) {
112 const lmmc_status_t status = lmmc_quad_tanh_sinh_level(state, h, &integral);
115 out->
value = last_complete;
116 out->
error = INFINITY;
120 last_error = lmmc_abs(integral - last_complete);
121 if (!isfinite(last_error)) {
122 out->
error = INFINITY;
126 last_complete = integral;
127 out->
value = last_complete;
128 out->
error = last_error;
129 if (have_complete && last_error <= abs_tol)
return LMMC_STATUS_OK;
141 if (f == NULL || out == NULL) {
145 out->
error = INFINITY;
147 if (!lmmc_quad_tanh_sinh_arguments(a, b, abs_tol, max_nodes)) {
159 return lmmc_quad_tanh_sinh_integrate(&state, abs_tol, out);
double lmmc_real_t
Public and internal LMMC real type.
#define LMMC_CONST_PI
圆周率常数 。
lmmc_real_t(*) lmmc_quad_func_t(lmmc_real_t x, void *user_data)
被积函数签名 。
lmmc_status_t lmmc_quad_tanh_sinh(lmmc_quad_func_t f, void *ud, lmmc_real_t a, lmmc_real_t b, lmmc_real_t abs_tol, size_t max_nodes, lmmc_quad_result_t *out)
Tanh-Sinh(双指数)积分,适用于端点奇异性。
void lmmc_quad_center_half_length(lmmc_real_t a, lmmc_real_t b, lmmc_real_t *center, lmmc_real_t *half_length)
双指数映射:x(t) = center + half_length*tanh(pi/2*sinh(t))。
lmmc_status_t
LMMC 库统一返回的状态码.
@ LMMC_STATUS_CONVERGENCE_FAILED
@ LMMC_STATUS_NUMERICAL_FAILURE
@ LMMC_STATUS_INVALID_ARGUMENT