56 double Q = (
SQR( a ) - 3. * b )/9. , R = ( 2. *
CUB( a ) - 9. * a * b + 27. * c )/54., Theta = 0.;
59 Theta = acos( R/ sqrt(
CUB( Q ) ) );
60 roots[0].real(-2. * sqrt( Q ) * cos( Theta/3. ) - a/3.);
61 roots[1].real(-2. * sqrt( Q ) * cos( ( Theta + 2 *
PI )/3. ) - a/3.);
62 roots[2].real(-2. * sqrt( Q ) * cos( ( Theta - 2 *
PI )/3. ) - a/3.);
69 double A = -
sgn( R ) * pow( (
ABS( R ) + sqrt(
SQR( R ) -
CUB( Q ) ) ), 1./3. ), B = ( A == 0 )? 0 : Q/A;
71 roots[0].real(( A + B ) - a/3.); roots[0].imag(0.);
73 roots[1].real(-.5 * ( A + B ) - a/3.); roots[2].real(-.5 * ( A + B ) - a/3.);
74 roots[1].imag(sqrt( 3.)/2. * ( A - B ));
75 roots[2].imag(-sqrt( 3.)/2. * ( A - B ));
88 std::complex<double> c, std::complex<double>* roots )
90 std::complex<double> Q = (
SQR( a ) - 3. * b )/9. , R = ( 2. *
CUB( a ) - 9. * a * b + 27. * c )/54.;
93 roots[0] = roots[1] = roots[2] = (0. , 0.);
98 (
SQR( real( R ) ) <
CUB( real( Q ) ) ) )
100 double Theta = acos( real( R )/ sqrt(
CUB( real( Q ) ) ) ),
101 aux_mlt1 = -2. * sqrt( real( Q ) );
102 std::complex<double> aux_mlt2 = (real( a )/3. , 0.);
104 roots[0] = aux_mlt1 * cos( Theta/3. ) - aux_mlt2;
105 roots[1] = aux_mlt1 * cos( ( Theta + 2 *
PI )/3. ) - aux_mlt2;
106 roots[2] = aux_mlt1 * cos( ( Theta - 2 *
PI )/3. ) - aux_mlt2;
109 std::complex<double> aux_mlt1 = sqrt(
SQR( R ) -
CUB( Q ) );
110 int signum = ( real( aux_mlt1 ) < 0. )? -1 : 1;
111 std::complex<double> A = -1. * pow( ( R + (
double)signum * aux_mlt1 ), 1./3. ),
114 AplusB = A + B, AminusB = A - B, a_div_3 = a/3.,
118 roots[0] = AplusB - a_div_3;
119 roots[1] = roots[2] = -.5 * AplusB - a/3.;
120 roots[1] += auxConjPart;
121 roots[2] -= auxConjPart;
136 if( x == NULL )
_errorr(
"Field for point positions must be allocated" );
137 if( w == NULL )
_errorr(
"Field for weights must be allocated" );
141 double p1, p2, p3, pp, xl, xm, z, z1;
148 xm = 0.5 * (maxLim + minLim);
149 xl = 0.5 * (maxLim - minLim);
151 nn = (double)nPoints;
152 for(i = 0; i < m; i++)
154 z = cos(
PI * ((
double)i + 0.75) / ((
double)nPoints + 0.5));
158 for(j = 0; j < nPoints; j++)
163 p1 = ((2.*jj + 1.)*z*p2 - jj*p3) / (jj + 1.);
165 pp = nn * (z*p1 - p2) / (z*z - 1.);
168 }
while( fabs(z - z1) >= 1.
e-12);
171 x[nPoints-1-i] = xm + xl * z;
172 w[i] = 2. * xl / ((1. - z*z) * pp*pp);
173 w[nPoints-1-i] = w[i];
182 if( x == NULL )
_errorr(
"Field for point positions must be allocated" );
183 if( w == NULL )
_errorr(
"Field for weights must be allocated" );
186 double p1, p2, p3, pp, z, z1;
189 PIM4 = pow(
PI, -0.25);
193 nn = (double)nPoints;
194 for( i = 1; i <= m; i++ )
197 z = sqrt(2.*nn + 1.) - 1.85575 * pow(2.*nn + 1., -0.16667);
200 z -= 1.14*pow(nn, 0.426) / z;
203 z = 1.86*z - 0.86 * x[1];
206 z = 1.91*z - 0.91 * x[2];
216 for( j = 1; j <= nPoints; j++ )
221 p1 = z*sqrt(2./jj)*p2 - sqrt((jj-1.)/jj)*p3;
223 pp = sqrt(2.*nn) * p2;
226 }
while (fabs(z-z1) >= 1.
e-12);
230 w[i-1] = 2.0 / (pp * pp);
231 w[nPoints-i] = w[i-1];
double sgn(double i)
Returns the signum of given value (if value is < 0 returns -1, otherwise returns 1) ...
Class polynomialRootSolution collects functions calculating the roots of polynomial functions...
std::complex< double > * GetCubicPolyRoots(double a, double b, double c, std::complex< double > *roots)
Function gives the analitical solution of cubic furmula of the real coefficients a, b, c x^3 + ax^2 + bx + c = 0.
The header file of usefull macros.
Collection of the functions of basic manipulations, some of them can be used instead of their counter...
static void GauLegF(double *x, double *w, const int nPoints, const double minLim, const double maxLim)
void CleanVector(double *a, long n)
Functin cleans a 'double' vector, initialize each value being 0-zero.
static void GauHerQ(double *x, double *w, const int nPoints)