Class cubic_real_coeff_cern (o2scl)

O2scl : Class List

template<class fp_t = double, class cx_t = std::complex<fp_t>>
class cubic_real_coeff_cern : public o2scl::cubic_real_coeff<double, std::complex<double>>

Solve a cubic with real coefficients and complex roots (CERNLIB)

Note

The function rrteq3() is based on the CERNLIB routine of the same name, but differs slightly. See the documentation of that function for details.

Public Functions

inline cubic_real_coeff_cern()
inline virtual ~cubic_real_coeff_cern()
inline virtual int solve_rc(const fp_t a3, const fp_t b3, const fp_t c3, const fp_t d3, fp_t &r1, cx_t &r2, cx_t &r3)

Solves the polynomial \( a_3 x^3 + b_3 x^2 + c_3 x + d_3= 0 \) giving the real solution \( x=x_1 \) and two complex solutions \( x=x_2 \) , and \( x=x_3 \) .

inline fp_t sign(fp_t a, fp_t b)
inline virtual int rrteq3(fp_t r, fp_t s, fp_t t, fp_t x[], fp_t &d)

The CERNLIB-like interface.

This function computes the roots of the cubic equation

\[ x^3 + r x^2 + s x + t =0 \]
returning the value of the discriminant in d and the roots in the array x. If the discriminant is negative, then all three real roots are stored in x. Otherwise, the real root is stored in x[0] and the real and imaginary parts of the complex conjugate roots are stored in x[1] and x[2], respectively. This differs from the CERNLIB routine where the results were stored in x[1], x[2], and x[3] instead.

Another small change is that the discriminant for the resolvent cubic is evaluated slightly differently in order to improve the properties in the case where the roots are not all of order unity. The default CERNLIB behavior can be restored by setting improve_scale to false.

inline const char *type()

Return a string denoting the type (“cubic_real_coeff_cern”)

Public Members

fp_t eps

Numerical tolerance (default \( 10^{-6} \))

fp_t delta

Numerical tolerance (default \( 10^{-15} \))

bool improve_scale

Improve algorithm for poorly-scaled roots (default true)