Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename F>
- class TrapezoidalRule : public IntegrationMethod<F> {
- public:
- double Integrate (const F& func, const double& a, const double& b, const int& n) const override {
- double sum = 0;
- for (auto i = 0; i < n; i++) {
- double x1 = X_n(a, b, n, i);
- double x2 = X_n(a, b, n, i + 1);
- sum += ((func(x1) + func(x2)) / 2) * (x2 - x1);
- }
- return sum;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement