Quartic roots
Utilities for C++ programming
Loading...
Searching...
No Matches
PolynomialRoots::Quadratic Class Reference

#include <PolynomialRoots.hh>

Public Member Functions

 Quadratic ()
 
 Quadratic (real_type a, real_type b, real_type c)
 
void setup (real_type a, real_type b, real_type c)
 
integer num_roots () const
 
integer numRoots () const
 alias of num_roots
 
bool complex_root () const
 
bool complexRoot () const
 alias of complex_root
 
bool double_root () const
 
bool doubleRoot () const
 alias of double_root
 
integer get_real_roots (real_type r[]) const
 
integer getRealRoots (real_type r[]) const
 alias of get_real_roots
 
integer get_positive_roots (real_type r[]) const
 
integer getPositiveRoots (real_type r[]) const
 alias of get_positive_roots
 
integer get_negative_roots (real_type r[]) const
 
integer getNegativeRoots (real_type r[]) const
 alias of get_negative_roots
 
integer get_roots_in_range (real_type a, real_type b, real_type r[]) const
 
integer getRootsInRange (real_type a, real_type b, real_type r[]) const
 alias of get_roots_in_range
 
integer get_roots_in_open_range (real_type a, real_type b, real_type r[]) const
 
integer getRootsInOpenRange (real_type a, real_type b, real_type r[]) const
 alias of get_roots_in_open_range
 
real_type real_root0 () const
 
real_type real_root1 () const
 
complex_type root0 () const
 
complex_type root1 () const
 
void get_root0 (real_type &re, real_type &im) const
 
void getRoot0 (real_type &re, real_type &im) const
 alias of get_root0
 
void get_root0 (complex_type &r) const
 
void getRoot0 (complex_type &r) const
 alias of get_root0
 
void get_root1 (real_type &re, real_type &im) const
 
void getRoot1 (real_type &re, real_type &im) const
 alias of get_root1
 
void get_root1 (complex_type &r) const
 
void getRoot1 (complex_type &r) const
 alias of get_root1
 
real_type eval (real_type x) const
 
complex_type eval (complex_type x) const
 
void eval (real_type x, real_type &p, real_type &dp) const
 
void info (ostream_type &s) const
 
bool check (ostream_type &s) const
 

Detailed Description

Quadratic polynomial class

Constructor

double a = 1;
double b = 2;
double c = 3;
Quadratic q(a,b,c); // build an solve `a x^2 + b x + c = 0`
q.setup(a,b,c); // build an solve `a x^2 + b x + c = 0`
Quadratic()
Definition PolynomialRoots.hh:206
void setup(real_type a, real_type b, real_type c)
Definition PolynomialRoots.hh:240

Get kind of solution

int nroots = q.num_roots();
bool has_complex_root = q.complex_root();
bool has_a_double_root = q.double_root();
integer num_roots() const
Definition PolynomialRoots.hh:258
bool double_root() const
Definition PolynomialRoots.hh:274
bool complex_root() const
Definition PolynomialRoots.hh:266

Get real roots

double r_min = 0;
double r_max = 2;
double r[2];
int nroots;
nroots = p.getRealRoots( r );
nroots = p.getPositiveRoots( r );
nroots = p.getNegativeRoots( r );
nroots = p.getRootsInRange( r_min, r_max, r );
nroots = p.getRootsInOpenRange( r_min, r_max, r );

Get roots

double r0 = p.real_root0();
double r1 = p.real_root1();
complex_type r0 = p.root0();
complex_type r1 = p.root1();
double re, im;
p.getRoot0( re, im );
p.getRoot0( r );
p.getRoot1( re, im );
p.getRoot1( r );
std::complex< real_type > complex_type
complex type numbers
Definition PolynomialRoots-Utils.hh:50

Evaluate polynomial

{double or complex} v, x;
v = p.eval( x );
p.eval( x, p, dp );

Information

p.info( cout );
bool ok = p.check( cout );

Constructor & Destructor Documentation

◆ Quadratic() [1/2]

PolynomialRoots::Quadratic::Quadratic ( )
inline

◆ Quadratic() [2/2]

PolynomialRoots::Quadratic::Quadratic ( real_type a,
real_type b,
real_type c )
inline

Build the object that store the roots of the quadratic polynomial

\[ q(x) = a x^2 + b x + c \]

Parameters
[in]aleading coefficient of \( q(x) \)
[in]bcoefficient of \( x \)
[in]ccoefficient of \( x^0 \)

Member Function Documentation

◆ check()

bool PolynomialRoots::Quadratic::check ( ostream_type & s) const

Check tolerance and quality of the computed roots

◆ complex_root()

bool PolynomialRoots::Quadratic::complex_root ( ) const
inline

true if roots are complex conjugated

◆ complexRoot()

bool PolynomialRoots::Quadratic::complexRoot ( ) const
inline

alias of complex_root

◆ double_root()

bool PolynomialRoots::Quadratic::double_root ( ) const
inline

true if \( p(x) = a x^2 + b x + c = (x-r)^2 \)

◆ doubleRoot()

bool PolynomialRoots::Quadratic::doubleRoot ( ) const
inline

alias of double_root

◆ eval() [1/3]

complex_type PolynomialRoots::Quadratic::eval ( complex_type x) const
inline

Evalute the quadratic polynomial

Parameters
[in]xvalue where compute \( p(x)=ax^2+bx+c \)
Returns
the value \( p(x) \)

◆ eval() [2/3]

real_type PolynomialRoots::Quadratic::eval ( real_type x) const
inline

Evaluate the quadratic polynomial

Parameters
xvalue where compute \( p(x) \)
Returns
the value \( p(x) \)

