EMath++
Classes for mathematical concepts
Loading...
Searching...
No Matches
emth::Polynomial Class Reference

Class for representing and operating polynomials. More...

#include <emath.h>

Public Member Functions

 Polynomial () noexcept
 Default constructor for when initialized with no arguments.
 
 Polynomial (const std::map< int, Monomial > mns) noexcept
 Normal constructor for initialization with a std::map<int, Monomial>
 
 Polynomial (const std::initializer_list< Monomial > mns) noexcept
 List constructor for initialization with a std::initializer_list<Monomial>
 
 Polynomial (const std::vector< Monomial > mns) noexcept
 Vector constructor for initialization with a std::vector<Monomial>
 
 Polynomial (const Polynomial &ogn) noexcept
 Copy constructor for when initialized with an lvalue Polynomial object.
 
 Polynomial (Polynomial &&ogn) noexcept
 Move constructor for when initialized with an rvalue Polynomial object.
 
Polynomialoperator= (const Polynomial &ogn) noexcept
 Assigment operator overload for when called with an lvalue.
 
Polynomialoperator= (Polynomial &&ogn) noexcept
 Move assigment operator overload for when called with an rvalue.
 
bool operator== (const Polynomial &ogn) const noexcept
 Equal logic operator overload.
 
bool operator!= (const Polynomial &ogn) const noexcept
 Not equal logic operator overload.
 
bool operator> (const Polynomial &ogn) const noexcept
 Greater than logic operator overload.
 
bool operator< (const Polynomial &ogn) const noexcept
 Less than logic operator overload.
 
bool operator>= (const Polynomial &ogn) const noexcept
 Greater or equal than logic operator overload.
 
bool operator<= (const Polynomial &ogn) const noexcept
 Less or equal than logic operator overload.
 
Polynomial operator+ (const Polynomial &ogn) const noexcept
 Addition operator overload.
 
Polynomial operator- (const Polynomial &ogn) const noexcept
 Substraction operator overload.
 
Polynomial operator* (const Polynomial &ogn) const noexcept
 Multiplication operator overload.
 
Polynomial operator/ (const Polynomial &ogn) const noexcept
 Division operator overload.
 
Polynomial operator% (const Polynomial &ogn) const noexcept
 Modulus operator overload.
 
Polynomialoperator+= (const Polynomial &ogn) noexcept
 Addition assigment operator overload.
 
Polynomialoperator-= (const Polynomial &ogn) noexcept
 Substraction assigment operator overload.
 
Polynomialoperator*= (const Polynomial &ogn) noexcept
 Multiplication assigment operator overload.
 
Polynomialoperator/= (const Polynomial &ogn) noexcept
 Division assigment operator overload.
 
Polynomialoperator%= (const Polynomial &ogn) noexcept
 Modulus assigment operator overload.
 
int get_degree () const noexcept
 Getter function for getting the degree of the Polynomial.
 
std::map< int, Monomialget_monomials () const noexcept
 Getter function for getting the monomials of the Polynomial.
 
bool is_empty () const noexcept
 Function for knowing if the polynomial has or not any monomials.
 
bool push_monomial (const Monomial &m) noexcept
 Function for appending a lvalue monomial to the Polynomial.
 
bool push_monomial (Monomial &&m) noexcept
 Function for appending a rvalue monomial to the Polynomial.
 
std::string get_expression () const noexcept
 Getter function for getting the expression of the Polynomial.
 
double get_value (const double &x) const noexcept
 Calculus function for getting the value of the Polynomial at a point.
 
Polynomial get_derivative () const noexcept
 Calculus function for getting the derivative of the Polynomial.
 
Polynomial get_integral () const noexcept
 Calculus function for getting the integral of the Polynomial.
 
std::vector< std::complex< double > > get_roots () const noexcept
 Calculus function for getting all the real and complex roots of the Polynomial using the Eigen library.
 
 ~Polynomial ()
 The class destructor.
 

Friends

