24 #include <gsl/gsl_math.h>
25 #include <gsl/gsl_complex.h>
26 #include <gsl/gsl_poly.h>
28 #define SWAP(a,b) do { double tmp = b ; b = a ; a = tmp ; } while(0)
32 gsl_complex *z0, gsl_complex *z1,
35 double q = (a * a - 3 * b);
36 double r = (2 * a * a * a - 9 * a * b + 27 *
c);
41 double Q3 = Q * Q *
Q;
49 GSL_REAL (*z0) = -a / 3;
51 GSL_REAL (*z1) = -a / 3;
53 GSL_REAL (*z2) = -a / 3;
66 double sqrtQ =
sqrt (Q);
70 GSL_REAL (*z0) = -2 * sqrtQ - a / 3;
72 GSL_REAL (*z1) = sqrtQ - a / 3;
74 GSL_REAL (*z2) = sqrtQ - a / 3;
79 GSL_REAL (*z0) = -sqrtQ - a / 3;
81 GSL_REAL (*z1) = -sqrtQ - a / 3;
83 GSL_REAL (*z2) = 2 * sqrtQ - a / 3;
90 double sqrtQ =
sqrt (Q);
91 double sqrtQ3 = sqrtQ * sqrtQ * sqrtQ;
92 double ctheta = R / sqrtQ3;
96 else if ( ctheta < 1.0)
97 theta =
acos (R / sqrtQ3);
99 double norm = -2 * sqrtQ;
100 double r0 = norm *
cos (theta / 3) - a / 3;
101 double r1 = norm *
cos ((theta + 2.0 *
M_PI) / 3) - a / 3;
102 double r2 = norm *
cos ((theta - 2.0 *
M_PI) / 3) - a / 3;
130 double sgnR = (R >= 0 ? 1 : -1);
131 double A = -sgnR *
pow (
fabs (R) +
sqrt (R2 - Q3), 1.0 / 3.0);
136 GSL_REAL (*z0) = A + B - a / 3;
139 GSL_REAL (*z1) = -0.5 * (A +
B) - a / 3;
140 GSL_IMAG (*z1) = -(
sqrt (3.0) / 2.0) *
fabs(A - B);
142 GSL_REAL (*z2) = -0.5 * (A +
B) - a / 3;
143 GSL_IMAG (*z2) = (
sqrt (3.0) / 2.0) *
fabs(A - B);
147 GSL_REAL (*z0) = -0.5 * (A +
B) - a / 3;
148 GSL_IMAG (*z0) = -(
sqrt (3.0) / 2.0) *
fabs(A - B);
150 GSL_REAL (*z1) = -0.5 * (A +
B) - a / 3;
151 GSL_IMAG (*z1) = (
sqrt (3.0) / 2.0) *
fabs(A - B);
153 GSL_REAL (*z2) = A + B - a / 3;
double pow(double, double)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
unsigned int r1[N_CITIES]
int gsl_poly_complex_solve_cubic(double a, double b, double c, gsl_complex *z0, gsl_complex *z1, gsl_complex *z2)
double norm(double *x, double *p)
unsigned int r2[N_CITIES]