Mantid
|
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... | |
PolyBase & | derivative () |
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... | |
PolyBase & | operator*= (const PolyBase &) |
Self multiplication value. More... | |
PolyBase & | operator*= (double const) |
PolyBase multiplication. More... | |
PolyBase | operator+ (const PolyBase &) const |
PolyBase addition. More... | |
PolyBase | operator+ (double const) const |
PolyBase addition. More... | |
PolyBase & | operator+= (const PolyBase &) |
Self addition value. More... | |
PolyBase & | operator+= (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... | |
PolyBase & | operator-= (const PolyBase &) |
Self addition value. More... | |
PolyBase & | operator-= (double const) |
PolyBase subtraction. More... | |
PolyBase | operator/ (double const) const |
PolyBase division. More... | |
PolyBase & | operator/= (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... | |
Holds a polynominal as a primary type.
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.
Add conversion to a continued fraction.
ADD solveQuartic
Definition at line 31 of file PolyBase.h.
|
explicit |
Mantid::mathLevel::PolyBase::PolyBase | ( | int const | iD, |
double const | E | ||
) |
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().
epsilon | :: tolerance factor (-ve to use default) |
Definition at line 430 of file PolyBase.cpp.
References afCoeff, compress(), iDegree, solveCubic(), and solveQuadratic().
Referenced by realRoots().
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.
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().
PolyBase & Mantid::mathLevel::PolyBase::derivative | ( | ) |
Take derivative of this polynomial.
Definition at line 317 of file PolyBase.cpp.
References afCoeff, and iDegree.
Referenced by getDerivative().
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.
pD | :: Polynominal to divide |
pQ | :: Quotant |
pR | :: Remainder |
epsilon | :: Tolerance [-ve to use master tolerance] |
Definition at line 370 of file PolyBase.cpp.
int Mantid::mathLevel::PolyBase::getDegree | ( | ) | const |
Accessor to degree size.
Definition at line 59 of file PolyBase.cpp.
References iDegree.
PolyBase Mantid::mathLevel::PolyBase::getDerivative | ( | ) | const |
Take derivative.
Definition at line 307 of file PolyBase.cpp.
References derivative().
PolyBase Mantid::mathLevel::PolyBase::GetInversion | ( | ) | const |
Mantid::mathLevel::PolyBase::operator const std::vector< double > & | ( | ) | const |
Mantid::mathLevel::PolyBase::operator std::vector< double > & | ( | ) |
double Mantid::mathLevel::PolyBase::operator() | ( | double const | X | ) | const |
Calculate polynomial at x.
X | :: Value to calculate poly |
Definition at line 110 of file PolyBase.cpp.
References Mantid::Geometry::X.
PolyBase multiplication.
A | :: PolyBase multiplication |
Definition at line 193 of file PolyBase.cpp.
PolyBase Mantid::mathLevel::PolyBase::operator* | ( | double const | V | ) | const |
PolyBase multiplication.
V | :: Value multiplication |
Definition at line 226 of file PolyBase.cpp.
Self multiplication value.
A | :: PolyBase to add |
Definition at line 153 of file PolyBase.cpp.
PolyBase & Mantid::mathLevel::PolyBase::operator*= | ( | double const | V | ) |
PolyBase multiplication.
V | :: Value to multipication |
Definition at line 272 of file PolyBase.cpp.
References afCoeff.
PolyBase addition.
A | :: PolyBase addition |
Definition at line 171 of file PolyBase.cpp.
PolyBase Mantid::mathLevel::PolyBase::operator+ | ( | double const | V | ) | const |
PolyBase addition.
V | :: Value Addtion |
Definition at line 204 of file PolyBase.cpp.
Self addition value.
A | :: PolyBase to add |
Definition at line 125 of file PolyBase.cpp.
PolyBase & Mantid::mathLevel::PolyBase::operator+= | ( | double const | V | ) |
PolyBase addition.
V | :: Value to add |
Definition at line 250 of file PolyBase.cpp.
References afCoeff.
PolyBase Mantid::mathLevel::PolyBase::operator- | ( | ) | const |
PolyBase subtraction.
A | :: PolyBase addition |
Definition at line 182 of file PolyBase.cpp.
PolyBase Mantid::mathLevel::PolyBase::operator- | ( | double const | V | ) | const |
PolyBase substractr.
V | :: Value substract |
Definition at line 215 of file PolyBase.cpp.
Self addition value.
A | :: PolyBase to add |
Definition at line 139 of file PolyBase.cpp.
PolyBase & Mantid::mathLevel::PolyBase::operator-= | ( | double const | V | ) |
PolyBase subtraction.
V | :: Value to subtract |
Definition at line 261 of file PolyBase.cpp.
References afCoeff.
PolyBase Mantid::mathLevel::PolyBase::operator/ | ( | double const | V | ) | const |
PolyBase division.
V | :: Value division |
Definition at line 237 of file PolyBase.cpp.
PolyBase & Mantid::mathLevel::PolyBase::operator/= | ( | double const | V | ) |
PolyBase division scalar.
V | :: Value to divide |
Definition at line 284 of file PolyBase.cpp.
References afCoeff.
double & Mantid::mathLevel::PolyBase::operator[] | ( | int const | i | ) |
Accessor to component.
i | :: index |
Definition at line 98 of file PolyBase.cpp.
double Mantid::mathLevel::PolyBase::operator[] | ( | int const | i | ) | const |
Accessor to component.
i | :: index |
Definition at line 86 of file PolyBase.cpp.
std::vector< double > Mantid::mathLevel::PolyBase::realRoots | ( | double const | epsilon = -1.0 | ) |
Get just the real roots.
epsilon | :: tolerance factor (-ve to use default) |
Definition at line 412 of file PolyBase.cpp.
References calcRoots(), Eaccuracy, and fabs.
Referenced by Mantid::Geometry::Quadratic::distance().
void Mantid::mathLevel::PolyBase::setDegree | ( | int const | iD | ) |
|
private |
Solves Cubic equation Compress MUST have been called.
AnsA | :: complex roots of the equation |
AnsB | :: complex roots of the equation |
AnsC | :: complex roots of the equation |
Definition at line 505 of file PolyBase.cpp.
References Mantid::Geometry::d.
Referenced by calcRoots().
|
private |
Solves Complex Quadratic component.
compress MUST have been called.
AnsA | :: complex roots of the equation |
AnsB | :: complex roots of the equation |
Definition at line 478 of file PolyBase.cpp.
Referenced by calcRoots().
void Mantid::mathLevel::PolyBase::write | ( | std::ostream & | OX | ) | const |
Basic write command.
OX | :: output stream |
Definition at line 574 of file PolyBase.cpp.
Referenced by Mantid::mathLevel::operator<<().
|
private |
Coefficients.
Definition at line 34 of file PolyBase.h.
Referenced by calcRoots(), compress(), derivative(), GetInversion(), operator*=(), operator+=(), operator-=(), operator/=(), operator[](), and setDegree().
|
private |
Polynomic accuracy.
Definition at line 35 of file PolyBase.h.
Referenced by compress(), and realRoots().
|
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().