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

#include <PolynomialRoots.hh>

Public Member Functions

 Quartic ()
 
 Quartic (real_type a, real_type b, real_type c, real_type d, real_type e)
 
void setup (real_type a, real_type b, real_type c, real_type d, real_type e)
 
integer num_roots () const
 
integer numRoots () const
 alias of num_roots
 
integer num_real_roots () const
 
integer numRealRoots () const
 alias of num_real_roots
 
integer num_complex_roots () const
 
integer numComplexRoots () const
 alias of num_complex_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
 
real_type real_root3 () const
 
complex_type root0 () const
 
complex_type root1 () const
 
complex_type root2 () const
 
complex_type root3 () 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
 
void get_root3 (real_type &re, real_type &im) const
 
void getRoot3 (real_type &re, real_type &im) const
 alias of get_root3
 
void get_root3 (complex_type &r) const
 
void getRoot3 (complex_type &r) const
 alias of get_root3
 
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

Quartic polynomial class

Constructor

double a = 1;
double b = 2;
double c = 3;
double d = 3;
double e = 3;
Quartic p(a,b,c,d,e); // build an solve a x^4 + b x^3 + c x^2 + d x + e = 0
p.setup(a,b,c,d,e); // build an solve a x^4 + b x^3 + c x^2 + d x + e = 0
Quartic()
Definition PolynomialRoots.hh:964
void setup(real_type a, real_type b, real_type c, real_type d, real_type e)
Definition PolynomialRoots.hh:996

Get kind of solution

int nroots = p.num_roots();
int nroots = p.num_real_roots();
int nroots = p.num_complex_root();
integer num_real_roots() const
Definition PolynomialRoots.hh:1030
integer num_roots() const
Definition PolynomialRoots.hh:1022

Get real roots

double r_min = 0;
double r_max = 2;
double r[4];
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 getPositiveRoots(real_type r[]) const
alias of get_positive_roots
Definition PolynomialRoots.hh:1063
integer getRootsInOpenRange(real_type a, real_type b, real_type r[]) const
alias of get_roots_in_open_range
Definition PolynomialRoots.hh:1100
integer getRootsInRange(real_type a, real_type b, real_type r[]) const
alias of get_roots_in_range
Definition PolynomialRoots.hh:1087
integer getRealRoots(real_type r[]) const
alias of get_real_roots
Definition PolynomialRoots.hh:1052
integer getNegativeRoots(real_type r[]) const
alias of get_negative_roots
Definition PolynomialRoots.hh:1074

Get roots

double r0 = p.real_root0();
double r1 = p.real_root1();
double r2 = p.real_root2();
double r3 = p.real_root3();
double re, im;
p.getRoot0( re, im );
p.getRoot0( r );
p.getRoot1( re, im );
p.getRoot1( r );
p.getRoot2( re, im );
p.getRoot2( r );
p.getRoot3( re, im );
p.getRoot3( r );
real_type real_root1() const
Definition PolynomialRoots.hh:1110
real_type real_root3() const
Definition PolynomialRoots.hh:1120
complex_type root0() const
Definition PolynomialRoots.hh:1126
void getRoot2(real_type &re, real_type &im) const
alias of get_root2
Definition PolynomialRoots.hh:1208
void getRoot0(real_type &re, real_type &im) const
alias of get_root0
Definition PolynomialRoots.hh:1160
void getRoot3(real_type &re, real_type &im) const
alias of get_root3
Definition PolynomialRoots.hh:1232
complex_type root3() const
Definition PolynomialRoots.hh:1147
real_type real_root2() const
Definition PolynomialRoots.hh:1115
complex_type root2() const
Definition PolynomialRoots.hh:1140
complex_type root1() const
Definition PolynomialRoots.hh:1133
real_type real_root0() const
Definition PolynomialRoots.hh:1105
void getRoot1(real_type &re, real_type &im) const
alias of get_root1
Definition PolynomialRoots.hh:1184
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:1253

Information

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

Constructor & Destructor Documentation

◆ Quartic() [1/2]

PolynomialRoots::Quartic::Quartic ( )
inline

◆ Quartic() [2/2]

PolynomialRoots::Quartic::Quartic ( real_type a,
real_type b,
real_type c,
real_type d,
real_type e )
inline

Member Function Documentation

◆ check()

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

Check tolerenace and quality of the computed roots.

◆ eval() [1/3]

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

Evalute the quartic polynomial.

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

◆ eval() [2/3]

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

Evalute the quartic polynomial.

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

◆ eval() [3/3]

void PolynomialRoots::Quartic::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::Quartic::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, 3 or 4

◆ get_positive_roots()

integer PolynomialRoots::Quartic::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, 3 or 4

◆ get_real_roots()

integer PolynomialRoots::Quartic::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, 3 or 4

◆ get_root0() [1/2]

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

First real or complex root.

◆ get_root0() [2/2]

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

First real or complex root.

◆ get_root1() [1/2]

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

Second real or complex root.

◆ get_root1() [2/2]

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

Second real or complex root.

◆ get_root2() [1/2]

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

Third real or complex root.

◆ get_root2() [2/2]

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

Third real or complex root.

◆ get_root3() [1/2]

void PolynomialRoots::Quartic::get_root3 ( complex_type & r) const
inline

4th real or complex root.

◆ get_root3() [2/2]

void PolynomialRoots::Quartic::get_root3 ( real_type & re,
real_type & im ) const
inline

4th real or complex root.

◆ get_roots_in_open_range()

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

alias of get_negative_roots

◆ getPositiveRoots()

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

alias of get_positive_roots

◆ getRealRoots()

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

alias of get_real_roots

◆ getRoot0() [1/2]

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

alias of get_root0

◆ getRoot0() [2/2]

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

alias of get_root0

◆ getRoot1() [1/2]

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

alias of get_root1

◆ getRoot1() [2/2]

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

alias of get_root1

◆ getRoot2() [1/2]

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

alias of get_root2

◆ getRoot2() [2/2]

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

alias of get_root2

◆ getRoot3() [1/2]

void PolynomialRoots::Quartic::getRoot3 ( complex_type & r) const
inline

alias of get_root3

◆ getRoot3() [2/2]

void PolynomialRoots::Quartic::getRoot3 ( real_type & re,
real_type & im ) const
inline

alias of get_root3

◆ getRootsInOpenRange()

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

alias of get_roots_in_open_range

◆ getRootsInRange()

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

alias of get_roots_in_range

◆ info()

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

Print info of the roots of the polynomial.

◆ num_complex_roots()

integer PolynomialRoots::Quartic::num_complex_roots ( ) const
inline

Number of complex roots

◆ num_real_roots()

integer PolynomialRoots::Quartic::num_real_roots ( ) const
inline

Number of real roots.

◆ num_roots()

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

Number of roots found.

◆ numComplexRoots()

integer PolynomialRoots::Quartic::numComplexRoots ( ) const
inline

alias of num_complex_root

◆ numRealRoots()

integer PolynomialRoots::Quartic::numRealRoots ( ) const
inline

alias of num_real_roots

◆ numRoots()

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

alias of num_roots

◆ real_root0()

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

First real root.

◆ real_root1()

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

Second real root.

◆ real_root2()

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

Third real root.

◆ real_root3()

real_type PolynomialRoots::Quartic::real_root3 ( ) const
inline

Fourth real root.

◆ root0()

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

First real or complex root.

◆ root1()

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

Second real or complex root.

◆ root2()

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

Third real or complex root.

◆ root3()

complex_type PolynomialRoots::Quartic::root3 ( ) const
inline

4th real or complex root.

◆ setup()

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

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

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

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