sisi4s
Loading...
Searching...
No Matches
Integration.hpp
Go to the documentation of this file.
1#ifndef INTEGRATION_DEFINED
2#define INTEGRATION_DEFINED
3
5#include <iostream>
6#include <string>
7namespace sisi4s {
8template <typename Method, typename F, typename Float>
9
10double integrate(F f, Float a, Float b, int steps, Method m) {
11 double s = 0;
12 double h = (b - a) / steps;
13 for (int i = 0; i < steps; ++i) s += m(f, a + h * i, h);
14 return h * s;
15}
16class trapezium {
17public:
18 template <typename F, typename Float>
19 double operator()(F f, Float x, Float h) const {
20 return (f(x) + f(x + h)) / 2;
21 }
22};
23
24class simpson {
25public:
26 template <typename F, typename Float>
27 double operator()(F f, Float x, Float h) const {
28 return (f(x) + 4 * f(x + h / 2) + f(x + h)) / 6;
29 }
30};
31} // namespace sisi4s
32#endif
Definition Integration.hpp:24
double operator()(F f, Float x, Float h) const
Definition Integration.hpp:27
Definition Integration.hpp:16
double operator()(F f, Float x, Float h) const
Definition Integration.hpp:19
Definition Algorithm.hpp:10
double integrate(F f, Float a, Float b, int steps, Method m)
Definition Integration.hpp:10