27 mfunname(
"void Cubic::find_zero(double_complex &z1, double_complex &z2, "
28 "double_complex &z3) const");
35 double Q = (3.0 * a1 - a2 * a2) / 9.0;
36 double R = (9.0 * a2 * a1 - 27.0 * a0 - 2.0 * a2 * a2 * a2) / 54.0;
37 double D = Q * Q * Q + R * R;
46 S = -
pow(-t, 1 / 3.0);
54 T = -
pow(-t, 1 / 3.0);
59 S =
pow(R + iu * sD, 1 / 3.0);
60 T =
pow(R - iu * sD, 1 / 3.0);
62 z1 = -a2 / 3.0 + (S + T);
63 z2 = -a2 / 3.0 - (S + T) / 2.0 + 0.5 * iu *
sqrt(3.0) * (S - T);
64 z3 = -a2 / 3.0 - (S + T) / 2.0 - 0.5 * iu *
sqrt(3.0) * (S - T);
77 mfunname(
"int Cubic::find_real_zero(double z[3]) const");
82 double thresh = 10.0 * DBL_MIN;
84 if (
fabs(zc1.imag()) < thresh ||
85 (zc1.real() != 0.0 &&
fabs(zc1.imag() / zc1.real()) < thresh)) {
89 if (
fabs(zc2.imag()) < thresh ||
90 (zc2.real() != 0.0 &&
fabs(zc2.imag() / zc2.real()) < thresh)) {
94 if (
fabs(zc3.imag()) < thresh ||
95 (zc3.real() != 0.0 &&
fabs(zc3.imag() / zc3.real()) < thresh)) {
100 for (n1 = 0; n1 < q - 1; n1++) {
101 for (n2 = n1; n2 < q; n2++) {
109 for (n1 = 0; n1 < q - 1; n1++) {
110 if ((
fabs(z[n1]) < thresh &&
fabs(z[n2]) < thresh) ||
111 fabs((z[n1] - z[n1 + 1]) / (z[n1] + z[n1 + 1])) < thresh) {
112 for (n2 = n1 + 1; n2 < q - 1; n2++) {
123 mfunname(
"int Cubic::find_maxmin(double xmm[2], double ymm[2], int s_mm[2]) "
144 for (
int n = 0; n < qz; ++n) {
157 Ifile <<
"Cubic: a=" << f.
a() <<
" b=" << f.
b() <<
" c=" << f.
c()
158 <<
" d=" << f.
d() <<
'\n';
159 file <<
" z1,2,3=" << z1 <<
' ' << z2 <<
' ' << z3 <<
'\n';
163 Ifile <<
"The number of real zeros =" << q <<
'\n';
165 Ifile <<
"Solutions=";
166 for (n = 0; n < q; n++)
173 Ifile <<
"Max/Min, q=" << q <<
'\n';
175 for (n = 0; n < q; n++) {
176 Ifile <<
"n=" << n <<
" xmm[n]=" << std::setw(13) << xmm[n]
177 <<
" ymm[n]=" << std::setw(13) << ymm[n]
178 <<
" s_mm[n]=" << std::setw(13) << s_mm[n] <<
'\n';
DoubleAc pow(const DoubleAc &f, double p)
DoubleAc sqrt(const DoubleAc &f)
DoubleAc fabs(const DoubleAc &f)
#define check_econd11a(a, signb, add, stream)
double s_xzero(void) const
int find_maxmin(double xmm[2], double ymm[2], int s_mm[2]) const
int find_real_zero(double z[3]) const
void find_zero(double_complex &z1, double_complex &z2, double_complex &z3) const
std::complex< double > double_complex
int find_zero(double xzero[2]) const
std::ostream & operator<<(std::ostream &file, const Cubic &f)