iterative-solver 0.0
Interpolate.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_INTERPOLATE_H_
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_INTERPOLATE_H_
3#include <cmath>
4#include <string>
5#include <vector>
6
11namespace molpro::linalg::itsolv {
12
14public:
15 struct point {
16 double x; //< abscissa
17 double f = std::nan("unset"); //< function value at x
18 double f1 = std::nan("unset"); //< function first gradient at x
19 double f2 = std::nan("unset"); //< function second gradient at x
20 friend std::ostream& operator<<(std::ostream& os, const point& p);
21 };
29 explicit Interpolate(point p0, point p1, std::string interpolant = "cubic", int verbosity = 0);
35 point operator()(double x) const;
46 Interpolate::point minimize(double xa, double xb, size_t bracket_grid = 100, size_t max_bracket_grid = 100000, bool analytic=true) const;
48 static std::vector<std::string> interpolants();
49
50 const std::vector<double>& parameters() const { return m_parameters; }
51 friend std::ostream& operator<<(std::ostream& os, const Interpolate& interpolant);
52
53private:
54 const point m_p0, m_p1;
55 const std::string m_interpolant;
56 double m_c0, m_c1, m_c2, m_c3; //< parameters defining the interpolant
57 std::vector<double> m_parameters;
58};
59
60inline bool operator==(const Interpolate::point& lhs, const Interpolate::point& rhs) {
61 return lhs.x == rhs.x && lhs.f == rhs.f && lhs.f1 == rhs.f1;
62}
63std::ostream& operator<<(std::ostream& os, const Interpolate& interpolant);
64std::ostream& operator<<(std::ostream& os, const Interpolate::point& p);
65
66} // namespace molpro::linalg::itsolv
67#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_INTERPOLATE_H_
Definition: Interpolate.h:13
static std::vector< std::string > interpolants()
Definition: Interpolate.cpp:99
const std::vector< double > & parameters() const
Definition: Interpolate.h:50
friend std::ostream & operator<<(std::ostream &os, const Interpolate &interpolant)
point operator()(double x) const
Evaluate the interpolant and its derivative at a given point.
Definition: Interpolate.cpp:101
Interpolate(point p0, point p1, std::string interpolant="cubic", int verbosity=0)
Construct the interpolant.
Definition: Interpolate.cpp:51
Interpolate::point minimize_cubic() const
Definition: Interpolate.cpp:115
Interpolate::point minimize(double xa, double xb, size_t bracket_grid=100, size_t max_bracket_grid=100000, bool analytic=true) const
Find the minimum of the interpolant within a range.
Definition: Interpolate.cpp:136
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition: helper.h:10
std::ostream & operator<<(std::ostream &o, const Statistics &statistics)
Definition: Statistics.h:39
bool operator==(const Interpolate::point &lhs, const Interpolate::point &rhs)
Definition: Interpolate.h:60
Definition: Interpolate.h:15
double x
Definition: Interpolate.h:16
double f2
Definition: Interpolate.h:19
double f
Definition: Interpolate.h:17
double f1
Definition: Interpolate.h:18
friend std::ostream & operator<<(std::ostream &os, const point &p)