Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::mathLevel::PolyBase Class Reference

Holds a polynominal as a primary type. More...

#include <PolyBase.h>

Public Member Functions

std::vector< std::complex< double > > calcRoots (double const =-1.0)
 Calculate all the roots of the polynominal. More...
 
void compress (double const)
 Two part process remove coefficients of zero or near zero: Reduce degree by eliminating all (nearly) zero leading coefficients and by making the leading coefficient one. More...
 
PolyBasederivative ()
 Take derivative of this polynomial. More...
 
void divide (const PolyBase &, PolyBase &, PolyBase &, double const =-1.0) const
 Carry out polynomial division of this / pD (Euclidean algorithm) If 'this' is P(t) and the divisor is D(t) with degree(P) >= degree(D), then P(t) = Q(t)*D(t)+R(t) where Q(t) is the quotient with degree(Q) = degree(P) - degree(D) and R(t) is the remainder with degree(R) < degree(D). More...
 
int getDegree () const
 Accessor to degree size. More...
 
PolyBase getDerivative () const
 Take derivative. More...
 
PolyBase GetInversion () const
 Inversion of the coefficients. More...
 
 operator const std::vector< double > & () const
 Accessor to a vector component. More...
 
 operator std::vector< double > & ()
 Accessor to a vector component. More...
 
double operator() (double const) const
 Calculate polynomial at x. More...
 
PolyBase operator* (const PolyBase &) const
 PolyBase multiplication. More...
 
PolyBase operator* (double const) const
 PolyBase multiplication. More...
 
PolyBaseoperator*= (const PolyBase &)
 Self multiplication value. More...
 
PolyBaseoperator*= (double const)
 PolyBase multiplication. More...
 
PolyBase operator+ (const PolyBase &) const
 PolyBase addition. More...
 
PolyBase operator+ (double const) const
 PolyBase addition. More...
 
PolyBaseoperator+= (const PolyBase &)
 Self addition value. More...
 
PolyBaseoperator+= (double const)
 PolyBase addition. More...
 
PolyBase operator- () const
 PolyBase negation operator. More...
 
PolyBase operator- (const PolyBase &) const
 PolyBase subtraction. More...
 
PolyBase operator- (double const) const
 PolyBase substractr. More...
 
PolyBaseoperator-= (const PolyBase &)
 Self addition value. More...
 
PolyBaseoperator-= (double const)
 PolyBase subtraction. More...
 
PolyBase operator/ (double const) const
 PolyBase division. More...
 
PolyBaseoperator/= (double const)
 PolyBase division scalar. More...
 
double & operator[] (int const)
 Accessor to component. More...
 
double operator[] (int const) const
 Accessor to component. More...
 
 PolyBase (int const)
 Constructor. More...
 
 PolyBase (int const, double const)
 Constructor. More...
 
std::vector< double > realRoots (double const =-1.0)
 Get just the real roots. More...
 
void setDegree (int const)
 Set the degree value. More...
 
void write (std::ostream &) const
 Basic write command. More...
 

Private Member Functions

int solveCubic (std::complex< double > &, std::complex< double > &, std::complex< double > &) const
 Solves Cubic equation Compress MUST have been called. More...
 
int solveQuadratic (std::complex< double > &, std::complex< double > &) const
 Solves Complex Quadratic component. More...
 

Private Attributes

std::vector< double > afCoeff
 Coefficients. More...
 
double Eaccuracy
 Polynomic accuracy. More...
 
int iDegree
 Degree of polynomial [0 == constant]. More...
 

Detailed Description

Holds a polynominal as a primary type.

Version
1.0
Author
S. Ansell and D. Eberly
Date
December 2007

This holds a single variable poynomial of primary positive type. Assumes Euclidean division, hence a remainders. Internal solution of the polynomial is possible. Conversion to other forms is not internally handled.

Todo:

Add conversion to a continued fraction.

ADD solveQuartic

