Loading...
Searching...
No Matches
quadraticEqn Class Reference

Container to encapsulate various operations for quadratic equation of the forms with real coefficients: More...

#include <quadraticEqn.H>

Inheritance diagram for quadraticEqn:
Collaboration diagram for quadraticEqn:

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.
typedef scalar cmptType
 Component type.
typedef scalar magType
 Magnitude type.
typedef direction size_type
 The type to represent the size of a VectorSpace.
typedef scalar * iterator
 Random access iterator for traversing VectorSpace.
typedef const scalar * const_iterator
 Random access iterator for traversing VectorSpace.

Public Member Functions

 quadraticEqn ()=default
 Default construct.
 quadraticEqn (const Foam::zero)
 Construct initialized to zero.
 quadraticEqn (const scalar a, const scalar b, const scalar c)
 Construct from components.
scalar a () const noexcept
scalar b () const noexcept
scalar c () const noexcept
scalar & a () noexcept
scalar & b () noexcept
scalar & c () noexcept
scalar value (const scalar x) const
 Evaluate the quadratic equation at x.
scalar derivative (const scalar x) const
 Evaluate the derivative of the quadratic equation at x.
scalar error (const scalar x) const
 Estimate the error of evaluation of the quadratic equation at x.
Roots< 2 > roots () const
 Return the roots of the quadratic equation with no particular order.
Public Member Functions inherited from VectorSpace< quadraticEqn, scalar, 3 >
const Foam::VectorSpace< quadraticEqn, scalar, Ncmpts >::template ConstBlock< SubVector, BStart > block () const
 VectorSpace ()=default
 Default construct.
const scalar & component (const direction) const
void replace (const direction, const scalar &)
const scalar * cdata () const noexcept
 Return const pointer to the first data element.
scalar * data () noexcept
 Return pointer to the first data element.
void fill (const scalar &s)
 Assign all components to given value.
const scalar & operator[] (const direction) const
void operator= (const VectorSpace< quadraticEqn, scalar, Ncmpts > &)
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 (pointer) to begin of VectorSpace.
const_iterator cbegin () const noexcept
 Return const_iterator (const pointer) to begin of VectorSpace.
iterator end () noexcept
 Return an iterator (pointer) to end of VectorSpace.
const_iterator cend () const noexcept
 Return const_iterator (const pointer) to end of VectorSpace.

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.
static quadraticEqn uniform (const scalar &s)
 Return a VectorSpace with all elements = s.
Public Attributes inherited from VectorSpace< quadraticEqn, scalar, 3 >
scalar v_ [Ncmpts]
 The components of this vector space.
Static Public Attributes inherited from VectorSpace< quadraticEqn, scalar, 3 >
static constexpr direction dim
 Dimensionality of space.
static constexpr direction nComponents
 Number of components in this vector space.
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

Detailed Description

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
See also
Test-quadraticEqn.C
Source files

Definition at line 84 of file quadraticEqn.H.

Member Enumeration Documentation

◆ components

enum components

Component labeling enumeration.

Enumerator

Definition at line 93 of file quadraticEqn.H.

Constructor & Destructor Documentation

◆ quadraticEqn() [1/3]

quadraticEqn ( )
default

Default construct.

References a(), b(), and c().

Referenced by quadraticEqn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ quadraticEqn() [2/3]

quadraticEqn ( const Foam::zero )
inline

Construct initialized to zero.

Definition at line 23 of file quadraticEqnI.H.

References quadraticEqn(), VectorSpace< quadraticEqn, scalar, 3 >::VectorSpace(), and VectorSpace< quadraticEqn, scalar, 3 >::zero.

Here is the call graph for this function:

◆ quadraticEqn() [3/3]

quadraticEqn ( const scalar a,
const scalar b,
const scalar c )
inline

Construct from components.

Definition at line 29 of file quadraticEqnI.H.

References A, a(), B, b(), C, c(), and VectorSpace< quadraticEqn, scalar, 3 >::v_.

Here is the call graph for this function:

Member Function Documentation

◆ a() [1/2]

scalar a ( ) const
inlinenoexcept

Definition at line 118 of file quadraticEqn.H.

References A, Foam::noexcept, and VectorSpace< quadraticEqn, scalar, 3 >::v_.

Referenced by derivative(), error(), quadraticEqn(), quadraticEqn(), roots(), and value().

Here is the caller graph for this function:

◆ b() [1/2]

scalar b ( ) const
inlinenoexcept

Definition at line 119 of file quadraticEqn.H.

References B, Foam::noexcept, and VectorSpace< quadraticEqn, scalar, 3 >::v_.

Referenced by quadraticEqn(), quadraticEqn(), and roots().

Here is the caller graph for this function:

◆ c() [1/2]

scalar c ( ) const
inlinenoexcept

Definition at line 120 of file quadraticEqn.H.

References C, Foam::noexcept, and VectorSpace< quadraticEqn, scalar, 3 >::v_.

Referenced by error(), quadraticEqn(), quadraticEqn(), roots(), and value().

Here is the caller graph for this function:

◆ a() [2/2]

scalar & a ( )
inlinenoexcept

Definition at line 122 of file quadraticEqn.H.

References A, Foam::noexcept, and VectorSpace< quadraticEqn, scalar, 3 >::v_.

◆ b() [2/2]

scalar & b ( )
inlinenoexcept

Definition at line 123 of file quadraticEqn.H.

References B, Foam::noexcept, and VectorSpace< quadraticEqn, scalar, 3 >::v_.

◆ c() [2/2]

scalar & c ( )
inlinenoexcept

Definition at line 124 of file quadraticEqn.H.

References C, Foam::noexcept, and VectorSpace< quadraticEqn, scalar, 3 >::v_.

◆ value()

Foam::scalar value ( const scalar x) const
inline

Evaluate the quadratic equation at x.

Definition at line 44 of file quadraticEqnI.H.

References a(), b, c(), and x.

Here is the call graph for this function:

◆ derivative()

Foam::scalar derivative ( const scalar x) const
inline

Evaluate the derivative of the quadratic equation at x.

Definition at line 50 of file quadraticEqnI.H.

References a(), b, and x.

Here is the call graph for this function:

◆ error()

Foam::scalar error ( const scalar x) const
inline

Estimate the error of evaluation of the quadratic equation at x.

Definition at line 56 of file quadraticEqnI.H.

References a(), b, c(), Foam::mag(), and x.

Here is the call graph for this function:

◆ roots()

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 27 of file quadraticEqn.C.

References a(), b(), c(), Foam::roots::complex, Foam::mag(), Foam::roots::nan, roots(), Foam::sign(), Foam::sqrt(), and x.

Referenced by roots().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: