Last active
December 12, 2017 15:29
-
-
Save YashasSamaga/4b3d7d6cd3116fe1854377e2b76ba217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment