From 45f12ba19761024d335407793ffb8d4823b28149 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Tue, 15 Apr 2025 00:51:40 +0300 Subject: Started doing 207 --- libprakpp/include/prakmath.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libprakpp/include/prakmath.hpp') diff --git a/libprakpp/include/prakmath.hpp b/libprakpp/include/prakmath.hpp index ebd02bf..bb09e74 100644 --- a/libprakpp/include/prakmath.hpp +++ b/libprakpp/include/prakmath.hpp @@ -289,6 +289,22 @@ pvalue function(function_t func, const std::vector> &args) { return ret; } +template +requires requires(iterator a){ ++a; *a; } && (std::integral || std::floating_point) +T discrete_integral_trapezoid(iterator X_start, iterator X_end, iterator Y_start, iterator Y_end) +{ + T ret = 0; + for (T Xl = *X_start, Yl = *Y_start; + X_start != X_end && Y_start != Y_end; + ++X_start, ++Y_start) + { + ret += std::abs(*X_start - Xl) * (*Y_start + Yl) / 2; // first iteration will add 0 + Xl = *X_start; + Yl = *Y_start; + } + return ret; +} + /// calculate least-squares linear approximation to fit data /// ax+b = y (ss is an error of Y value) template -- cgit v1.2.3-70-g09d2