Definition at line 31 of file PolyBase.h.

Constructor & Destructor Documentation

◆ PolyBase() [1/2]

Mantid::mathLevel::PolyBase::PolyBase ( int const  iD)
explicit

Constructor.

Parameters
iD:: degree

Definition at line 32 of file PolyBase.cpp.

◆ PolyBase() [2/2]

Mantid::mathLevel::PolyBase::PolyBase ( int const  iD,
double const  E 
)

Constructor.

Parameters
iD:: degree
E:: Accuracy

Definition at line 40 of file PolyBase.cpp.

Member Function Documentation

◆ calcRoots()

std::vector< std::complex< double > > Mantid::mathLevel::PolyBase::calcRoots ( double const  epsilon = -1.0)

Calculate all the roots of the polynominal.

Uses the GSL which uses a Hessian reduction of the characteristic compainion matrix.

\[ A= \left( -a_{m-1}/a_m -a_{m-2}/a_m ... -a_0/a_m \right) \]

where the matrix component below A is the Indenty. However, GSL requires that the input coefficient is a_m == 1, hence the call to this->compress().

Parameters
epsilon:: tolerance factor (-ve to use default)
Returns
roots (not sorted/uniqued)

Definition at line 430 of file PolyBase.cpp.

References afCoeff, compress(), iDegree, solveCubic(), and solveQuadratic().

Referenced by realRoots().

◆ compress()

void Mantid::mathLevel::PolyBase::compress ( double const  epsilon)

Two part process remove coefficients of zero or near zero: Reduce degree by eliminating all (nearly) zero leading coefficients and by making the leading coefficient one.

Parameters
epsilon:: coeficient to use to decide if a values is zero

Definition at line 347 of file PolyBase.cpp.

References afCoeff, Eaccuracy, fabs, and iDegree.

Referenced by calcRoots().

◆ derivative()

PolyBase & Mantid::mathLevel::PolyBase::derivative ( )

Take derivative of this polynomial.

Returns
dP / dx

Definition at line 317 of file PolyBase.cpp.

References afCoeff, and iDegree.

Referenced by getDerivative().

◆ divide()

void Mantid::mathLevel::PolyBase::divide ( const PolyBase pD,
PolyBase pQ,
PolyBase pR,
double const  epsilon = -1.0 
) const

Carry out polynomial division of this / pD (Euclidean algorithm) If 'this' is P(t) and the divisor is D(t) with degree(P) >= degree(D), then P(t) = Q(t)*D(t)+R(t) where Q(t) is the quotient with degree(Q) = degree(P) - degree(D) and R(t) is the remainder with degree(R) < degree(D).

If this routine is called with degree(P) < degree(D), then Q = 0 and R = P are returned. The value of epsilon is used as a threshold on the coefficients of the remainder polynomial. If smaller, the coefficient is assumed to be zero.

Parameters
pD:: Polynominal to divide
pQ:: Quotant
pR:: Remainder
epsilon:: Tolerance [-ve to use master tolerance]

Definition at line 370 of file PolyBase.cpp.

◆ getDegree()

int Mantid::mathLevel::PolyBase::getDegree ( ) const

Accessor to degree size.

Returns
size

Definition at line 59 of file PolyBase.cpp.

References iDegree.

◆ getDerivative()

PolyBase Mantid::mathLevel::PolyBase::getDerivative ( ) const

Take derivative.

Returns
dP / dx

Definition at line 307 of file PolyBase.cpp.

References derivative().

◆ GetInversion()

PolyBase Mantid::mathLevel::PolyBase::GetInversion ( ) const

Inversion of the coefficients.

Returns
(Poly)^-1

Definition at line 335 of file PolyBase.cpp.

References afCoeff, and iDegree.

◆ operator const std::vector< double > &()

Mantid::mathLevel::PolyBase::operator const std::vector< double > & ( ) const

Accessor to a vector component.

Returns
vector

