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

#include <PolynomialRoots.hh>

Public Member Functions

 Cubic ()
 
 Cubic (real_type a, real_type b, real_type c, real_type d)
 
void setup (real_type a, real_type b, real_type c, real_type d)
 
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
 
bool triple_root () const
 
bool tripleRoot () const
 alias of triple_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
 
real_type real_root2 () const
 
complex_type root0 () const
 
complex_type root1 () const
 
complex_type root2 () 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
 
void get_root2 (real_type &re, real_type &im) const
 
void getRoot2 (real_type &re, real_type &im) const
 alias of get_root2
 
void get_root2 (complex_type &r) const
 
void getRoot2 (complex_type &r) const
 alias of get_root2
 
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

Cubic polynomial class

Constructor

double a = 1;
double b = 2;
double c = 3;
double d = 3;
Cubic p(a,b,c,d); // build an solve a x^3 + b x^2 + c x + d = 0
p.setup(a,b,c,d); // build an solve a x^3 + b x^2 + c x + d = 0
Cubic()
Definition PolynomialRoots.hh:565
void setup(real_type a, real_type b, real_type c, real_type d)
Definition PolynomialRoots.hh:599

Get kind of solution

int nroots = p.num_roots();
bool has_complex_root = p.complex_root();
bool has_a_double_root = p.double_root();
bool has_a_triple_root = p.triple_root();
bool complex_root() const
Definition PolynomialRoots.hh:627
bool double_root() const
Definition PolynomialRoots.hh:635
integer num_roots() const
Definition PolynomialRoots.hh:619
bool triple_root() const
Definition PolynomialRoots.hh:643

Get real roots

double r_min = 0;
double r_max = 2;
double r[3];
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 );
integer getRootsInRange(real_type a, real_type b, real_type r[]) const
alias of get_roots_in_range
Definition PolynomialRoots.hh:699
integer getPositiveRoots(real_type r[]) const
alias of get_positive_roots
Definition PolynomialRoots.hh:671
integer getRealRoots(real_type r[]) const
alias of get_real_roots
Definition PolynomialRoots.hh:658
integer getRootsInOpenRange(real_type a, real_type b, real_type r[]) const
alias of get_roots_in_open_range
Definition PolynomialRoots.hh:714
integer getNegativeRoots(real_type r[]) const
alias of get_negative_roots
Definition PolynomialRoots.hh:684

Get roots

double r0 = p.real_root0();
double r1 = p.real_root1();
double r2 = p.real_root2();
double re, im;
p.getRoot0( re, im );
p.getRoot0( r );
p.getRoot1( re, im );
p.getRoot1( r );
p.getRoot2( re, im );
p.getRoot2( r );
void getRoot1(real_type &re, real_type &im) const
alias of get_root1
Definition PolynomialRoots.hh:785
complex_type root0() const
Definition PolynomialRoots.hh:736
complex_type root2() const
Definition PolynomialRoots.hh:750
real_type real_root2() const
Definition PolynomialRoots.hh:730
real_type real_root0() const
Definition PolynomialRoots.hh:720
void getRoot2(real_type &re, real_type &im) const
alias of get_root2
Definition PolynomialRoots.hh:805
complex_type root1() const
Definition PolynomialRoots.hh:743
real_type real_root1() const
Definition PolynomialRoots.hh:725
void getRoot0(real_type &re, real_type &im) const
alias of get_root0
Definition PolynomialRoots.hh:763
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 );
real_type eval(real_type x) const
Definition PolynomialRoots.hh:824

Information

p.info( cout );
bool ok = p.check( cout );
void info(ostream_type &s) const
bool check(ostream_type &s) const

Constructor & Destructor Documentation

◆ Cubic() [1/2]

PolynomialRoots::Cubic::Cubic ( )
inline

Build an empty instance of Cubic polynomial solver

◆ Cubic() [2/2]

PolynomialRoots::Cubic::Cubic ( real_type a,
real_type b,
real_type c,
real_type d )
inline

