28 #include <gsl/gsl_integration.h>
29 #include <gsl/gsl_complex.h>
30 #include <gsl/gsl_complex_math.h>
31 #include <gsl/gsl_sf_pow_int.h>
32 #include <gsl/gsl_math.h>
33 #include <gsl/gsl_errno.h>
34 #include <gsl/gsl_sf_gamma.h>
48 double my_f (
double x,
void *p) {
50 gsl_complex z = gsl_complex_add(gsl_complex_rect(params->
a, 0),
51 gsl_complex_polar(params->
r, x));
52 gsl_complex z1 = gsl_complex_div(gsl_complex_add(z,
53 gsl_complex_rect(params->
s0, 0)),
55 gsl_complex z2 = gsl_complex_div(gsl_complex_sub(z,
56 gsl_complex_rect(params->
s0, 0)),
58 gsl_complex func = gsl_complex_div(gsl_complex_sub(gsl_complex_tanh(z1),
59 gsl_complex_tanh(z2)),
60 gsl_complex_rect(2, 0));
61 func = gsl_complex_mul(func, gsl_complex_polar(1, -params->
n * x));
62 return gsl_sf_fact(params->
n) * GSL_REAL(func)
63 / (2 * M_PI * gsl_sf_pow_int(params->
r, params->
n));
68 const double &lambdaleft,
69 const double &lambdaright,
72 double radius = gsl_hypot(
a - 2, lambdaright * M_PI / 2) - 0.01;
73 double radius2 = gsl_hypot(
a + 2, lambdaleft * M_PI / 2) - 0.01;
74 if (radius > radius2) radius = radius2;
75 struct my_f_params params = {
a, s0, lambdaleft, lambdaright, radius,
n};
78 gsl_integration_workspace *w = gsl_integration_workspace_alloc(100);
79 double error = gsl_sf_pow_int(10, -12);
80 double *result =
new double;
81 double *abserr =
new double;
82 gsl_set_error_handler_off();
83 int status = gsl_integration_qag(&F, 0, 2 * M_PI, 0, error,
84 100, 6, w, result, abserr);
85 gsl_integration_workspace_free(w);
86 double finalResult = *result;
92 else return finalResult;
double my_f(double x, void *p)
double integrate(const double &a, const double &s0, const double &lambdaleft, const double &lambdaright, const int &n)