Debian Codegraph @

cvd_src/quartic.h

raw symbols SCIP
1 #ifndef QUARTIC_H
2 #define QUARTIC_H
3
4 namespace CVD
5 {
6
7 /// A function to evaluate x^4 + Bx^3 + Cx^2 + Dx + E
8 inline double eval_quartic(double B, double C, double D, double E, double x)
9 {
10 return E + x * (D + x * (C + x * (B + x)));
11 }
12
13 /// A function that performs one iteration of Newton's method on the quartic x^4 + Bx^3 + Cx^2 + Dx + E
14 inline double newton_quartic(double B, double C, double D, double E, double x)
15 {
16 double fx = E + x * (D + x * (C + x * (B + x)));
17 double dx = D + x * (2 * C + x * (3 * B + x * 4));
18 return x - fx / dx;
19 }
20
21 /// A function to find the real roots of a quartic polynomial x^4 + Bx^3 + Cx^2 + Dx + E.
22 /// It efficiently implements the quartic formula as given by Cardano, Harriot, et al.
23 /// The precision of the resulting roots depends on the nature of the coefficients.
24 /// Sufficient precision can be ensured by refining the resulting roots using Newton's method.
25 /// @param[in] B the coefficient of the cubic term
26 /// @param[in] C the coefficient of the quadratic term
27 /// @param[in] D the coefficient of the linear term
28 /// @param[in] E the coefficient of the constant term
29 /// @param[out] r an array in which 0, 2, or 4 real roots will be stored
30 /// @return the number of real roots
31 /// @ingroup helpersgroup
32 int find_quartic_real_roots(double B, double C, double D, double E, double r[]);
33
34 }
35
36 #endif