Core 1.0
Polynomial Class Reference

Polynomials of degree lower than or equal to 11. More...

#include <polynomial.h>

Public Member Functions

 Polynomial ()
 Creates a null polynomial.
 
 ~Polynomial ()
 Empty.
 
 Polynomial (const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &)
 Creates a degree 9 polynomial.
 
 Polynomial (const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &)
 Creates a degree 8 polynomial.
 
 Polynomial (const double &, const double &, const double &, const double &, const double &, const double &, const double &, const double &)
 Creates a septic.
 
 Polynomial (const double &, const double &, const double &, const double &, const double &, const double &, const double &)
 Creates a sextic.
 
 Polynomial (const double &, const double &, const double &, const double &, const double &, const double &)
 Creates a quintic.
 
 Polynomial (const double &, const double &, const double &, const double &, const double &)
 Creates a quartic.
 
 Polynomial (const double &, const double &, const double &, const double &)
 Creates a cubic.
 
 Polynomial (const double &, const double &, const double &)
 Creates a quadric.
 
 Polynomial (const double &, const double &)
 Creates a linear polynomial.
 
 Polynomial (const double &)
 Creates a constant polynomial.
 
 Polynomial (const Linear &)
 Creates a polynomial given a linear.
 
 Polynomial (const Quadric &)
 Creates a polynomial given a quadric.
 
 Polynomial (const Cubic &)
 Creates a polynomial given a cubic.
 
 Polynomial (const Quartic &)
 Creates a polynomial given a quartic.
 
 Polynomial (const Quintic &)
 Creates a polynomial given a quintic.
 
 Polynomial (const Sextic &)
 Creates a polynomial given a sextic.
 
 Polynomial (const Septic &)
 Creates a polynomial given a septic.
 
 Polynomial (const Octic &)
 Creates a polynomial given an octic.
 
 Polynomial (const Nonic &)
 Creates a polynomial given a nonic.
 
constexpr double & operator[] (int)
 Access to the cefficients of the polynomial.
 
constexpr double operator[] (int) const
 Overloaded.
 
Polynomial operator+ () const
 Overloaded.
 
Polynomial operator- () const
 Unary.
 
Polynomialoperator+= (const Polynomial &)
 Destructive sum of two polynomials.
 
Polynomialoperator-= (const Polynomial &)
 Destructive difference of two polynomials.
 
Polynomialoperator*= (const Polynomial &)
 Overloaded.
 
Polynomialoperator*= (const double &)
 Scale a polynomial by a double value. Optimizations are provided if scalar is 0.0 or 1.0.
 
Polynomialoperator/= (const double &)
 Scale a polynomial by a double value.
 
Polynomial Prime () const
 Compute the derivative of the polynomial.
 
Polynomial Compose (const Polynomial &) const
 Compose the polynomial by the argument polynomial.
 
Polynomial Reversed () const
 Reverse the terms of the polynomial.
 
double operator() (const double &) const
 Evaluates the polynomial.
 
int Solve (double *) const
 Search the roots of a polynomial equation.
 
int SturmSolve (double *) const
 Search the roots of a polynomial equation using the Sturm sequences.
 
int Solve (double *, const double &, const double &) const
 Search the roots of a polynomial equation over a given interval.
 
int Degree () const
 Returns the degree of the polynomial.
 
void Check ()
 Check the degree of the polynomial.
 
void Range (double &, double &, const double &=0.0, const double &=1.0) const
 This function computes the range of values taken by a polynomial over a given interval.
 
int Bissection (double, double, double &, const double &) const
 Compute the roots of a polynomial equation using bissection.
 

Static Public Member Functions

static Polynomial Compose (const Quartic &, const Quadric &)
 Compose the quartic by a quadric.
 

Static Public Attributes

static const Polynomial Null
 Set the null polynomial member constant.
 

Protected Attributes

int n = 0
 The degree of the polynomial.
 
double c [MaxDegree+1] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }
 Array of coefficients.
 

Static Protected Attributes

static constexpr int MaxDegree = 11
 Maximum degree.
 

Friends

Polynomial operator+ (const Polynomial &u, const Polynomial &v)
 Overloaded.
 
Polynomial operator- (const Polynomial &u, const Polynomial &v)
 Overloaded.
 
Polynomial operator* (const Polynomial &u, const Polynomial &v)
 Multiply two polynomials.
 
Polynomial operator* (const Polynomial &u, const double &e)
 Multiply a polynomial by a scalar value. Optimizations are provided if scalar is 0.0 or 1.0.
 
Polynomial operator* (const double &a, const Polynomial &p)
 Overloaded.
 
Polynomial operator/ (const Polynomial &p, const double &a)
 Overloaded.
 