Definition at line 68 of file PolyBase.cpp.

◆ operator std::vector< double > &()

Mantid::mathLevel::PolyBase::operator std::vector< double > & ( )

Accessor to a vector component.

Returns
vector

Definition at line 77 of file PolyBase.cpp.

◆ operator()()

double Mantid::mathLevel::PolyBase::operator() ( double const  X) const

Calculate polynomial at x.

Parameters
X:: Value to calculate poly
Returns
polyvalue(x)

Definition at line 110 of file PolyBase.cpp.

References Mantid::Geometry::X.

◆ operator*() [1/2]

PolyBase Mantid::mathLevel::PolyBase::operator* ( const PolyBase A) const

PolyBase multiplication.

Parameters
A:: PolyBase multiplication
Returns
(*this*A);

Definition at line 193 of file PolyBase.cpp.

◆ operator*() [2/2]

PolyBase Mantid::mathLevel::PolyBase::operator* ( double const  V) const

PolyBase multiplication.

Parameters
V:: Value multiplication
Returns
(*this*V);

Definition at line 226 of file PolyBase.cpp.

◆ operator*=() [1/2]

PolyBase & Mantid::mathLevel::PolyBase::operator*= ( const PolyBase A)

Self multiplication value.

Parameters
A:: PolyBase to add
Returns
this=A;

Definition at line 153 of file PolyBase.cpp.

References afCoeff, and iDegree.

◆ operator*=() [2/2]

PolyBase & Mantid::mathLevel::PolyBase::operator*= ( double const  V)

PolyBase multiplication.

Parameters
V:: Value to multipication
Returns
(*this*V);

Definition at line 272 of file PolyBase.cpp.

References afCoeff.

◆ operator+() [1/2]

PolyBase Mantid::mathLevel::PolyBase::operator+ ( const PolyBase A) const

PolyBase addition.

Parameters
A:: PolyBase addition
Returns
(*this+A);

Definition at line 171 of file PolyBase.cpp.

◆ operator+() [2/2]

PolyBase Mantid::mathLevel::PolyBase::operator+ ( double const  V) const

PolyBase addition.

Parameters
V:: Value Addtion
Returns
(*this+V);

Definition at line 204 of file PolyBase.cpp.

◆ operator+=() [1/2]

PolyBase & Mantid::mathLevel::PolyBase::operator+= ( const PolyBase A)

Self addition value.

Parameters
A:: PolyBase to add
Returns
*this+=A;

Definition at line 125 of file PolyBase.cpp.

References afCoeff, and iDegree.

◆ operator+=() [2/2]

PolyBase & Mantid::mathLevel::PolyBase::operator+= ( double const  V)

PolyBase addition.

Parameters
V:: Value to add
Returns
(*this+V);

Definition at line 250 of file PolyBase.cpp.

References afCoeff.

◆ operator-() [1/3]

PolyBase Mantid::mathLevel::PolyBase::operator- ( ) const

PolyBase negation operator.

Returns
-(*this);

Definition at line 296 of file PolyBase.cpp.

◆ operator-() [2/3]

PolyBase Mantid::mathLevel::PolyBase::operator- ( const PolyBase A) const

PolyBase subtraction.

Parameters
A:: PolyBase addition
Returns
(*this-A);

Definition at line 182 of file PolyBase.cpp.

◆ operator-() [3/3]

PolyBase Mantid::mathLevel::PolyBase::operator- ( double const  V) const

PolyBase substractr.

Parameters
V:: Value substract
Returns
(*this-V);

Definition at line 215 of file PolyBase.cpp.

◆ operator-=() [1/2]

PolyBase & Mantid::mathLevel::PolyBase::operator-= ( const PolyBase A)

Self addition value.

Parameters
A:: PolyBase to add
Returns
*this+=A;

Definition at line 139 of file PolyBase.cpp.

References afCoeff, and iDegree.

◆ operator-=() [2/2]

PolyBase & Mantid::mathLevel::PolyBase::operator-= ( double const  V)

PolyBase subtraction.

Parameters
V:: Value to subtract
Returns
(*this+V);

Definition at line 261 of file PolyBase.cpp.

References afCoeff.

◆ operator/()

PolyBase Mantid::mathLevel::PolyBase::operator/ ( double const  V) const

PolyBase division.

Parameters
V:: Value division
Returns
(*this/V);

Definition at line 237 of file PolyBase.cpp.

◆ operator/=()

PolyBase & Mantid::mathLevel::PolyBase::operator/= ( double const  V)

PolyBase division scalar.

Parameters
V:: Value to divide
Returns
(*this/V);

Definition at line 284 of file PolyBase.cpp.

References afCoeff.

◆ operator[]() [1/2]

double & Mantid::mathLevel::PolyBase::operator[] ( int const  i)

Accessor to component.

Parameters
i:: index
Returns
Coeficient c_i

Definition at line 98 of file PolyBase.cpp.

References afCoeff, and iDegree.

◆ operator[]() [2/2]

double Mantid::mathLevel::PolyBase::operator[] ( int const  i) const

Accessor to component.

Parameters
i:: index
Returns
Coeficient c_i

Definition at line 86 of file PolyBase.cpp.

◆ realRoots()

std::vector< double > Mantid::mathLevel::PolyBase::realRoots ( double const  epsilon = -1.0)

Get just the real roots.

Parameters
epsilon:: tolerance factor (-ve to use default)
Returns
vector of the real roots (if any)

Definition at line 412 of file PolyBase.cpp.

References calcRoots(), Eaccuracy, and fabs.

Referenced by Mantid::Geometry::Quadratic::distance().

◆ setDegree()

void Mantid::mathLevel::PolyBase::setDegree ( int const  iD)

Set the degree value.

Parameters
iD:: degree

Definition at line 49 of file PolyBase.cpp.

References afCoeff, and iDegree.

◆ solveCubic()

int Mantid::mathLevel::PolyBase::solveCubic ( std::complex< double > &  AnsA,
std::complex< double > &  AnsB,
std::complex< double > &  AnsC 
) const
private

Solves Cubic equation Compress MUST have been called.

Parameters
AnsA:: complex roots of the equation
AnsB:: complex roots of the equation
AnsC:: complex roots of the equation
Returns
Number of unique solutions

Definition at line 505 of file PolyBase.cpp.

References Mantid::Geometry::d.

Referenced by calcRoots().

◆ solveQuadratic()

int Mantid::mathLevel::PolyBase::solveQuadratic ( std::complex< double > &  AnsA,
std::complex< double > &  AnsB 
) const
private

Solves Complex Quadratic component.

compress MUST have been called.

Parameters
AnsA:: complex roots of the equation
AnsB:: complex roots of the equation
Returns
Number of unique solutions

Definition at line 478 of file PolyBase.cpp.

Referenced by calcRoots().

◆ write()

void Mantid::mathLevel::PolyBase::write ( std::ostream &  OX) const

Basic write command.

Parameters
OX:: output stream

Definition at line 574 of file PolyBase.cpp.

Referenced by Mantid::mathLevel::operator<<().

Member Data Documentation

◆ afCoeff

std::vector<double> Mantid::mathLevel::PolyBase::afCoeff
private

◆ Eaccuracy

double Mantid::mathLevel::PolyBase::Eaccuracy
private

Polynomic accuracy.

Definition at line 35 of file PolyBase.h.

Referenced by compress(), and realRoots().

◆ iDegree

int Mantid::mathLevel::PolyBase::iDegree
private

Degree of polynomial [0 == constant].

Definition at line 33 of file PolyBase.h.

Referenced by calcRoots(), compress(), derivative(), getDegree(), GetInversion(), operator*=(), operator+=(), operator-=(), operator[](), and setDegree().


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