Build the instance of the calss and compute the roots of cubic polynomial \( a x^3 + b x^2 + c x + d \)

Parameters
[in]acoefficient of \( x^3 \)
[in]bcoefficient of \( x^2 \)
[in]ccoefficient of \( x \)
[in]dcoefficient of \( x^0 \)

Member Function Documentation

◆ check()

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

Check tolerenace and quality of the computed roots.

◆ complex_root()

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

Has complex roots?

◆ complexRoot()

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

alias of complex_root

◆ double_root()

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

Has a double root?

◆ doubleRoot()

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

alias of double_root

◆ eval() [1/3]

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

Evalute the cubic polynomial.

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

◆ eval() [2/3]

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

Evalute the cubic polynomial.

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

◆ eval() [3/3]

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

Evalute the polynomial with its derivative.

Parameters
xvalue where compute \( p(x) \)
pvalue \( p(x) \)
dpvalue \( p'(x) \)

◆ get_negative_roots()

integer PolynomialRoots::Cubic::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, 2 or 3

◆ get_positive_roots()

integer PolynomialRoots::Cubic::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, 2 or 3

◆ get_real_roots()

integer PolynomialRoots::Cubic::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, 2 or 3

◆ get_root0() [1/2]

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

First complex or real root.

◆ get_root0() [2/2]

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

First complex or real root.

◆ get_root1() [1/2]

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

Second complex or real root.

◆ get_root1() [2/2]

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

Second complex or real root.

◆ get_root2() [1/2]

void PolynomialRoots::Cubic::get_root2 ( complex_type & r) const
inline

Third complex or real root.

◆ get_root2() [2/2]

void PolynomialRoots::Cubic::get_root2 ( real_type & re,
real_type & im ) const
inline

Third complex or real root.

◆ get_roots_in_open_range()

integer PolynomialRoots::Cubic::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::Cubic::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::Cubic::getNegativeRoots ( real_type r[]) const
inline

alias of get_negative_roots

◆ getPositiveRoots()

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

alias of get_positive_roots

◆ getRealRoots()

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

alias of get_real_roots

◆ getRoot0() [1/2]

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

alias of get_root0

◆ getRoot0() [2/2]

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

alias of get_root0

◆ getRoot1() [1/2]

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

alias of get_root1

◆ getRoot1() [2/2]

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

alias of get_root1

◆ getRoot2() [1/2]

void PolynomialRoots::Cubic::getRoot2 ( complex_type & r) const
inline

alias of get_root2

◆ getRoot2() [2/2]

void PolynomialRoots::Cubic::getRoot2 ( real_type & re,
real_type & im ) const
inline

alias of get_root2

◆ getRootsInOpenRange()

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

alias of get_roots_in_open_range

◆ getRootsInRange()

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

alias of get_roots_in_range

◆ info()

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

Print info of the roots of the polynomial.

◆ num_roots()

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

Number of found roots.

◆ numRoots()

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

alias of num_roots

◆ real_root0()

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

First real root.

◆ real_root1()

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

Second real root.

◆ real_root2()

real_type PolynomialRoots::Cubic::real_root2 ( ) const
inline

Third real root.

◆ root0()

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

First complex or real root.

◆ root1()

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

Second complex or real root.

◆ root2()

complex_type PolynomialRoots::Cubic::root2 ( ) const
inline

Third complex or real root.

◆ setup()

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

Compute the roots of cubic polynomial \( a x^3 + b x^2 + c x + d \)

Parameters
[in]acoefficient of \( x^3 \)
[in]bcoefficient of \( x^2 \)
[in]ccoefficient of \( x \)
[in]dcoefficient of \( x^0 \)

◆ triple_root()

bool PolynomialRoots::Cubic::triple_root ( ) const
inline

Has a triple root?

◆ tripleRoot()

bool PolynomialRoots::Cubic::tripleRoot ( ) const
inline

alias of triple_root


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