Guest User

Untitled

a guest
Dec 14th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <functional>
  5. #include <cmath>
  6.  
  7. typedef long double Type;
  8. constexpr Type eps = 1E-12;
  9.  
  10. using analysisFunction = std::function<const Type(const Type, const Type)>;
  11.  
  12. class derivatives {
  13. private:
  14. class derivative;
  15. public:
  16. derivatives(std::vector<analysisFunction>& p_fList) { fList = &p_fList; };
  17. derivative operator[](int index) {
  18. return derivative((*fList).at(index));
  19. }
  20. private:
  21. class derivative {
  22. public:
  23. derivative(analysisFunction& p_f) { f = &p_f; }
  24. Type operator()(Type t, Type u) {
  25. return (((*f)(t, u + eps)) - ((*f)(t,u)))/eps;
  26. }
  27. private:
  28. analysisFunction *f;
  29. };
  30. std::vector<analysisFunction> *fList;
  31. };
  32.  
  33. int main ()
  34. {
  35. std::vector <analysisFunction> numericalFunctions;
  36. auto& f = numericalFunctions;
  37.  
  38. f.push_back([](Type t, Type u)->Type { return u*u; });
  39.  
  40.  
  41. std::cout << std::setprecision(16);
  42. std::cout << f[0](5.0, 10.0) << '\n';
  43.  
  44. derivatives dfdt(f);
  45. std::cout << dfdt[0](5.0, 10.0);
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment