Quartic roots
Utilities for C++ programming
Loading...
Searching...
No Matches
PolynomialRoots::QuarticT< T_real, T_complex > Class Template Reference

#include <PolynomialRoots.hh>

Public Types

using value_type = T_real
using complex_type = T_complex

Public Member Functions

 QuarticT ()=default
 Build an empty quartic solver instance.
 QuarticT (T_real const &a, T_real const &b, T_real const &c, T_real const &d, T_real const &e)
void setup (T_real const &a, T_real const &b, T_real const &c, T_real const &d, T_real const &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_roots().
integer get_real_roots (T_real r[]) const
integer getRealRoots (T_real r[]) const
 Alias of get_real_roots().
integer get_positive_roots (T_real r[]) const
integer getPositiveRoots (T_real r[]) const
 Alias of get_positive_roots().
integer get_negative_roots (T_real r[]) const
integer getNegativeRoots (T_real r[]) const
 Alias of get_negative_roots().
integer get_roots_in_range (T_real const &a, T_real const &b, T_real r[]) const
integer getRootsInRange (T_real const &a, T_real const &b, T_real r[]) const
 Alias of get_roots_in_range().
integer get_roots_in_open_range (T_real const &a, T_real const &b, T_real r[]) const
integer getRootsInOpenRange (T_real const &a, T_real const &b, T_real r[]) const
 Alias of get_roots_in_open_range().
T_real real_root0 () const
T_real real_root1 () const
T_real real_root2 () const
T_real real_root3 () const
T_complex root0 () const
T_complex root1 () const
T_complex root2 () const
T_complex root3 () const
void get_root0 (T_real &re, T_real &im) const
void getRoot0 (T_real &re, T_real &im) const
 Alias of get_root0().
void get_root0 (T_complex &r) const
void getRoot0 (T_complex &r) const
 Alias of get_root0().
void get_root1 (T_real &re, T_real &im) const
void getRoot1 (T_real &re, T_real &im) const
 Alias of get_root1().
void get_root1 (T_complex &r) const
void getRoot1 (T_complex &r) const
 Alias of get_root1().
void get_root2 (T_real &re, T_real &im) const
void getRoot2 (T_real &re, T_real &im) const
 Alias of get_root2().
void get_root2 (T_complex &r) const
void getRoot2 (T_complex &r) const
 Alias of get_root2().
void get_root3 (T_real &re, T_real &im) const
void getRoot3 (T_real &re, T_real &im) const
 Alias of get_root3().
void get_root3 (T_complex &r) const
void getRoot3 (T_complex &r) const
 Alias of get_root3().
T_complex root (integer const i) const
void get_root (integer const i, T_real &re, T_real &im) const
T_real eval (T_real const &x) const
T_complex eval (T_complex const &x) const
void eval (T_real const &x, T_real &p, T_real &dp) const
void info (ostream_type &s) const
bool check (ostream_type &s) const

Detailed Description

template<typename T_real, typename T_complex>
class PolynomialRoots::QuarticT< T_real, T_complex >

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
void setup(T_real const &a, T_real const &b, T_real const &c, T_real const &d, T_real const &e)
Definition PolynomialRoots.hh:1131
QuarticT< real_type, real_complex > Quartic
Definition PolynomialRoots.hh:1481

Get kind of solution

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

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(T_real r[]) const
Alias of get_positive_roots().
Definition PolynomialRoots.hh:1194
integer getRealRoots(T_real r[]) const
Alias of get_real_roots().
Definition PolynomialRoots.hh:1183
integer getRootsInRange(T_real const &a, T_real const &b, T_real r[]) const
Alias of get_roots_in_range().
Definition PolynomialRoots.hh:1218
integer getNegativeRoots(T_real r[]) const
Alias of get_negative_roots().
Definition PolynomialRoots.hh:1205
integer getRootsInOpenRange(T_real const &a, T_real const &b, T_real r[]) const
Alias of get_roots_in_open_range().
Definition PolynomialRoots.hh:1232

Get roots

real_type 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 );
T_complex root3() const
Definition PolynomialRoots.hh:1279
void getRoot2(T_real &re, T_real &im) const
Alias of get_root2().
Definition PolynomialRoots.hh:1367
T_real real_root2() const
Definition PolynomialRoots.hh:1253
void getRoot3(T_real &re, T_real &im) const
Alias of get_root3().
Definition PolynomialRoots.hh:1401
void getRoot0(T_real &re, T_real &im) const
Alias of get_root0().
Definition PolynomialRoots.hh:1299
T_complex root1() const
Definition PolynomialRoots.hh:1269
T_real real_root3() const
Definition PolynomialRoots.hh:1259
void getRoot1(T_real &re, T_real &im) const
Alias of get_root1().
Definition PolynomialRoots.hh:1333
T_complex root0() const
Definition PolynomialRoots.hh:1264
T_real real_root0() const
Definition PolynomialRoots.hh:1241
T_complex root2() const
Definition PolynomialRoots.hh:1274
T_real real_root1() const
Definition PolynomialRoots.hh:1247
Lightweight complex number type used by the standard-precision solvers.
Definition PolynomialRoots-complex.hxx:30
double real_type
Scalar type used by the standard-precision API.
Definition PolynomialRoots.hh:66

Evaluate polynomial

{double or complex} v, x;
v = p.eval( x );
p.eval( x, p, dp );
T_real eval(T_real const &x) const
Definition PolynomialRoots.hh:1455

Information

p.info( cout );
bool ok = p.check( cout );
bool check(ostream_type &s) const
Definition PolynomialRoots-3-Quartic.cc:894
void info(ostream_type &s) const
Definition PolynomialRoots-3-Quartic.cc:847

Member Typedef Documentation

◆ complex_type

template<typename T_real, typename T_complex>
using PolynomialRoots::QuarticT< T_real, T_complex >::complex_type = T_complex

◆ value_type

template<typename T_real, typename T_complex>
using PolynomialRoots::QuarticT< T_real, T_complex >::value_type = T_real

Constructor & Destructor Documentation

◆ QuarticT() [1/2]

template<typename T_real, typename T_complex>
PolynomialRoots::QuarticT< T_real, T_complex >::QuarticT ( )
default

Build an empty quartic solver instance.

◆ QuarticT() [2/2]

template<typename T_real, typename T_complex>
PolynomialRoots::QuarticT< T_real, T_complex >::QuarticT ( T_real const & a,
T_real const & b,
T_real const & c,
T_real const & d,
T_real const & e )
inline

Build the instance and immediately compute the quartic roots.

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 \)

Member Function Documentation

◆ check()

template<typename T_real, typename T_complex>
bool PolynomialRoots::QuarticT< T_real, T_complex >::check ( ostream_type & s) const
nodiscard

Check tolerance and quality of the computed roots.

◆ eval() [1/3]

template<typename T_real, typename T_complex>
T_complex PolynomialRoots::QuarticT< T_real, T_complex >::eval ( T_complex const & x) const
inline

Evaluate the quartic polynomial at a complex point.

Parameters
[in]xcomplex value where compute \( p(x) \)
Returns
the value \( p(x) \)

◆ eval() [2/3]

template<typename T_real, typename T_complex>
T_real PolynomialRoots::QuarticT< T_real, T_complex >::eval ( T_real const & x) const
inline

Evaluate the quartic polynomial at a real point.

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

◆ eval() [3/3]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::eval ( T_real const & x,
T_real & p,
T_real & dp ) const
inline

Evaluate the quartic polynomial and its derivative at a real point.

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

◆ get_negative_roots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::get_negative_roots ( T_real 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()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::get_positive_roots ( T_real 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()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::get_real_roots ( T_real 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_root()

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root ( integer const i,
T_real & re,
T_real & im ) const
inline

Store the i-th root in split real/imaginary form.

Parameters
[in]iroot index in [0,3]
[out]rereal part of the selected root
[out]imimaginary part of the selected root

◆ get_root0() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root0 ( T_complex & r) const
inline

First real or complex root.

◆ get_root0() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root0 ( T_real & re,
T_real & im ) const
inline

First real or complex root.

◆ get_root1() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root1 ( T_complex & r) const
inline

Second real or complex root.

◆ get_root1() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root1 ( T_real & re,
T_real & im ) const
inline

Second real or complex root.

◆ get_root2() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root2 ( T_complex & r) const
inline

Third real or complex root.

◆ get_root2() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root2 ( T_real & re,
T_real & im ) const
inline

Third real or complex root.

◆ get_root3() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root3 ( T_complex & r) const
inline

Fourth real or complex root.

◆ get_root3() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::get_root3 ( T_real & re,
T_real & im ) const
inline

Fourth real or complex root.

◆ get_roots_in_open_range()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::get_roots_in_open_range ( T_real const & a,
T_real const & b,
T_real 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()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::get_roots_in_range ( T_real const & a,
T_real const & b,
T_real 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()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::getNegativeRoots ( T_real r[]) const
inline

◆ getPositiveRoots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::getPositiveRoots ( T_real r[]) const
inline

◆ getRealRoots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::getRealRoots ( T_real r[]) const
inline

Alias of get_real_roots().

◆ getRoot0() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot0 ( T_complex & r) const
inline

Alias of get_root0().

◆ getRoot0() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot0 ( T_real & re,
T_real & im ) const
inline

Alias of get_root0().

◆ getRoot1() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot1 ( T_complex & r) const
inline

Alias of get_root1().

◆ getRoot1() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot1 ( T_real & re,
T_real & im ) const
inline

Alias of get_root1().

◆ getRoot2() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot2 ( T_complex & r) const
inline

Alias of get_root2().

◆ getRoot2() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot2 ( T_real & re,
T_real & im ) const
inline

Alias of get_root2().

◆ getRoot3() [1/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot3 ( T_complex & r) const
inline

Alias of get_root3().

◆ getRoot3() [2/2]

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::getRoot3 ( T_real & re,
T_real & im ) const
inline

Alias of get_root3().

◆ getRootsInOpenRange()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::getRootsInOpenRange ( T_real const & a,
T_real const & b,
T_real r[] ) const
inline

◆ getRootsInRange()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::getRootsInRange ( T_real const & a,
T_real const & b,
T_real r[] ) const
inline

◆ info()

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::info ( ostream_type & s) const

Print info of the roots of the polynomial.

◆ num_complex_roots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::num_complex_roots ( ) const
inline

Number of complex roots.

◆ num_real_roots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::num_real_roots ( ) const
inline

Number of real roots.

◆ num_roots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::num_roots ( ) const
inline

Number of roots found.

◆ numComplexRoots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::numComplexRoots ( ) const
inline

◆ numRealRoots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::numRealRoots ( ) const
inline

Alias of num_real_roots().

◆ numRoots()

template<typename T_real, typename T_complex>
integer PolynomialRoots::QuarticT< T_real, T_complex >::numRoots ( ) const
inline

Alias of num_roots().

◆ real_root0()

template<typename T_real, typename T_complex>
T_real PolynomialRoots::QuarticT< T_real, T_complex >::real_root0 ( ) const
inline

Return the first stored real component.

When num_complex_roots() > 0, this is the real part of the first conjugate pair returned by root0() and root1().

◆ real_root1()

template<typename T_real, typename T_complex>
T_real PolynomialRoots::QuarticT< T_real, T_complex >::real_root1 ( ) const
inline

Return the second stored real component.

When num_complex_roots() > 0, this is the positive imaginary part of the first conjugate pair. Otherwise it is the second real root.

◆ real_root2()

template<typename T_real, typename T_complex>
T_real PolynomialRoots::QuarticT< T_real, T_complex >::real_root2 ( ) const
inline

Return the third stored real component.

When num_complex_roots() > 2, this is the real part of the second conjugate pair returned by root2() and root3().

◆ real_root3()

template<typename T_real, typename T_complex>
T_real PolynomialRoots::QuarticT< T_real, T_complex >::real_root3 ( ) const
inline

Return the fourth stored real component.

When num_complex_roots() > 2, this is the positive imaginary part of the second conjugate pair. Otherwise it is the fourth real root.

◆ root()

template<typename T_real, typename T_complex>
T_complex PolynomialRoots::QuarticT< T_real, T_complex >::root ( integer const i) const
inline

Return the i-th root as a complex value.

Parameters
[in]iroot index in [0,3]
Returns
requested root, or zero for an invalid index

◆ root0()

template<typename T_real, typename T_complex>
T_complex PolynomialRoots::QuarticT< T_real, T_complex >::root0 ( ) const
inline

Return the first root as a complex value.

◆ root1()

template<typename T_real, typename T_complex>
T_complex PolynomialRoots::QuarticT< T_real, T_complex >::root1 ( ) const
inline

Return the second root as a complex value.

◆ root2()

template<typename T_real, typename T_complex>
T_complex PolynomialRoots::QuarticT< T_real, T_complex >::root2 ( ) const
inline

Return the third root as a complex value.

◆ root3()

template<typename T_real, typename T_complex>
T_complex PolynomialRoots::QuarticT< T_real, T_complex >::root3 ( ) const
inline

Return the fourth root as a complex value.

◆ setup()

template<typename T_real, typename T_complex>
void PolynomialRoots::QuarticT< T_real, T_complex >::setup ( T_real const & a,
T_real const & b,
T_real const & c,
T_real const & d,
T_real const & 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 files: