Alexandria
2.18
Please provide a description of the project.
|
Represents a piecewise function. More...
#include <Piecewise.h>
Public Member Functions | |
Piecewise (std::vector< double > knots, std::vector< std::shared_ptr< Function >> functions) | |
Piecewise (std::vector< double > knots, std::vector< std::unique_ptr< Function >> &&functions) | |
virtual | ~Piecewise ()=default |
Default destructor. More... | |
const std::vector< double > & | getKnots () const |
Returns the knots of the piecewise function. More... | |
const std::vector< std::unique_ptr< Function > > & | getFunctions () const |
Returns the functions in the ranges between the knots. More... | |
double | operator() (const double) const override |
std::unique_ptr< Function > | clone () const override |
double | integrate (const double x1, const double x2) const override |
![]() | |
virtual | ~Integrable ()=default |
Default destructor. More... | |
![]() | |
virtual | ~Function ()=default |
Default destructor. More... | |
Private Attributes | |
std::vector< double > | m_knots |
A vector where the knots are kept. More... | |
std::vector< std::unique_ptr< Function > > | m_functions |
A vector where the sub-functions are kept. More... | |
Represents a piecewise function.
A Piecewise function is defined by multiple sub functions, each applied to an interval defined by the piecewise knots. Outside of the knots range the Piecewise evaluates zero.
Definition at line 48 of file Piecewise.h.
Euclid::MathUtils::Piecewise::Piecewise | ( | std::vector< double > | knots, |
std::vector< std::shared_ptr< Function >> | functions | ||
) |
Creates a new Piecewise instance with the given knots and functions between them. The functions vector must have size one less than the knots. The sub-function with index 0 corresponds to the range [knot0,knot1], the one with index 1 to the range [knot1,knot2], etc.
knots | The knots of the piecewise function |
functions | The sub-functions in the knot ranges |
Elements::Exception | if the size of the sub-functions vector is not ine less than the knots vector size |
Elements::Exception | if the knots are not strictly increasing |
Definition at line 33 of file Piecewise.cpp.
References std::back_inserter(), std::vector< T >::begin(), std::vector< T >::end(), m_functions, m_knots, std::vector< T >::size(), and std::transform().
Referenced by clone().
Euclid::MathUtils::Piecewise::Piecewise | ( | std::vector< double > | knots, |
std::vector< std::unique_ptr< Function >> && | functions | ||
) |
Definition at line 50 of file Piecewise.cpp.
References std::vector< T >::begin(), std::vector< T >::end(), m_functions, m_knots, and std::vector< T >::size().
|
virtualdefault |
Default destructor.
|
overridevirtual |
Creates a Piecewise function with the same knots and sub-functions. Note that the sub-functions are not cloned, but just a pointer is copied.
Implements Euclid::MathUtils::Function.
Definition at line 87 of file Piecewise.cpp.
References std::vector< T >::emplace_back(), m_functions, m_knots, std::move(), Piecewise(), and std::vector< T >::reserve().
const std::vector< std::unique_ptr< Function > > & Euclid::MathUtils::Piecewise::getFunctions | ( | ) | const |
Returns the functions in the ranges between the knots.
Definition at line 67 of file Piecewise.cpp.
References m_functions.
Referenced by Euclid::MathUtils::multiplyPiecewises(), and Euclid::MathUtils::multiplyPiecewiseWithGeneric().
const std::vector< double > & Euclid::MathUtils::Piecewise::getKnots | ( | ) | const |
Returns the knots of the piecewise function.
Definition at line 63 of file Piecewise.cpp.
References m_knots.
Referenced by Euclid::MathUtils::multiplyPiecewises(), and Euclid::MathUtils::multiplyPiecewiseWithGeneric().
|
overridevirtual |
Calculates the integral in the range [x1,x2], by delegating the integration in the sub-functions.
x1 | The lower bound of the integration |
x2 | The upper bound of the integration |
Implements Euclid::MathUtils::Integrable.
Definition at line 96 of file Piecewise.cpp.
References std::vector< T >::begin(), std::vector< T >::end(), Euclid::MathUtils::integrate(), m_functions, m_knots, and std::upper_bound().
|
overridevirtual |
Returns the value of the piecewise function for the given value, by using the correct sub-function. Values outside of the knots evaluate to zero.
Implements Euclid::MathUtils::Function.
Definition at line 71 of file Piecewise.cpp.
References std::vector< T >::begin(), std::vector< T >::end(), std::lower_bound(), m_functions, and m_knots.
|
private |
A vector where the sub-functions are kept.
Definition at line 98 of file Piecewise.h.
Referenced by clone(), getFunctions(), integrate(), operator()(), and Piecewise().
|
private |
A vector where the knots are kept.
Definition at line 96 of file Piecewise.h.
Referenced by clone(), getKnots(), integrate(), operator()(), and Piecewise().