std::stringstream & operator<< (std::stringstream &ss, const Polynomial &p) noexcept
 A friend operator to insert the Polynomial into a std::stringstream.
 
std::ostream & operator<< (std::ostream &out, const Polynomial &p) noexcept
 A friend operator to insert the Polynomial into a std::ostream.
 

Detailed Description

Class for representing and operating polynomials.

The class consists of the constructors, the operators, the getters, the properties and some private functions.

Definition at line 392 of file emath.h.

Constructor & Destructor Documentation

◆ Polynomial() [1/6]

emth::Polynomial::Polynomial ( )
noexcept

Default constructor for when initialized with no arguments.

Definition at line 264 of file emath.cpp.

◆ Polynomial() [2/6]

emth::Polynomial::Polynomial ( const std::map< int, Monomial mns)
noexcept

Normal constructor for initialization with a std::map<int, Monomial>

Parameters
mnsThe std::map<int, Monomial>.

◆ Polynomial() [3/6]

emth::Polynomial::Polynomial ( const std::initializer_list< Monomial mns)
noexcept

List constructor for initialization with a std::initializer_list<Monomial>

Parameters
mnsThe std::initializer_list<Monomial>.

◆ Polynomial() [4/6]

emth::Polynomial::Polynomial ( const std::vector< Monomial mns)
noexcept

Vector constructor for initialization with a std::vector<Monomial>

Parameters
mnsThe std::vector<Monomial>.

◆ Polynomial() [5/6]

emth::Polynomial::Polynomial ( const Polynomial ogn)
noexcept

Copy constructor for when initialized with an lvalue Polynomial object.

Parameters
ognThe lvalue Polynomial object.

Definition at line 284 of file emath.cpp.

◆ Polynomial() [6/6]

emth::Polynomial::Polynomial ( emth::Polynomial &&  ogn)
noexcept

Move constructor for when initialized with an rvalue Polynomial object.

Parameters
ognThe rvalue Polynomial object.

Definition at line 289 of file emath.cpp.

Member Function Documentation

◆ get_degree()

int emth::Polynomial::get_degree ( ) const
noexcept

Getter function for getting the degree of the Polynomial.

Returns
(int) The degree of the Polynomial.

Definition at line 468 of file emath.cpp.

◆ get_derivative()

emth::Polynomial emth::Polynomial::get_derivative ( ) const
noexcept

Calculus function for getting the derivative of the Polynomial.

Returns
(Polynomial) The result of the derivative of the Polynomial.

Definition at line 515 of file emath.cpp.

◆ get_expression()

std::string emth::Polynomial::get_expression ( ) const
noexcept

Getter function for getting the expression of the Polynomial.

Returns
(std::string) The expression of the Polynomial.

Definition at line 500 of file emath.cpp.

◆ get_integral()

emth::Polynomial emth::Polynomial::get_integral ( ) const
noexcept

Calculus function for getting the integral of the Polynomial.

Returns
(Polynomial) The result of the integral of the Polynomial.

Definition at line 526 of file emath.cpp.

◆ get_monomials()

std::map< int, emth::Monomial > emth::Polynomial::get_monomials ( ) const
noexcept

Getter function for getting the monomials of the Polynomial.

Returns
(std::map<int, Monomial>) The monomials of the Polynomial.

Definition at line 473 of file emath.cpp.

◆ get_roots()

std::vector< std::complex< double > > emth::Polynomial::get_roots ( ) const
noexcept

Calculus function for getting all the real and complex roots of the Polynomial using the Eigen library.

Returns
(std::vector<double>) All the roots as doubles in a std::vector

Does not handle the edge case when called with a constant polynomial (polynomial of degree zero).

Returns
(std::vector<double>) All the roots as doubles in a std::vector

Definition at line 538 of file emath.cpp.

◆ get_value()

double emth::Polynomial::get_value ( const double &  x) const
noexcept

Calculus function for getting the value of the Polynomial at a point.