◆ eval() [3/3]

void PolynomialRoots::Quadratic::eval ( real_type x,
real_type & p,
real_type & dp ) const
inline

Evaluate the polynomial with its derivative

Parameters
[in]xvalue where compute \( p(x) \)
[out]pvalue \( p(x) \)
[out]dpvalue \( p'(x) \)

◆ get_negative_roots()

integer PolynomialRoots::Quadratic::get_negative_roots ( real_type r[]) const

Get negative real roots

Parameters
[out]rvector that will be filled with the real roots
Returns
the total number of negative real roots, 0, 1 or 2

◆ get_positive_roots()

integer PolynomialRoots::Quadratic::get_positive_roots ( real_type r[]) const

Get positive real roots

Parameters
[out]rvector that will be filled with the real roots
Returns
the total number of positive real roots, 0, 1 or 2

◆ get_real_roots()

integer PolynomialRoots::Quadratic::get_real_roots ( real_type r[]) const

Get the real roots

Parameters
[out]rvector that will be filled with the real roots
Returns
the total number of real roots, 0, 1 or 2

◆ get_root0() [1/2]

void PolynomialRoots::Quadratic::get_root0 ( complex_type & r) const
inline

Get the first root (complex or real)

Parameters
[out]rthe first complex root

◆ get_root0() [2/2]

void PolynomialRoots::Quadratic::get_root0 ( real_type & re,
real_type & im ) const
inline

Get the first root (complex or real)

Parameters
[out]rethe first complex root, real part
[out]imthe first complex root, imaginary part

◆ get_root1() [1/2]

void PolynomialRoots::Quadratic::get_root1 ( complex_type & r) const
inline

Get the second root (complex or real)

Parameters
[out]rthe second complex root

◆ get_root1() [2/2]

void PolynomialRoots::Quadratic::get_root1 ( real_type & re,
real_type & im ) const
inline

Get the second root (complex or real)

Parameters
[out]rethe second complex root, real part
[out]imthe second complex root, imaginary part

◆ get_roots_in_open_range()

integer PolynomialRoots::Quadratic::get_roots_in_open_range ( real_type a,
real_type b,
real_type r[] ) const

Get real roots in an open range

Parameters
[in]aleft side of the range
[in]bright side of the range
[out]rvector that will be filled with the real roots
Returns
the total number of real roots in the open range \( (a,b) \)

◆ get_roots_in_range()

integer PolynomialRoots::Quadratic::get_roots_in_range ( real_type a,
real_type b,
real_type r[] ) const

Get real roots in a closed range

Parameters
[in]aleft side of the range
[in]bright side of the range
[out]rvector that will be filled with the real roots
Returns
the total number of real roots in the range \( [a,b] \)

◆ getNegativeRoots()

integer PolynomialRoots::Quadratic::getNegativeRoots ( real_type r[]) const
inline

alias of get_negative_roots

◆ getPositiveRoots()

integer PolynomialRoots::Quadratic::getPositiveRoots ( real_type r[]) const
inline

alias of get_positive_roots

◆ getRealRoots()

integer PolynomialRoots::Quadratic::getRealRoots ( real_type r[]) const
inline

alias of get_real_roots

◆ getRoot0() [1/2]

void PolynomialRoots::Quadratic::getRoot0 ( complex_type & r) const
inline

alias of get_root0

◆ getRoot0() [2/2]

void PolynomialRoots::Quadratic::getRoot0 ( real_type & re,
real_type & im ) const
inline

alias of get_root0

◆ getRoot1() [1/2]

void PolynomialRoots::Quadratic::getRoot1 ( complex_type & r) const
inline

alias of get_root1

◆ getRoot1() [2/2]

void PolynomialRoots::Quadratic::getRoot1 ( real_type & re,
real_type & im ) const
inline

alias of get_root1

◆ getRootsInOpenRange()

integer PolynomialRoots::Quadratic::getRootsInOpenRange ( real_type a,
real_type b,
real_type r[] ) const
inline

alias of get_roots_in_open_range

◆ getRootsInRange()

integer PolynomialRoots::Quadratic::getRootsInRange ( real_type a,
real_type b,
real_type r[] ) const
inline

alias of get_roots_in_range

◆ info()

void PolynomialRoots::Quadratic::info ( ostream_type & s) const

Print info of the roots of the polynomial.

◆ num_roots()

integer PolynomialRoots::Quadratic::num_roots ( ) const
inline

Return the number of computed roots of

\[ q(x) = a x^2 + b x + c \]

Normally return 2 but if e.g. \( a = 0 \) return 1 or less depending on the values of \( a, b, c \)

Returns
number of computed roots

◆ numRoots()

integer PolynomialRoots::Quadratic::numRoots ( ) const
inline

alias of num_roots

◆ real_root0()

real_type PolynomialRoots::Quadratic::real_root0 ( ) const
inline

The first real root

◆ real_root1()

real_type PolynomialRoots::Quadratic::real_root1 ( ) const
inline

The second real root

◆ root0()

complex_type PolynomialRoots::Quadratic::root0 ( ) const
inline

The first complex root

◆ root1()

complex_type PolynomialRoots::Quadratic::root1 ( ) const
inline

The second complex root

◆ setup()

void PolynomialRoots::Quadratic::setup ( real_type a,
real_type b,
real_type c )
inline

Setup the object that store the roots of the quadratic polynomial

\[ q(x) = a x^2 + b x + c \]

Parameters
[in]aleading coefficient of \( q(x) \)
[in]bcoefficient of \( x \)
[in]ccoefficient of \( x^0 \)

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