15using namespace CurveFitting;
26 : m_base(
std::make_shared<
ChebfunBase>(
n, start, end)), m_badFit(false) {
31 : m_base(
std::make_shared<
ChebfunBase>(
n, start, end)), m_badFit(false) {
49 m_base = ChebfunBase::bestFitAnyTolerance<ChebfunFunctionType>(start, end, fun,
m_P,
m_A,
accuracy);
51 m_base = std::make_shared<ChebfunBase>(badSize - 1, start, end,
accuracy);
59 m_base = ChebfunBase::bestFitAnyTolerance<const API::IFunction &>(start, end, fun,
m_P,
m_A,
accuracy);
61 m_base = std::make_shared<ChebfunBase>(badSize - 1, start, end,
accuracy);
71 : m_base(
std::make_shared<
ChebfunBase>(
x.size() - 1,
x.front(),
x.back())), m_badFit(false) {
79 m_P.resize(base->size());
121 std::vector<double> A;
124 cheb.
m_P = base->calcP(A);
132 std::vector<double> rs;
136 auto y1 =
m_P.front() - level;
137 for (
size_t i = 1; i <
m_P.size(); ++i) {
138 auto y =
m_P[i] - level;
140 rs.emplace_back(
x[i]);
141 }
else if (y1 *
y < 0.0) {
142 rs.emplace_back((-
x[i - 1] *
y +
x[i] * y1) / (y1 -
y));
156 for (
size_t i = 0; i <
x.size(); ++i) {
This is an interface to a fitting function - a semi-abstarct class.
The ChebfunBase class provides a base for function approximation with Chebyshev polynomials.
SimpleChebfun : approximates smooth 1d functions and provides methods to manipulate them.
SimpleChebfun(size_t n, ChebfunFunctionType fun, double start, double end)
Constructor.
std::vector< double > roughRoots(double level=0.0) const
Get rough estimates of the roots.
SimpleChebfun derivative() const
Create a derivative of this function.
ChebfunBase_sptr m_base
Underlying base that does actual job.
double accuracy() const
Get the accuracy of the approximation.
std::vector< double > m_P
Function values at the chebfun x-points.
SimpleChebfun integral() const
Create an integral of this function.
SimpleChebfun & operator+=(const ChebfunFunctionType &fun)
Add a C++ function to the function.
std::vector< double > m_A
Chebyshev expansion coefficients.
const std::vector< double > & xPoints() const
Get a reference to the x-points.
bool m_badFit
Set in a case of a bad fit.
double integrate() const
Integrate the function on its interval.
double operator()(double x) const
Evaluate the function.
std::vector< double > linspace(size_t n) const
Create a vector of x values linearly spaced on the approximation interval.
const std::vector< double > & coeffs() const
Get a reference to the Chebyshev expansion coefficients.
std::shared_ptr< ChebfunBase > ChebfunBase_sptr
std::function< double(double)> ChebfunFunctionType
Type of the approximated function.