Parameters
xThe point to evaluate.
Returns
(double) The result of the evaluation of the Polynomial.

Definition at line 506 of file emath.cpp.

◆ is_empty()

bool emth::Polynomial::is_empty ( ) const
noexcept

Function for knowing if the polynomial has or not any monomials.

Returns
(bool) If the polynomial is empty.

Definition at line 478 of file emath.cpp.

◆ operator!=()

bool emth::Polynomial::operator!= ( const Polynomial ogn) const
noexcept

Not equal logic operator overload.

Parameters
ognThe Polynomial object to compare to.
Returns
(true) If Polynomial objects degrees and monomials dont match.
(false) If Polynomial objects degrees and monomials match.

Definition at line 315 of file emath.cpp.

◆ operator%()

emth::Polynomial emth::Polynomial::operator% ( const Polynomial ogn) const
noexcept

Modulus operator overload.

Parameters
ognThe Polynomial object to divide by.
Returns
(Polynomial) A brand new Polynomial that represents the result.

Definition at line 373 of file emath.cpp.

◆ operator%=()

emth::Polynomial & emth::Polynomial::operator%= ( const Polynomial ogn)
noexcept

Modulus assigment operator overload.

Parameters
ognThe Polynomial object to divide by.
Returns
(Polynomial&) A reference to the lvalue of the operation.

Definition at line 429 of file emath.cpp.

◆ operator*()

emth::Polynomial emth::Polynomial::operator* ( const Polynomial ogn) const
noexcept

Multiplication operator overload.

Parameters
ognThe Polynomial object to multiply by.
Returns
(Polynomial) A brand new Polynomial that represents the result.

Definition at line 361 of file emath.cpp.

◆ operator*=()

emth::Polynomial & emth::Polynomial::operator*= ( const Polynomial ogn)
noexcept

Multiplication assigment operator overload.

Parameters
ognThe Polynomial object to multiply by.
Returns
(Polynomial&) A reference to the lvalue of the operation.

Definition at line 397 of file emath.cpp.

◆ operator+()

emth::Polynomial emth::Polynomial::operator+ ( const Polynomial ogn) const
noexcept

Addition operator overload.

Parameters
ognThe Polynomial object to add.
Returns
(Polynomial) A brand new Polynomial that represents the result.

Definition at line 349 of file emath.cpp.

◆ operator+=()

emth::Polynomial & emth::Polynomial::operator+= ( const Polynomial ogn)
noexcept

Addition assigment operator overload.

Parameters
ognThe Polynomial object to add.
Returns
(Polynomial&) A reference to the lvalue of the operation.

Definition at line 379 of file emath.cpp.

◆ operator-()

emth::Polynomial emth::Polynomial::operator- ( const Polynomial ogn) const
noexcept

Substraction operator overload.

Parameters
ognThe Polynomial object to substract by.
Returns
(Polynomial) A brand new Polynomial that represents the result.

Definition at line 355 of file emath.cpp.

◆ operator-=()

emth::Polynomial & emth::Polynomial::operator-= ( const Polynomial ogn)
noexcept

Substraction assigment operator overload.

Parameters
ognThe Polynomial object to substract by.
Returns
(Polynomial&) A reference to the lvalue of the operation.

Definition at line 388 of file emath.cpp.

◆ operator/()

emth::Polynomial emth::Polynomial::operator/ ( const Polynomial ogn) const
noexcept

Division operator overload.

Parameters
ognThe Polynomial object to divide by.
Returns
(Polynomial) A brand new Polynomial that represents the result.

Definition at line 367 of file emath.cpp.

◆ operator/=()

emth::Polynomial & emth::Polynomial::operator/= ( const Polynomial ogn)
noexcept

Division assigment operator overload.

Parameters
ognThe Polynomial object to divide by.
Returns
(Polynomial&) A reference to the lvalue of the operation.

Definition at line 412 of file emath.cpp.

References emth::Monomial::get_degree().

◆ operator<()

