25 mfunname(
"void Cubic::find_zero(...) const");
26 const Cubic& t = (*this);
38 double Q = (3.0 * a1 - a2 * a2) / 9.0;
39 double R = (9.0 * a2 * a1 - 27.0 * a0 - 2.0 * a2 * a2 * a2) / 54.0;
40 double D = Q * Q * Q + R * R;
48 }
else if (tt < 0.0) {
49 S = -
pow(-tt, 1 / 3.0);
56 }
else if (tt < 0.0) {
57 T = -
pow(-tt, 1 / 3.0);
62 S =
pow(R + iu * sD, 1 / 3.0);
63 T =
pow(R - iu * sD, 1 / 3.0);
65 z1 = -a2 / 3.0 + (S + T);
66 z2 = -a2 / 3.0 - (S + T) / 2.0 + 0.5 * iu * std::sqrt(3.0) * (S - T);
67 z3 = -a2 / 3.0 - (S + T) / 2.0 - 0.5 * iu * std::sqrt(3.0) * (S - T);
75 mfunname(
"int Cubic::find_real_zero(double z[3]) const");
80 double thresh = 10.0 * DBL_MIN;
82 if (
fabs(zc1.imag()) < thresh ||
83 (zc1.real() != 0.0 &&
fabs(zc1.imag() / zc1.real()) < thresh)) {
87 if (
fabs(zc2.imag()) < thresh ||
88 (zc2.real() != 0.0 &&
fabs(zc2.imag() / zc2.real()) < thresh)) {
92 if (
fabs(zc3.imag()) < thresh ||
93 (zc3.real() != 0.0 &&
fabs(zc3.imag() / zc3.real()) < thresh)) {
98 for (
int n1 = 0; n1 < q - 1; n1++) {
99 for (n2 = n1; n2 < q; n2++) {
107 for (
int n1 = 0; n1 < q - 1; n1++) {
109 if ((
fabs(z[n1]) < thresh &&
fabs(z[n2]) < thresh) ||
110 fabs((z[n1] - z[n1 + 1]) / (z[n1] + z[n1 + 1])) < thresh) {
111 for (n2 = n1 + 1; n2 < q - 1; n2++) {
123 "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++) file <<
' ' << r[n];
172 Ifile <<
"Max/Min, q=" << q <<
'\n';
174 for (n = 0; n < q; n++) {
175 Ifile <<
"n=" << n <<
" xmm[n]=" << std::setw(13) << xmm[n]
176 <<
" ymm[n]=" << std::setw(13) << ymm[n]
177 <<
" s_mm[n]=" << std::setw(13) << s_mm[n] <<
'\n';
#define check_econd11a(a, signb, add, stream)
Find solution to cubic equation.
void find_zero(double_complex &z1, double_complex &z2, double_complex &z3) const
std::complex< double > double_complex
int find_maxmin(double xmm[2], double ymm[2], int s_mm[2]) const
int find_real_zero(double z[3]) const
int find_zero(double xzero[2]) const
std::ostream & operator<<(std::ostream &file, const BGMesh &bgm)
DoubleAc pow(const DoubleAc &f, double p)
DoubleAc fabs(const DoubleAc &f)
DoubleAc sqrt(const DoubleAc &f)