OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Public Member Functions | Private Attributes | List of all members
polynomial::Polynomial Class Reference

#include <Polynomial.h>

Public Member Functions

 Polynomial ()
 
 Polynomial (const std::vector< int > &coefficients)
 
 Polynomial (const Polynomial &poly)
 
 ~Polynomial ()
 
Polynomialoperator= (const Polynomial &poly)
 
void differentiatePolynomial ()
 
void multiplyPolynomial (const Polynomial &poly)
 
void addPolynomial (const Polynomial &poly)
 
void printPolynomial () const
 
int getCoefficient (const std::size_t &order) const
 
void setCoefficient (const int &coefficient, const std::size_t &order)
 
int getMaxXorder () const
 
void setMaxXorder (const std::size_t &maxXorder)
 
void setZero ()
 
double evaluatePolynomial (const double &x) const
 
void truncate (const std::size_t &truncateOrder)
 

Private Attributes

std::size_t maxXorder_m
 
std::vector< int > coefficients_m
 

Detailed Description

Definition at line 51 of file Polynomial.h.

Constructor & Destructor Documentation

◆ Polynomial() [1/3]

polynomial::Polynomial::Polynomial ( )

Default constructor, initialises zero polynomial

Definition at line 34 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ Polynomial() [2/3]

polynomial::Polynomial::Polynomial ( const std::vector< int > &  coefficients)
explicit

Initialises polynomial with input coefficients, starting with the const term
If coefficients is an empty vector, a zero polynomial with one constant zero term is created

Parameters
coefficients-> List of polynomial coefficients, starting with the const term

Definition at line 39 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ Polynomial() [3/3]

polynomial::Polynomial::Polynomial ( const Polynomial poly)

Copy constructor

Definition at line 48 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ ~Polynomial()

polynomial::Polynomial::~Polynomial ( )

Destructor, does nothing

Definition at line 53 of file Polynomial.cpp.

Member Function Documentation

◆ addPolynomial()

void polynomial::Polynomial::addPolynomial ( const Polynomial poly)

Add polynomial to input polynomial
If input polynomial has higher order terms, then maxXorder_m is adjusted and coefficients_m is resized

Parameters
poly-> Polynomial to be added to this polynomial

Definition at line 107 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ differentiatePolynomial()

void polynomial::Polynomial::differentiatePolynomial ( )

Differentiate polynomial using \(\frac{d}{dx}x^n = nx^{n - 1}\)

Definition at line 62 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ evaluatePolynomial()

double polynomial::Polynomial::evaluatePolynomial ( const double &  x) const

Evaluate the polynomial

Parameters
x-> The point at which polynomial is evaluated

Definition at line 126 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ getCoefficient()

int polynomial::Polynomial::getCoefficient ( const std::size_t &  order) const
inline

Returns coefficient in front of x^order

Parameters
order-> The power of x belonging to this coefficient

Definition at line 120 of file Polynomial.h.

References coefficients_m, and maxXorder_m.

◆ getMaxXorder()

int polynomial::Polynomial::getMaxXorder ( ) const
inline

Returns the highest order of x, does nothing if order is negative

Definition at line 127 of file Polynomial.h.

References maxXorder_m.

◆ multiplyPolynomial()

void polynomial::Polynomial::multiplyPolynomial ( const Polynomial poly)

Multiply polynomial with input polynomial by multiplying term by term
maxXorder_m is adjusted accordingly and coefficients_m is resized

Parameters
poly-> Polynomial to be multiplied with this polynomial

Definition at line 77 of file Polynomial.cpp.

References coefficients_m, maxXorder_m, and setZero().

Here is the call graph for this function:

◆ operator=()

Polynomial & polynomial::Polynomial::operator= ( const Polynomial poly)

Assigment operator

Definition at line 56 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ printPolynomial()

void polynomial::Polynomial::printPolynomial ( ) const

Print polynomial for internal debugging

Definition at line 96 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ setCoefficient()

void polynomial::Polynomial::setCoefficient ( const int &  coefficient,
const std::size_t &  order 
)

Set the coefficient in front of x^order
If order is larger than maxXorder_m maxXorder_m is adjusted and coefficients_m is resized

Parameters
coefficient-> Coefficient we wish to insert
order-> The power of x belonging to this coefficient

Definition at line 117 of file Polynomial.cpp.

References coefficients_m, and maxXorder_m.

◆ setMaxXorder()

void polynomial::Polynomial::setMaxXorder ( const std::size_t &  maxXorder)
inline

Set the highest order of x to maxXorder, filling in zeros if necessary

Parameters
maxXorder-> Highest power of x

Definition at line 131 of file Polynomial.h.

References coefficients_m, and maxXorder_m.

◆ setZero()

void polynomial::Polynomial::setZero ( )
inline

Set polynomial to zero

Definition at line 136 of file Polynomial.h.

References coefficients_m, and maxXorder_m.

Referenced by multiplyPolynomial().

◆ truncate()

void polynomial::Polynomial::truncate ( const std::size_t &  truncateOrder)
inline

Truncate polynomial to truncateOrder
If truncateOrder is greater than maxXorder_m, maxXorder_m is adjusted and coefficients is resized with zero coefficients at the end

Parameters
truncateOrder-> Highest order of x after truncation

Definition at line 142 of file Polynomial.h.

References coefficients_m, and maxXorder_m.

Member Data Documentation

◆ coefficients_m

std::vector<int> polynomial::Polynomial::coefficients_m
private

◆ maxXorder_m

std::size_t polynomial::Polynomial::maxXorder_m
private

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