bool emth::Polynomial::operator< ( const Polynomial ogn) const
noexcept

Less than logic operator overload.

Parameters
ognThe Polynomial object to compare to.
Returns
(true) If the Polynomial object degree is less than the degree of the passed Polynomial.
(false) If the Polynomial object degree is equal or greater than the degree of the passed Polynomial.

Definition at line 329 of file emath.cpp.

◆ operator<=()

bool emth::Polynomial::operator<= ( const Polynomial ogn) const
noexcept

Less or equal than logic operator overload.

Parameters
ognThe Polynomial object to compare to.
Returns
(true) If the Polynomial object degree is less or equal than the degree of the passed Polynomial.
(false) If the Polynomial object degree is greater than the degree of the passed Polynomial.

Definition at line 343 of file emath.cpp.

◆ operator=() [1/2]

emth::Polynomial & emth::Polynomial::operator= ( const Polynomial ogn)
noexcept

Assigment operator overload for when called with an lvalue.

Parameters
ognThe lvalue Polynomial object.
Returns
(Polynomial&) A reference to the lvalue of the operation

Definition at line 295 of file emath.cpp.

◆ operator=() [2/2]

emth::Polynomial & emth::Polynomial::operator= ( emth::Polynomial &&  ogn)
noexcept

Move assigment operator overload for when called with an rvalue.

Parameters
ognThe rvalue Polynomial object.
Returns
(Polynomial&) A reference to the lvalue of the operation

Definition at line 301 of file emath.cpp.

◆ operator==()

bool emth::Polynomial::operator== ( const Polynomial ogn) const
noexcept

Equal logic operator overload.

Parameters
ognThe Polynomial object to compare to.
Returns
(true) If Polynomial objects degrees and monomials match.
(false) If Polynomial objects degrees and monomials dont match.

Definition at line 308 of file emath.cpp.

◆ operator>()

bool emth::Polynomial::operator> ( const Polynomial ogn) const
noexcept

Greater than logic operator overload.

Parameters
ognThe Polynomial object to compare to.
Returns
(true) If the Polynomial object degree is greater than the degree of the passed Polynomial.
(false) If the Polynomial object degree is equal or less than the degree of the passed Polynomial.

Definition at line 322 of file emath.cpp.

◆ operator>=()

bool emth::Polynomial::operator>= ( const Polynomial ogn) const
noexcept

Greater or equal than logic operator overload.

Parameters
ognThe Polynomial object to compare to.
Returns
(true) If the Polynomial object degree is greater or equal than the degree of the passed Polynomial.
(false) If the Polynomial object degree is less than the degree of the passed Polynomial.

Definition at line 336 of file emath.cpp.

◆ push_monomial() [1/2]

bool emth::Polynomial::push_monomial ( const Monomial m)
noexcept

Function for appending a lvalue monomial to the Polynomial.

Parameters
mThe Monomial object to append.
Returns
(bool) If the operation was successful.

Definition at line 484 of file emath.cpp.

◆ push_monomial() [2/2]

bool emth::Polynomial::push_monomial ( emth::Monomial &&  m)
noexcept

Function for appending a rvalue monomial to the Polynomial.

Parameters
mThe Monomial object to append.
Returns
(bool) If the operation was successful.

Definition at line 490 of file emath.cpp.

References emth::Monomial::get_coeff(), and emth::Monomial::get_degree().

Friends And Related Function Documentation

◆ operator<< [1/2]

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

A friend operator to insert the Polynomial into a std::ostream.

Parameters
outThe std::ostream.
mThe Polynomial object to insert.
Returns
(std::ostream&) A reference to the std::ostream.

◆ operator<< [2/2]

std::stringstream & operator<< ( std::stringstream &  ss,
const Polynomial p 
)
friend

A friend operator to insert the Polynomial into a std::stringstream.

Parameters
ssThe std::stringstream.
mThe Polynomial object to insert.
Returns
(std::stringstream&) A reference to the std::stringstream.

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