Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
Polynomial Class Reference

Polynomials of degree lower than or equal to 8. 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 &)
 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 form. More...
 
 Polynomial (const Quadric &)
 Creates a polynomial given a quadric form. More...
 
 Polynomial (const Cubic &)
 Creates a polynomial given a cubic form. More...
 
 Polynomial (const Quartic &)
 Creates a polynomial given a quartic form. More...
 
 Polynomial (const Quintic &)
 Creates a polynomial given a quintic form. More...
 
 Polynomial (const Sextic &)
 Creates a polynomial given a sextic form. More...
 
 Polynomial (const Septic &)
 Creates a polynomial given a quintic form. More...
 
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. More...
 
double operator() (const double &) const
 Evaluates the polynomial. More...
 
double operator() (const double &)
 Evaluates the polynomial. More...
 
int Solve (double *) const
 Search the roots of a polynomial equation. More...
 
int SturmSolve (double *) const
 Search the roots of a polynomial equation using the Sturm sequences. More...
 
int Solve (double *, const double &, const double &) const
 Search the roots of a polynomial equation over a given interval. More...
 
int Degree () const
 Returns the degree of the polynomial.
 
void Check ()
 Check the degree of the polynomial. More...
 
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. More...
 
int Bissection (double, double, double &, const double &) const
 Compute the roots of a polynomial equation using bissection. More...
 

Static Public Member Functions

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

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 [9]
 Array of coefficients.
 

Friends

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

Detailed Description

Polynomials of degree lower than or equal to 8.

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);
Polynomials of degree lower than or equal to 8.
Definition: polynomial.h:9
See also
Septic, Sextic, Quintic, Quartic, Cubic, Quadric, Linear.

Constructor & Destructor Documentation

◆ Polynomial() [1/7]

Polynomial::Polynomial ( const Linear p)
inline

Creates a polynomial given a linear form.

Parameters
pLinear polynomial.

◆ Polynomial() [2/7]

Polynomial::Polynomial ( const Quadric p)
inline

Creates a polynomial given a quadric form.

Parameters
pQuadric polynomial.

◆ Polynomial() [3/7]

Polynomial::Polynomial ( const Cubic p)
inline

Creates a polynomial given a cubic form.

Parameters
pCubic polynomial.

◆ Polynomial() [4/7]

Polynomial::Polynomial ( const Quartic p)
inline

Creates a polynomial given a quartic form.

Parameters
pQuartic polynomial.

◆ Polynomial() [5/7]

Polynomial::Polynomial ( const Quintic p)
inline

Creates a polynomial given a quintic form.

Parameters
pQuintic polynomial.

◆ Polynomial() [6/7]

Polynomial::Polynomial ( const Sextic p)
inline

Creates a polynomial given a sextic form.

Parameters
pSextic polynomial.

◆ Polynomial() [7/7]

Polynomial::Polynomial ( const Septic p)
inline

Creates a polynomial given a quintic form.

Parameters
pSeptic 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()() [1/2]

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

Evaluates the polynomial.

Parameters
xReal.

◆ operator()() [2/2]

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 Function Documentation

◆ operator<<

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

Overloaded output-stream operator.

Parameters
sStream.
pThe polynomial.