Container to encapsulate various operations for quadratic equation of the forms with real coefficients: More...
Public Types | |
enum | components { A , B , C } |
Component labeling enumeration. More... | |
Public Types inherited from VectorSpace< quadraticEqn, scalar, 3 > | |
typedef VectorSpace< quadraticEqn, scalar, Ncmpts > | vsType |
VectorSpace type. More... | |
typedef scalar | cmptType |
Component type. More... | |
typedef scalar | magType |
Magnitude type. More... | |
typedef scalar * | iterator |
Random access iterator for traversing VectorSpace. More... | |
typedef const scalar * | const_iterator |
Random access iterator for traversing VectorSpace. More... | |
Public Member Functions | |
quadraticEqn () | |
Construct null. More... | |
quadraticEqn (const Foam::zero) | |
Construct initialized to zero. More... | |
quadraticEqn (const scalar a, const scalar b, const scalar c) | |
Construct from components. More... | |
scalar | a () const |
scalar | b () const |
scalar | c () const |
scalar & | a () |
scalar & | b () |
scalar & | c () |
scalar | value (const scalar x) const |
Evaluate the quadratic equation at x. More... | |
scalar | derivative (const scalar x) const |
Evaluate the derivative of the quadratic equation at x. More... | |
scalar | error (const scalar x) const |
Estimate the error of evaluation of the quadratic equation at x. More... | |
Roots< 2 > | roots () const |
Return the roots of the quadratic equation with no particular order. More... | |
Public Member Functions inherited from VectorSpace< quadraticEqn, scalar, 3 > | |
VectorSpace ()=default | |
Default construct. More... | |
VectorSpace (const Foam::zero) | |
Construct initialized to zero. More... | |
VectorSpace (const VectorSpace< quadraticEqn, scalar, Ncmpts > &vs) | |
Copy construct. More... | |
VectorSpace (const VectorSpace< Form2, Cmpt2, Ncmpts > &) | |
Copy construct of a VectorSpace with the same size. More... | |
VectorSpace (Istream &is) | |
Construct from Istream. More... | |
const scalar & | component (const direction) const |
scalar & | component (const direction) |
void | component (scalar &, const direction) const |
void | replace (const direction, const scalar &) |
const scalar * | cdata () const noexcept |
Return const pointer to the first data element. More... | |
scalar * | data () noexcept |
Return pointer to the first data element. More... | |
const ConstBlock< SubVector, BStart > | block () const |
const Foam::VectorSpace< quadraticEqn, scalar, Ncmpts >::template ConstBlock< SubVector, BStart > | block () const |
const scalar & | operator[] (const direction) const |
scalar & | operator[] (const direction) |
void | operator= (const VectorSpace< quadraticEqn, scalar, Ncmpts > &) |
void | operator= (const Foam::zero) |
void | operator+= (const VectorSpace< quadraticEqn, scalar, Ncmpts > &) |
void | operator-= (const VectorSpace< quadraticEqn, scalar, Ncmpts > &) |
void | operator*= (const scalar) |
void | operator/= (const scalar) |
iterator | begin () noexcept |
Return an iterator to begin of VectorSpace. More... | |
const_iterator | begin () const noexcept |
Return const_iterator to begin of VectorSpace. More... | |
iterator | end () noexcept |
Return an iterator to end of VectorSpace. More... | |
const_iterator | end () const noexcept |
Return const_iterator to end of VectorSpace. More... | |
const_iterator | cbegin () const noexcept |
Return const_iterator to begin of VectorSpace. More... | |
const_iterator | cend () const noexcept |
Return const_iterator to end of VectorSpace. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from VectorSpace< quadraticEqn, scalar, 3 > | |
static constexpr direction | size () noexcept |
The number of elements in the VectorSpace = Ncmpts. More... | |
static quadraticEqn | uniform (const scalar &s) |
Return a VectorSpace with all elements = s. More... | |
Public Attributes inherited from VectorSpace< quadraticEqn, scalar, 3 > | |
scalar | v_ [Ncmpts] |
The components of this vector space. More... | |
Static Public Attributes inherited from VectorSpace< quadraticEqn, scalar, 3 > | |
static constexpr direction | dim |
Dimensionality of space. More... | |
static constexpr direction | nComponents |
Number of components in this vector space. More... | |
static constexpr direction | mRows |
static constexpr direction | nCols |
static const char *const | typeName |
static const char *const | componentNames [] |
static const quadraticEqn | zero |
static const quadraticEqn | one |
static const quadraticEqn | max |
static const quadraticEqn | min |
static const quadraticEqn | rootMax |
static const quadraticEqn | rootMin |
Container to encapsulate various operations for quadratic equation of the forms with real coefficients:
\[ a*x^2 + b*x + c = 0 x^2 + B*x + C = 0 \]
The expressions for the roots of quadraticEqn
are as follows:
\[ x1 = - (b + sign(b) sqrt(b^2 - 4ac)/(2*a)) x2 = c/(a*x1) \]
where (b^2 - 4ac) is evaluated by fused multiply-adds to avoid detrimental cancellation.
Reference:
Cancellation-avoiding quadratic formula (tag:F): Ford, W. (2014). Numerical linear algebra with applications: Using MATLAB. London: Elsevier/Academic Press. DOI:10.1016/C2011-0-07533-6 Kahan's algo. to compute 'b^2-a*c' using fused multiply-adds (tag:JML): Jeannerod, C. P., Louvet, N., & Muller, J. M. (2013). Further analysis of Kahan's algorithm for the accurate computation of 2× 2 determinants. Mathematics of Computation, 82(284), 2245-2264. DOI:10.1090/S0025-5718-2013-02679-8
Definition at line 88 of file quadraticEqn.H.
enum components |
|
inline |
Construct null.
Definition at line 30 of file quadraticEqnI.H.
|
inline |
Construct initialized to zero.
Definition at line 34 of file quadraticEqnI.H.
|
inline |
|
inline |
Definition at line 55 of file quadraticEqnI.H.
References A.
Referenced by quadraticEqn::roots().
|
inline |
Definition at line 61 of file quadraticEqnI.H.
References B.
Referenced by quadraticEqn::roots().
|
inline |
Definition at line 67 of file quadraticEqnI.H.
Referenced by quadraticEqn::roots().
|
inline |
Definition at line 73 of file quadraticEqnI.H.
References A.
|
inline |
Definition at line 79 of file quadraticEqnI.H.
References B.
|
inline |
Definition at line 85 of file quadraticEqnI.H.
|
inline |
Evaluate the quadratic equation at x.
Definition at line 91 of file quadraticEqnI.H.
References b, quadraticEqn::value(), and x.
Referenced by quadraticEqn::value().
|
inline |
Evaluate the derivative of the quadratic equation at x.
Definition at line 97 of file quadraticEqnI.H.
|
inline |
Estimate the error of evaluation of the quadratic equation at x.
Definition at line 103 of file quadraticEqnI.H.
References b, Foam::mag(), and x.
Foam::Roots< 2 > roots | ( | ) | const |
Return the roots of the quadratic equation with no particular order.
if discriminant > 0: return two distinct real roots if discriminant < 0: return one of the complex conjugate-pair roots otherwise : return two identical real roots
Definition at line 34 of file quadraticEqn.C.
References quadraticEqn::a(), quadraticEqn::b(), quadraticEqn::c(), Foam::roots::complex, Foam::mag(), Foam::roots::nan, quadraticEqn::roots(), Foam::sign(), Foam::sqrt(), and x.
Referenced by quadraticEqn::roots().