Find solution to cubic equation.
More...
#include <cubic.h>
Find solution to cubic equation.
Definition at line 22 of file cubic.h.
◆ double_complex
◆ Cubic() [1/2]
Definition at line 47 of file cubic.h.
47: da(0.0), db(0.0), dc(0.0), dd(0.0), s_dxzero(0) {}
◆ Cubic() [2/2]
Heed::Cubic::Cubic |
( |
double |
fa, |
|
|
double |
fb, |
|
|
double |
fc, |
|
|
double |
fd |
|
) |
| |
|
inline |
Definition at line 48 of file cubic.h.
49 : da(fa), db(fb), dc(fc), dd(fd), s_dxzero(0) {}
◆ a()
double Heed::Cubic::a |
( |
| ) |
const |
|
inline |
◆ b()
double Heed::Cubic::b |
( |
| ) |
const |
|
inline |
◆ c()
double Heed::Cubic::c |
( |
| ) |
const |
|
inline |
◆ d()
double Heed::Cubic::d |
( |
| ) |
const |
|
inline |
◆ find_maxmin()
int Heed::Cubic::find_maxmin |
( |
double |
xmm[2], |
|
|
double |
ymm[2], |
|
|
int |
s_mm[2] |
|
) |
| const |
Definition at line 121 of file cubic.cpp.
121 {
123 "int Cubic::find_maxmin(double xmm[2], double ymm[2], int s_mm[2]) "
124 "const");
125 double ap = 3 * da;
126 double bp = 2 * db;
127 double cp = dc;
128 Parabola par(ap, bp, cp);
129 s_mm[0] = 0;
130 s_mm[1] = 0;
131 int qz = par.find_zero(xmm);
132 if (qz == 1) {
133 s_mm[0] = 0;
134 }
135 if (qz == 2) {
137 s_mm[0] = 1;
138 s_mm[1] = -1;
139 } else {
140 s_mm[0] = -1;
141 s_mm[1] = 1;
142 }
143 }
144 for (int n = 0; n < qz; ++n) {
146 }
147 return qz;
148}
Referenced by Heed::operator<<().
◆ find_real_zero()
int Heed::Cubic::find_real_zero |
( |
double |
z[3] | ) |
const |
Definition at line 74 of file cubic.cpp.
74 {
75 mfunname(
"int Cubic::find_real_zero(double z[3]) const");
80 double thresh = 10.0 * DBL_MIN;
81 int q = 0;
82 if (
fabs(zc1.imag()) < thresh ||
83 (zc1.real() != 0.0 &&
fabs(zc1.imag() / zc1.real()) < thresh)) {
85 q++;
86 }
87 if (
fabs(zc2.imag()) < thresh ||
88 (zc2.real() != 0.0 &&
fabs(zc2.imag() / zc2.real()) < thresh)) {
90 q++;
91 }
92 if (
fabs(zc3.imag()) < thresh ||
93 (zc3.real() != 0.0 &&
fabs(zc3.imag() / zc3.real()) < thresh)) {
95 q++;
96 }
97 int n2 = 0;
98 for (int n1 = 0; n1 < q - 1; n1++) {
99 for (n2 = n1; n2 < q; n2++) {
100 if (z[n1] > z[n2]) {
104 }
105 }
106 }
107 for (int n1 = 0; n1 < q - 1; n1++) {
108
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++) {
113 }
114 q--;
115 n1--;
116 }
117 }
118 return q;
119}
void find_zero(double_complex &z1, double_complex &z2, double_complex &z3) const
std::complex< double > double_complex
DoubleAc fabs(const DoubleAc &f)
Referenced by Heed::operator<<(), and Heed::VanDerWaals::volume_of_mole().
◆ find_zero()
Definition at line 23 of file cubic.cpp.
24 {
25 mfunname(
"void Cubic::find_zero(...) const");
26 const Cubic& t = (*this);
27 if (s_dxzero != 0) {
28 z1 = dz1;
29 z2 = dz2;
30 z3 = dz3;
31 return;
32 }
33
35 double a2 = db / da;
36 double a1 = dc / da;
37 double a0 = dd / da;
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;
44 if (D >= 0.0) {
45 double tt = R + sD;
46 if (tt > 0.0) {
48 } else if (tt < 0.0) {
49 S = -
pow(-tt, 1 / 3.0);
50 } else {
51 S = 0.0;
52 }
53 tt = R - sD;
54 if (tt > 0.0) {
56 } else if (tt < 0.0) {
57 T = -
pow(-tt, 1 / 3.0);
58 } else {
59 T = 0.0;
60 }
61 } else {
62 S =
pow(R + iu * sD, 1 / 3.0);
63 T =
pow(R - iu * sD, 1 / 3.0);
64 }
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);
68 t.dz1 = z1;
69 t.dz2 = z2;
70 t.dz3 = z3;
71 t.s_dxzero = 3;
72}
#define check_econd11a(a, signb, add, stream)
DoubleAc pow(const DoubleAc &f, double p)
DoubleAc sqrt(const DoubleAc &f)
Referenced by find_real_zero(), and Heed::operator<<().
◆ put_a()
void Heed::Cubic::put_a |
( |
double |
fa | ) |
|
|
inline |
Definition at line 30 of file cubic.h.
30 {
31 da = fa;
32 s_dxzero = 0;
33 }
◆ put_b()
void Heed::Cubic::put_b |
( |
double |
fb | ) |
|
|
inline |
Definition at line 34 of file cubic.h.
34 {
35 db = fb;
36 s_dxzero = 0;
37 }
◆ put_c()
void Heed::Cubic::put_c |
( |
double |
fc | ) |
|
|
inline |
Definition at line 38 of file cubic.h.
38 {
39 dc = fc;
40 s_dxzero = 0;
41 }
◆ put_d()
void Heed::Cubic::put_d |
( |
double |
fd | ) |
|
|
inline |
Definition at line 42 of file cubic.h.
42 {
43 dd = fd;
44 s_dxzero = 0;
45 }
◆ s_xzero()
double Heed::Cubic::s_xzero |
( |
| ) |
const |
|
inline |
◆ y()
double Heed::Cubic::y |
( |
double |
x | ) |
const |
|
inline |
The documentation for this class was generated from the following files: