Commit 0dd8c595 authored by amitjans's avatar amitjans
Browse files

Add comments

parent 3f1904f7
......@@ -8,19 +8,20 @@
#include <array>
int main() {
// Constants
const unsigned xbins(1000);
const double a(0.);
const double b(1.);
// Instantiate the two functions
MyFunc1 f1;
MyFunc2 f2;
std::cout.precision(15);
// With an ABC we can create an array of functions an iterate over it!
std::array<SimpleFunction *, 2> f_arr = {&f1, &f2};
// Call using function object
for (auto & f: f_arr) { // pass by REFERENCE!
// Iterate over the array of function pointers
for (auto f: f_arr) {
std::cout << "I = " << simpson(a, b, xbins, *f) << std::endl;
}
return 0;
......
......@@ -55,17 +55,4 @@ T simpson(const T a, const T b, const unsigned bins, const F& func)
return (func(a) + 2.*I2 + 4.*I4 - func(b)) * (dr/3.);
}
// Overloading simpson function for 2D
template<typename F, typename T>
T simpson(const T a, const T b, const T c, const T d,
const unsigned xbins, const unsigned ybins, const F& func) {
assert(xbins > 0);
assert(ybins > 0);
auto function = [&] (T x) { return simpson(c, d, ybins,
[&] (T y) { return func(x, y); });
};
return simpson(a, b, xbins, function);
}
#endif // SIMPSON_HPP
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment