OPAL (Object Oriented Parallel Accelerator Library)
2021.1.99
OPAL
|
#include <Polynomial.h>
Public Member Functions | |
Polynomial () | |
Polynomial (const std::vector< int > &coefficients) | |
Polynomial (const Polynomial &poly) | |
~Polynomial () | |
Polynomial & | operator= (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 |
Definition at line 51 of file Polynomial.h.
polynomial::Polynomial::Polynomial | ( | ) |
Default constructor, initialises zero polynomial
Definition at line 34 of file Polynomial.cpp.
References coefficients_m, and maxXorder_m.
|
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
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::Polynomial::Polynomial | ( | const Polynomial & | poly | ) |
Copy constructor
Definition at line 48 of file Polynomial.cpp.
References coefficients_m, and maxXorder_m.
polynomial::Polynomial::~Polynomial | ( | ) |
Destructor, does nothing
Definition at line 53 of file Polynomial.cpp.
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
poly | -> Polynomial to be added to this polynomial |
Definition at line 107 of file Polynomial.cpp.
References coefficients_m, and maxXorder_m.
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.
double polynomial::Polynomial::evaluatePolynomial | ( | const double & | x | ) | const |
Evaluate the polynomial
x | -> The point at which polynomial is evaluated |
Definition at line 126 of file Polynomial.cpp.
References coefficients_m, and maxXorder_m.
|
inline |
Returns coefficient in front of x^order
order | -> The power of x belonging to this coefficient |
Definition at line 120 of file Polynomial.h.
References coefficients_m, and maxXorder_m.
|
inline |
Returns the highest order of x, does nothing if order is negative
Definition at line 127 of file Polynomial.h.
References maxXorder_m.
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
poly | -> Polynomial to be multiplied with this polynomial |
Definition at line 77 of file Polynomial.cpp.
References coefficients_m, maxXorder_m, and setZero().
Polynomial & polynomial::Polynomial::operator= | ( | const Polynomial & | poly | ) |
Assigment operator
Definition at line 56 of file Polynomial.cpp.
References coefficients_m, and maxXorder_m.
void polynomial::Polynomial::printPolynomial | ( | ) | const |
Print polynomial for internal debugging
Definition at line 96 of file Polynomial.cpp.
References coefficients_m, and maxXorder_m.
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
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.
|
inline |
Set the highest order of x to maxXorder, filling in zeros if necessary
maxXorder | -> Highest power of x |
Definition at line 131 of file Polynomial.h.
References coefficients_m, and maxXorder_m.
|
inline |
Set polynomial to zero
Definition at line 136 of file Polynomial.h.
References coefficients_m, and maxXorder_m.
Referenced by multiplyPolynomial().
|
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
truncateOrder | -> Highest order of x after truncation |
Definition at line 142 of file Polynomial.h.
References coefficients_m, and maxXorder_m.
|
private |
Definition at line 116 of file Polynomial.h.
Referenced by addPolynomial(), differentiatePolynomial(), evaluatePolynomial(), getCoefficient(), multiplyPolynomial(), operator=(), Polynomial(), printPolynomial(), setCoefficient(), setMaxXorder(), setZero(), and truncate().
|
private |
Definition at line 115 of file Polynomial.h.
Referenced by addPolynomial(), differentiatePolynomial(), evaluatePolynomial(), getCoefficient(), getMaxXorder(), multiplyPolynomial(), operator=(), Polynomial(), printPolynomial(), setCoefficient(), setMaxXorder(), setZero(), and truncate().