std::ostream & operator<< (std::ostream &s, const Polynomial &p)
 Overloaded output-stream operator.
 

Detailed Description

Polynomials of degree lower than or equal to 11.

This class is defined as a fixed size data-structure to speed-up and facilitate memory management. It is more memory and computationnally efficient to use Linear, Quadric, Cubic, and Quartic classes whenever possible.

When using constructors, the coefficients are given in descending order, i.e. start from the highest degree coefficient to the lowest degree.

Example of how to code the quartic polynomial 3 x4-x+1:

Polynomial p(3.0,0.0,0.0,-1.0,1.0);
Polynomial()
Creates a null polynomial.
Definition polynomial.cpp:32
See also
Septic, Sextic, Quintic, Quartic, Cubic, Quadric, Linear.

Constructor & Destructor Documentation

◆ Polynomial() [1/9]

Polynomial::Polynomial ( const Linear & p)
inline

Creates a polynomial given a linear.

Parameters
pLinear polynomial.

◆ Polynomial() [2/9]

Polynomial::Polynomial ( const Quadric & p)
inline

Creates a polynomial given a quadric.

Parameters
pQuadric polynomial.

◆ Polynomial() [3/9]

Polynomial::Polynomial ( const Cubic & p)
inline

Creates a polynomial given a cubic.

Parameters
pCubic polynomial.

◆ Polynomial() [4/9]

Polynomial::Polynomial ( const Quartic & p)
inline

Creates a polynomial given a quartic.

Parameters
pQuartic polynomial.

◆ Polynomial() [5/9]

Polynomial::Polynomial ( const Quintic & p)
inline

Creates a polynomial given a quintic.

Parameters
pQuintic polynomial.

◆ Polynomial() [6/9]

Polynomial::Polynomial ( const Sextic & p)
inline

Creates a polynomial given a sextic.

Parameters
pSextic polynomial.

◆ Polynomial() [7/9]

Polynomial::Polynomial ( const Septic & p)
inline

Creates a polynomial given a septic.

Parameters
pSeptic polynomial.

◆ Polynomial() [8/9]

Polynomial::Polynomial ( const Octic & p)
inline

Creates a polynomial given an octic.

Parameters
pOctic polynomial.

◆ Polynomial() [9/9]

Polynomial::Polynomial ( const Nonic & p)
inline

Creates a polynomial given a nonic.

Parameters
pNonic polynomial.

Member Function Documentation

◆ Bissection()

int Polynomial::Bissection ( double a,
double b,
double & val,
const double & epsilon ) const

Compute the roots of a polynomial equation using bissection.

Parameters
a,bInterval.
valValue.
epsilonPrecision.

◆ Check()

void Polynomial::Check ( )

Check the degree of the polynomial.

The function decreases the degree if higher coefficients are null.

◆ Compose() [1/2]

Polynomial Polynomial::Compose ( const Polynomial & v) const

Compose the polynomial by the argument polynomial.

Parameters
vArgument polynomial.

◆ Compose() [2/2]

Polynomial Polynomial::Compose ( const Quartic & p,
const Quadric & q )
static

Compose the quartic by a quadric.

This function computes p ( q(x) ), where p denotes the quartic and q the quadric.

Parameters
pThe quartic.
qThe quadric.

◆ operator()()

double Polynomial::operator() ( const double & x) const

Evaluates the polynomial.

Parameters
xParameter.

◆ Range()

void Polynomial::Range ( double & x,
double & y,
const double & a = 0.0,
const double & b = 1.0 ) const

This function computes the range of values taken by a polynomial over a given interval.

Computes the roots of the first derivative, and evaluates the polynomial at the roots if they are within the interval bounds.

Parameters
a,bInterval.
x,yReturned range.

◆ Solve() [1/2]

int Polynomial::Solve ( double * roots) const

Search the roots of a polynomial equation.

This function calls other root solving functions, invoking Quartic::Quartic(), Cubic::Solve() or Quadratic::Solve() as appropriate if the degree is lower of equal than four (which means that closed form expressions of the roots exist).

Otherwise, rely on a numeric root finder to isolate roots and converge using the Sturm sequences.

Parameters
rootsArray for storing the roots.
Returns
The number of roots.

◆ Solve() [2/2]

int Polynomial::Solve ( double * roots,
const double & a,
const double & b ) const

Search the roots of a polynomial equation over a given interval.

Parameters
rootsThe array of roots.
a,bThe search interval.
Returns
The number of roots.

◆ SturmSolve()

int Polynomial::SturmSolve ( double * roots) const

Search the roots of a polynomial equation using the Sturm sequences.

Parameters
rootsArray for storing the roots.
Returns
The number of roots.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Polynomial & p )
friend

Overloaded output-stream operator.

Parameters
sStream.
pThe polynomial.