Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <functional>
- #include <cmath>
- typedef long double Type;
- constexpr Type eps = 1E-12;
- using analysisFunction = std::function<const Type(const Type, const Type)>;
- class derivatives {
- private:
- class derivative;
- public:
- derivatives(std::vector<analysisFunction>& p_fList) { fList = &p_fList; };
- derivative operator[](int index) {
- return derivative((*fList).at(index));
- }
- private:
- class derivative {
- public:
- derivative(analysisFunction& p_f) { f = &p_f; }
- Type operator()(Type t, Type u) {
- return (((*f)(t, u + eps)) - ((*f)(t,u)))/eps;
- }
- private:
- analysisFunction *f;
- };
- std::vector<analysisFunction> *fList;
- };
- int main ()
- {
- std::vector <analysisFunction> numericalFunctions;
- auto& f = numericalFunctions;
- f.push_back([](Type t, Type u)->Type { return u*u; });
- std::cout << std::setprecision(16);
- std::cout << f[0](5.0, 10.0) << '\n';
- derivatives dfdt(f);
- std::cout << dfdt[0](5.0, 10.0);
- return 0;
- }
Add Comment
Please, Sign In to add comment